当尝试运行用Python2编写的应用程序时,我遇到导入错误,但是当查看文件时,它们都在那里?
与python2-six相关的所有文件:
python2-six /usr/
python2-six /usr/lib/
python2-six /usr/lib/python2.7/
python2-six /usr/lib/python2.7/site-packages/
python2-six /usr/lib/python2.7/site-packages/six-1.11.0-py2.7.egg-info/
python2-six /usr/lib/python2.7/site-packages/six-1.11.0-py2.7.egg-info/PKG-INFO
python2-six /usr/lib/python2.7/site-packages/six-1.11.0-py2.7.egg-info/SOURCES.txt
python2-six /usr/lib/python2.7/site-packages/six-1.11.0-py2.7.egg-info/dependency_links.txt
python2-six /usr/lib/python2.7/site-packages/six-1.11.0-py2.7.egg-info/top_level.txt
python2-six /usr/lib/python2.7/site-packages/six.py
python2-six /usr/lib/python2.7/site-packages/six.pyc
python2-six /usr/lib/python2.7/site-packages/six.pyo
python2-six /usr/share/
python2-six /usr/share/licenses/
python2-six /usr/share/licenses/python2-six/
python2-six /usr/share/licenses/python2-six/LICENSE
在运行程序时:
File "/usr/lib/python2.7/site-packages/configobj.py", line 22, in <module>
import six
ImportError: No module named six
我的Python2.7的PYTHONPATH是:
/usr/lib/python27.zip
/usr/lib/python2.7
/usr/lib/python2.7/plat-linux2
/usr/lib/python2.7/lib-tk
/usr/lib/python2.7/lib-old
/usr/lib/python2.7/lib-dynload
/usr/lib/python2.7/site-packages
/usr/lib/python2.7/site-packages/gtk-2.0
为什么不捡起模块? 我应该提到我在Arch Linux上,Python 2.7和Python 3.7并排运行。 / usr / bin / python被符号链接到python3。
答案 0 :(得分:2)
这通常意味着您的环境设置不正确。虚拟环境不只是符号链接bin
路径。
在python 3中,您可以执行python -m venv venv_name
,而在python 2中,您需要创建一个虚拟环境来运行。
您是如何创建virtualenv的?
我会激活环境; source /path/to/bin/activate
。
使用pip list
命令并查看其内容。