我正在尝试运行Spyder IDE,但它失败了,因为它导入了错误的文件。我得到ImportError
尝试从命令行运行它:
$ /opt/anaconda3/bin/spyder
Traceback (most recent call last):
File "/opt/anaconda3/bin/spyder", line 6, in <module>
sys.exit(spyder.app.start.main())
File "/opt/anaconda3/lib/python3.5/site-packages/spyder/app/start.py",
line 103, in main
from spyder.app import mainwindow
File "/opt/anaconda3/lib/python3.5/site-packages/spyder/app/mainwindow.py",
line 78, in <module>
from qtpy.compat import from_qvariant
File "/opt/anaconda3/lib/python3.5/site-packages/qtpy/compat.py",
line 15, in <module>
from qtpy.QtWidgets import QFileDialog
File "/opt/anaconda3/lib/python3.5/site-packages/qtpy/QtWidgets.py",
line 27, in <module>
from PyQt5.QtWidgets import *
ImportError: /opt/anaconda3/lib/python3.5/site-packages/PyQt5/Qt/lib/libQt5Gui.so.5:
symbol _Z10qAllocMoreii, version Qt_5 not defined in file libQt5Core.so.5 with
link time reference
然而,当我从/opt/anaconda3/bin/python
命令from PyQt5.QtWidgets import *
的python解释器运行时,它运行正常。好的,我觉得这是一个sys.path
问题。所以我修改/opt/anaconda3/lib/python3.5/site-packages/qtpy/QtWidgets.py
以打印出系统路径和系统可执行文件。相关的代码段是:
print(sys.path)
print(sys.executable)
from PyQt5.QtWidgets import *
打印结果:
['/opt/anaconda3/bin', '/opt/anaconda3/lib/python35.zip',
'/opt/anaconda3/lib/python3.5',
'/opt/anaconda3/lib/python3.5/plat-linux',
'/opt/anaconda3/lib/python3.5/lib-dynload',
'/opt/anaconda3/lib/python3.5/site-packages',
'/opt/anaconda3/lib/python3.5/site-packages/Sphinx-1.4.6-py3.5.egg',
'/opt/anaconda3/lib/python3.5/site-packages/setuptools-27.2.0-py3.5.egg']
/opt/anaconda3/bin/python
解释器对相同两个命令的结果是:
['', '/opt/anaconda3/lib/python35.zip',
'/opt/anaconda3/lib/python3.5',
'/opt/anaconda3/lib/python3.5/plat-linux',
'/opt/anaconda3/lib/python3.5/lib-dynload',
'/opt/anaconda3/lib/python3.5/site-packages',
'/opt/anaconda3/lib/python3.5/site-packages/Sphinx-1.4.6-py3.5.egg',
'/opt/anaconda3/lib/python3.5/site-packages/setuptools-27.2.0-py3.5.egg']
/opt/anaconda3/bin/python
所以除了第一个目录之外,路径完全相同,但这是无关紧要的,因为解释器在正确的目录中找到了相应的库:
$ /opt/anaconda3/bin/python
>>> import PyQt5.QtWidgets
>>> print(PyQt5.QtWidgets)
<module 'PyQt5.QtWidgets' from
'/opt/anaconda3/lib/python3.5/site-packages/PyQt5/QtWidgets.so'>
总而言之,即使我使用相同的系统路径相同的解释器,我在两个不同的位置使用相同的导入命令找到两个不同的文件。怎么可能?如何防止它做任何事情?