Unintentionally finding two different files with the same python interpreter and system path

217 Views Asked by At

I'm trying to run the Spyder IDE but it fails because it imports the wrong file. I get an ImportError attempting to run it from the command line:

$ /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

However, when I run from the python interpreter at /opt/anaconda3/bin/python the command from PyQt5.QtWidgets import *, it works fine. Ok, so naturally I think this is a sys.path issue. So I modify /opt/anaconda3/lib/python3.5/site-packages/qtpy/QtWidgets.py to print out the system path and system executable. The relevant segment of code is:

print(sys.path)
print(sys.executable)
from PyQt5.QtWidgets import *

Which prints the result:

['/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

The result from the interpreter for the same two commands is:

['', '/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

So the paths are exactly the same except for the first directory, but that is irrelevant because the interpreter finds the appropriate library in the right directory:

$ /opt/anaconda3/bin/python
>>> import PyQt5.QtWidgets
>>> print(PyQt5.QtWidgets)
<module 'PyQt5.QtWidgets' from 
'/opt/anaconda3/lib/python3.5/site-packages/PyQt5/QtWidgets.so'>

So in summary, even though I'm using the same interpreter with the same system path, I find two different files in two different locations with the same import command. How is that possible? How do I prevent it doing whatever it is doing?

0

There are 0 best solutions below