简体   繁体   中英

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. This started when I purged my whole install of python, and reinstalled it using 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. 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. 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. For reference, echoing the variables PYTHONPATH returns empty and PYTHONHOME returns:

/usr

In addition, the sys.path variable contains:

['',
 '/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. Given this question:

Python packages not available after install with pip

I suspect this has something to do with the installation of python that pip is serving. 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. Plus, as the sys.path variable shows, python should be looking into /usar/local/python2.7 as well. Other packages such as flask, bitarray, and redis have this problem as well. 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.

if you had previously another python installation, I suspect pip is still associated with the old version. 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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