【发布时间】:2016-08-27 20:15:55
【问题描述】:
每当我尝试运行脚本时,python 解释器总是显示ImportError 消息,例如(例如)No module named 'setuptools'。因此,我尝试使用 apt-get 安装(或满足此要求)...我对 Python 2.7 和 Python 3.5 都执行此操作,直到 Requirement already satisfied。
首先,我不使用 Python 2.7,但它是解释器的默认版本。那么,我该如何解决这个问题以使用 Python 3.5 呢?我试过这个:
>>> import sys
>>> print(sys.path)
['',
'/usr/local/lib/python35.zip',
'/usr/local/lib/python3.5',
'/usr/local/lib/python3.5/plat-linux',
'/usr/local/lib/python3.5/lib-dynload',
'/usr/local/lib/python3.5/site-packages']
这是针对 Python3 的,对于 Python2 我做了同样的比较路径,我得到了这个:
>>> import sys
>>> print(sys.path)
['',
'/usr/local/lib/python2.7/dist-packages/pygame-1.9.2b8-py2.7-linux-x86_64.egg',
'/usr/lib/python2.7',
'/usr/lib/python2.7/plat-x86_64-linux-gnu',
'/usr/lib/python2.7/lib-tk',
'/usr/lib/python2.7/lib-old',
'/usr/lib/python2.7/lib-dynload',
'/usr/local/lib/python2.7/dist-packages',
'/usr/lib/python2.7/dist-packages',
'/usr/lib/python2.7/dist-packages/PILcompat',
'/usr/lib/python2.7/dist-packages/gtk-2.0']
现在...如果我使用append() 方法将Python2 的所有路径添加到Python3 中的路径,它应该工作吗?另外,我曾考虑完全卸载 Python2,但我知道这会导致我的系统出现比我尝试解决的问题更多的问题。
【问题讨论】:
-
这种情况会发生在 any 脚本中,还是仅在特定脚本中发生?
-
我不认为这个问题与“如何安装 pip”是重复的。
-
所有使用 Python3 以利用第三方模块的脚本都会发生这种情况。 @elethan
标签: python python-2.7 python-3.x pip importerror