Python 模块虽然已安装但未被检测到

Python modules not being detected although they are installed

我有 Python 的旧版本。然后我卸载了旧版本,并安装了一个新版本 - 2.7.9.

我通过 pyenv 将 2.7.9 设置为我的全球版本,但未检测到我的所有模块。它们是在升级之前安装的。现在我卸载了它们并重新安装但仍然无法正常工作...

~/Projects/development$ python
Python 2.7.9 (default, Mar  3 2016, 16:42:45) 
[GCC 4.6.3] on linux2
>>> from github import Github
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: No module named github

python升级后已经重新安装了!再次尝试安装它们时,出现 已满足要求 错误。

~/Projects/development$ pip install PyGithub
Requirement already satisfied (use --upgrade to upgrade): PyGithub in /usr/local/lib/python2.7/dist-packages
Cleaning up...

我能做什么?

~/Projects/development$ pyenv versions
  system
* 2.7.9 (set by /home/user/.pyenv/version)

~/Projects/development$ python
    Python 2.7.9 (default, Mar  3 2016, 16:42:45) 
    [GCC 4.6.3] on linux2
>>> sys.executable
'/usr/local/bin/python'
>>> sys.exec_prefix
'/usr/local'
>>> print '\n'.join(sys.path)

/usr/local/lib/python27.zip
/usr/local/lib/python2.7
/usr/local/lib/python2.7/plat-linux2
/usr/local/lib/python2.7/lib-tk
/usr/local/lib/python2.7/lib-old
/usr/local/lib/python2.7/lib-dynload
/usr/local/lib/python2.7/site-packages

which pip 给出 /usr/bin/pip.

我发现了问题。

dist-packages 与 site-packages。

使用上一个 Python 版本,并且在升级后,我的软件包通过 pip 安装到 /usr/local/lib/python2.7/dist-packages,而我安装的新 Python 期望软件包安装到 /usr/local/lib/python2.7/site-packages(从源代码手动安装 Python 时,它使用 site-packages 目录。查看更多 here)。我可以临时复制模块,或者只是操纵 PYTHONPATH 环境变量指向 dist-packages,以便访问使用新安装的 Python.

版本安装的软件包

来自 here.