Installed Python 2.7.3 from http://www.python.org/ftp/python/2.7.3/python-2.7.3.msi
then
Installed PyVisa from https://sourceforge.net/projects/pyvisa/files/PyVISA/1.4/
then attempted to import visa in Idle:
Python 2.7.3 (default, Apr 10 2012, 23:31:26) [MSC v.1500 32 bit (Intel)] on win32
Type "copyright", "credits" or "license()" for more information.
>>> import visa
Traceback (most recent call last):
File "<pyshell#0>", line 1, in <module>
import visa
File "C:\Python27\lib\site-packages\visa.py", line 1, in <module>
from pyvisa.visa import *
File "C:\Python27\lib\site-packages\pyvisa\visa.py", line 231, in <module>
resource_manager = ResourceManager()
File "C:\Python27\lib\site-packages\pyvisa\vpp43.py", line 105, in __new__
it.init(*args, **kwds)
File "C:\Python27\lib\site-packages\pyvisa\visa.py", line 227, in init
self.session = self.vi = vpp43.open_default_resource_manager()
File "C:\Python27\lib\site-packages\pyvisa\vpp43.py", line 758, in open_default_resource_manager
visa_library().viOpenDefaultRM(byref(session))
File "C:\Python27\lib\site-packages\pyvisa\vpp43.py", line 175, in __call__
self.load_library()
File "C:\Python27\lib\site-packages\pyvisa\vpp43.py", line 141, in load_library
self.__lib = windll.visa32
File "C:\Python27\lib\ctypes\__init__.py", line 435, in __getattr__
dll = self._dlltype(name)
File "C:\Python27\lib\ctypes\__init__.py", line 365, in __init__
self._handle = _dlopen(self._name, mode)
WindowsError: [Error 126] The specified module could not be found
Looks like pyvisa can't find your visa dll. There' some documentation on where the VISA dll is expected at http://pyvisa.sourceforge.net/pyvisa.html#id32
Can you cross-check on your system? Where is your visa dll located?
Thank you bauflo3. I have visa32.dll in the correct spot:
C:\Windows\System32\visa32.dll
I checked the PATH and the above directory is in the PATH (as expected). I also am running on a 64bit system, if it matters.
Also, I am not sure why, today I get a slightly different error message number:
WindowsError: [Error 193] %1 is not a valid Win32 application
The rest of the error info is the same, just the error number has changed.
Thank you for your help.
Hi Paul,
i see from your traceback that you are running a 32 bit python, which matches the download link you gave. As the visa dll is called visa32.dll, I'm assuming it's 32 bit as well. Unfortunately I don't have access to a windows machine atm.
Just to double check, could you try the following (in idle, or save as a script and run)
import ctypes
ctypes.windll.LoadLibrary(r"C:\Windows\System32\visa32.dll")
or
ctypes.cdll.LoadLibrary(r"C:\Windows\System32\visa32.dll")
If this works, then check whether
import ctypes
ctypes.windll.visa32
works as well.
I would expect that both either work or fail with the same error message. Both your error messages are generated by Windows and merely translated to python. Error 126 means dll not found, and Error 193 hints at a 64 vs 32 bit issue. I don't think that PyVISA works in a 64 bit application, as it is completely untested. But i used to run it in a 32 bit process on 64 bit Windows 7 myself, so it is definitively doable ;)
Does it make a difference whether you use idle or the interactive interpreter on the command line?
Good luck,
Florian
Thank you for your help. You are correct, they both fail, and the fail in Idle and in Python Command line:
Python 2.7.3 (default, Apr 10 2012, 23:31:26) [MSC v.1500 32 bit (Intel)] on win32
Type "copyright", "credits" or "license()" for more information.
>>> import ctypes
>>> ctypes.windll.LoadLibrary(r"C:\Windows\System32\visa32.dll")
Traceback (most recent call last):
File "<pyshell#1>", line 1, in <module>
ctypes.windll.LoadLibrary(r"C:\Windows\System32\visa32.dll")
File "C:\Python27\lib\ctypes\__init__.py", line 443, in LoadLibrary
return self._dlltype(name)
File "C:\Python27\lib\ctypes\__init__.py", line 365, in __init__
self._handle = _dlopen(self._name, mode)
WindowsError: [Error 126] The specified module could not be found
>>> ctypes.cdll.LoadLibrary(r"C:\Windows\System32\visa32.dll")
Traceback (most recent call last):
File "<pyshell#2>", line 1, in <module>
ctypes.cdll.LoadLibrary(r"C:\Windows\System32\visa32.dll")
File "C:\Python27\lib\ctypes\__init__.py", line 443, in LoadLibrary
return self._dlltype(name)
File "C:\Python27\lib\ctypes\__init__.py", line 365, in __init__
self._handle = _dlopen(self._name, mode)
WindowsError: [Error 126] The specified module could not be found
>>>
The error message just tells you that the visa32.dll can't be found. You said that you verified that it is there. Could this be a permission issue?
Can you read a couple of bytes from the dll, like so:
with open(r"C:\Windows\System32\visa32.dll", 'rb') as infile:
print infile.read(10)
this should print 10 bytes of gibberish, if python can indeed find the dll. If this fails with an IOError, then either the visa32.dll is not there or for some reason not visible to the python process. This is just speculation from my part, but maybe the Windows Error 126 could also be generated by lacking sufficient permissions to read the dll?
You are a genius. I tried the print infile.read and it could not find it although I could clearly see it was there. I played with the permissions but got no where. I finally re-installed NI VISA and it now works fine! Thank you for your support! Paul Crossen
Glad I could help you. Closing the ticket now.