简体   繁体   English

Python无法在Linux上通过pip查找已安装的软件包

[英]Python not finding installed packages through pip on Linux

I've been trying to install some new python packages with pip, but for some reason, python is not finding them after installation. 我一直在尝试使用pip安装一些新的python软件包,但是由于某些原因,python在安装后找不到它们。 This started when I purged my whole install of python, and reinstalled it using apt-get. 当我清除整个python安装并使用apt-get重新安装它时,此操作开始。 I installed: 我安装了:

python
python2.7
python2.7-dev
python-setuptools

When I run: 当我跑步时:

sudo pip list

I get: 我得到:

decorator (3.4.0)
flann (1.8.4)
ipython (3.2.0)
itsdangerous (0.24)
MarkupSafe (0.23)
numpy (1.9.2)
pexpect (3.1)
pip (7.1.0)
setuptools (18.0.1)
simplegeneric (0.8.1)
Werkzeug (0.10.4)

so numpy is listed as installed. 因此numpy列为已安装。 In addition, a 此外,

locate numpy

returns 退货

/usr/bin/dh_numpy
/usr/include/numpy
/usr/include/python2.7/numpy
/usr/lib/python2.7/dist-packages/numpy
/usr/lib/python2.7/dist-packages/IPython/external/decorators/_numpy_testing_noseclasses.py
/usr/lib/python2.7/dist-packages/IPython/external/decorators/_numpy_testing_noseclasses.pyc
/usr/lib/python2.7/dist-packages/IPython/external/decorators/_numpy_testing_utils.py
/usr/lib/python2.7/dist-packages/IPython/external/decorators/_numpy_testing_utils.pyc
/usr/local/lib/python2.7/dist-packages/numpy
/usr/local/lib/python2.7/dist-packages/numpy-1.9.2.egg-info
/usr/share/numpy
/usr/share/doc/python-numpy
/usr/share/man/man1/dh_numpy.1.gz
/var/lib/dpkg/info/python-numpy.list
/var/lib/dpkg/info/python-numpy.md5sums
/var/lib/dpkg/info/python-numpy.postinst
/var/lib/dpkg/info/python-numpy.preinst
/var/lib/dpkg/info/python-numpy.prerm

so it seems like the installation is alright. 因此安装似乎没问题。 But if I try to import it from python, I get an import error. 但是,如果我尝试从python导入它,则会收到导入错误。 I've tried many things, like purging the entire python installation, purging pip, easy_install and reinstalling all that, massing with the PYTHONPATH and PYTHONHOME variables, and so forth. 我尝试了很多事情,例如清除整个python安装,清除pip,easy_install并重新安装所有这些,并合并PYTHONPATH和PYTHONHOME变量,等等。 For reference, echoing the variables PYTHONPATH returns empty and PYTHONHOME returns: 作为参考,回显变量PYTHONPATH返回空,而PYTHONHOME返回:

/usr

In addition, the sys.path variable contains: 另外,sys.path变量包含:

['',
 '/usr/local/bin',
 '/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/IPython/extensions']

So it is looking in both the /usr/lib/python2.7 directories and in /usr/local/lib/python2.7. 因此,它正在/usr/lib/python2.7目录和/usr/local/lib/python2.7中查找。 Given this question: 鉴于这个问题:

Python packages not available after install with pip 使用pip安装后无法使用Python软件包

I suspect this has something to do with the installation of python that pip is serving. 我怀疑这与pip服务的python安装有关。 But I only have python in /usr/bin, and not in /usr/local/bin, so I have no idea why pip is installing in local. 但是我在/ usr / bin中只有python,而在/ usr / local / bin中却没有,所以我不知道为什么在本地安装pip。 Plus, as the sys.path variable shows, python should be looking into /usar/local/python2.7 as well. 另外,如sys.path变量所示,python也应该考虑/usar/local/python2.7。 Other packages such as flask, bitarray, and redis have this problem as well. 其他软件包(例如flask,bitarray和redis)也存在此问题。 Thank you for the help! 感谢您的帮助!

EDIT: 编辑:

Another important information to add: which -a python outputs /usr/bin/python , so the python being used is in /usr/bin. 要添加的另一个重要信息: which -a python输出/usr/bin/python ,因此所使用的python在/ usr / bin中。

if you had previously another python installation, I suspect pip is still associated with the old version. 如果您以前安装了另一个python,我怀疑pip仍与旧版本关联。 type $ pip -V if it's not 2.7 create a symlink for /Library/Frameworks/Python.framework/Versions/2.7/bin/pip2.7 to usr/bin/pip I see that the packages are installed in the right place so maybe you can try $ python -V as well ps: This should go as a comment but I don't have enough "reputations" to add a comment. 如果不是2.7,则键入$ pip -V ,为/Library/Frameworks/Python.framework/Versions/2.7/bin/pip2.7创建usr / bin / pip的符号链接,我看到软件包安装在正确的位置,所以也许您也可以尝试$ python -V以及ps:这应该作为注释,但是我没有足够的“信誉”来添加注释。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM