Vector XL library not found even though it is installed
Closed this issue · 2 comments
Describe the bug
python-can throws exception CanInterfaceNotImplementedError: The Vector API has not been loaded
when trying to create a Vector bus.
To Reproduce
- Install python-can from pip (v4.4.2)
- Install CANalyzer, Vector Device Driver (VN1610), XL Driver Library from Vector
- Run the python code below
- The following error is thrown:
File "C:\Users\me\AppData\Local\Programs\Python\Python312\Lib\site-packages\can\interfaces\vector\canlib.py", line 178, in __init__
raise CanInterfaceNotImplementedError("The Vector API has not been loaded")
can.exceptions.CanInterfaceNotImplementedError: The Vector API has not been loaded
Expected behavior
Bus is successfully created and interface sends the message in the code below every 1.5s.
Additional context
OS and version: Windows 11 64-bit
Python version: 3.12.4
python-can version: 4.4.2
python-can interface/s (if applicable): Vector VN1610
CANalyzer v12.0 SP1
Vector Device Driver v24.20.10.0
XL Driver Library v20.30.14
pip freeze
altgraph==0.17.4
can-isotp==2.0.5
cffi==1.16.0
crc==7.0.0
cryptography==42.0.8
intelhex==2.3.0
packaging==24.1
pefile==2023.2.7
pyasn1==0.6.0
pycparser==2.22
pyinstaller==6.9.0
pyinstaller-hooks-contrib==2024.7
PySimpleGUI==5.0.6
python-can==4.4.2
pywin32==306
pywin32-ctypes==0.2.2
rsa==4.9
setuptools==71.1.0
typing_extensions==4.12.2
udsoncan==1.23.1
wrapt==1.16.0
NOTE: I was able to get rid of the "Vector API has not been loaded" message by adding the XL Driver Library bin folder, which contains vxlapi.dll and vxlapi64.dll, to my environment PATH, but my interface did not transmit any CAN messages. No exceptions were thrown, but I wonder if something behind the scenes isn't getting set up properly. Today I am getting the error even with the XL Driver Library bin folder in my PATH.
I recently had a new hard drive installed in my machine and had to reinstall everything, but before that this code worked properly. I don't remember having to add anything to my PATH before, and the instructions in the python-can docs don't indicate I should need to.
The only other difference I can think of is my company recently started using a credentials manager to allow elevated privileges for installing software that requires it. But, CANalyzer installed and works properly so I don't think that's an issue.
In the past if I didn't have the interface driver installed or had it unplugged I would get a different exception, more like #1754. Please let me know if there's any other information I can provide to help with this.
Traceback and logs
Could not import vxlapi: Vector XL library not found: vxlapi64
Traceback (most recent call last):
File "C:\temp\vector_test.py", line 6, in <module>
bus = can.ThreadSafeBus(interface='vector', channel=0, bitrate=500000)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\me\AppData\Local\Programs\Python\Python312\Lib\site-packages\can\thread_safe_bus.py", line 39, in __init__
return f(*args, **kwargs)
^^^^^^^^^^^^^^^^^^
File "C:\Users\me\AppData\Local\Programs\Python\Python312\Lib\site-packages\can\interface.py", line 135, in Bus
bus = cls(channel, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\me\AppData\Local\Programs\Python\Python312\Lib\site-packages\can\util.py", line 379, in wrapper
return f(*args, **kwargs)
^^^^^^^^^^^^^^^^^^
File "C:\Users\me\AppData\Local\Programs\Python\Python312\Lib\site-packages\can\interfaces\vector\canlib.py", line 178, in __init__
raise CanInterfaceNotImplementedError("The Vector API has not been loaded")
can.exceptions.CanInterfaceNotImplementedError: The Vector API has not been loaded
Test code:
import can
import time
msg = can.Message(arbitration_id=0x18E38000, data=[0x08, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff], is_extended_id=True)
bus = can.ThreadSafeBus(interface='vector', channel=0, bitrate=500000)
while True:
bus.send(msg)
time.sleep(1.5)
Does anyone know where the XL Driver Library typically installs? On my machine it is C:\Users\Public\Public Documents\Vector\XL Driver Library 20.30.14
and the bin\ folder has vxlapi.dll and vxlapi64.dll. The DLLs are NOT found in C:\Windows\System32
or C:\Windows\SysWOW64
.
I think I figured it out. Looks like there was a change in Python 3.8 that modified where DLLs could be loaded from so they are no longer loaded from untrusted locations by default:
https://docs.python.org/3.8/whatsnew/3.8.html#ctypes
This Stack Overflow answer recommended using os.add_dll_directory()
to add a location to search, and I don't get the exception after adding that line to my test script: https://stackoverflow.com/questions/71645822/dll-not-found-after-switching-from-python-3-7-6-to-python-3-10-3
import can
import time
import os
from pathlib import Path
os.add_dll_directory(Path("C:/Users/Public/Documents/Vector/XL Driver Library/bin"))
msg = can.Message(arbitration_id=0x18E38000, data=[0x08, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff], is_extended_id=True)
bus = can.ThreadSafeBus(interface='vector', channel=0, bitrate=500000)
print("bus created")
while True:
bus.send(msg)
time.sleep(1.5)
Should this be mentioned in the python-can docs somewhere?