当我运行基本代码时:
import visa
rm = visa.ResourceManager('@py')
a=rm.list_resources()
print(a)
我收到:
Traceback (most recent call last):
File "pyvisa.py", line 1, in <module>
import visa
File "/usr/local/lib/python2.7/dist-packages/visa.py", line 16, in <module>
from pyvisa import logger, __version__, log_to_screen, constants
File "/home/pi/pyvisa.py", line 2, in <module>
rm = visa.ResourceManager('@py')
AttributeError: 'module' object has no attribute 'ResourceManager'
当我尝试
时 python -m visa info
Traceback (most recent call last):
File "/usr/lib/python2.7/runpy.py", line 162, in _run_module_as_main
"__main__", fname, loader, pkg_name)
File "/usr/lib/python2.7/runpy.py", line 72, in _run_code
exec code in run_globals
File "/usr/local/lib/python2.7/dist-packages/visa.py", line 16, in <module>
from pyvisa import logger, __version__, log_to_screen, constants
File "pyvisa.py", line 1, in <module>
import visa
File "/usr/local/lib/python2.7/dist-packages/visa.py", line 16, in <module>
from pyvisa import logger, __version__, log_to_screen, constants
ImportError: cannot import name logger
另一方面,我无法升级,因为要求已经是最新的。
pip install pyvisa-py --upgrade
Requirement already up-to-date: pyvisa-py in /usr/local/lib/python2.7/dist-packages
Requirement already up-to-date: pyvisa>=1.8 in /usr/local/lib/python2.7/dist-packages (from pyvisa-py)
Requirement already up-to-date: enum34 in /usr/local/lib/python2.7/dist-packages (from pyvisa>=1.8->pyvisa-py)
如果有人能帮我解决这个问题,我将非常感激。
答案 0 :(得分:0)
“在python 2.7中,导入系统将始终使用工作目录中的文件而不是site-packages中的文件,并且当导入visa.py时,您的文件名为pyvisa.py,它会选择您自己的模块,而不是'真实的'pyvisa模块。“来自github的MatthieuDartiailh
答案 1 :(得分:0)
visa.py模块没有ResourceManager(),而必须使用pyvsa.py
import pyvisa
rm = pyvisa.ResourceManager('@py')
a=rm.list_resources()
print(a)
如果运行此代码,不会有任何错误,您应该能够打印所连接的任何仪器。