OS (Linux): Ubuntu 14.04.4 LTS (Trusty Tahr)
For some reason, my Python 3.5.2 is looking into the Python 2.7 packages directory instead of its own:
] python3 -m ensurepip
Ignoring indexes: https://pypi.python.org/simple
Requirement already satisfied (use --upgrade to upgrade):
setuptools in /usr/local/lib/python3.5/site-packages
Requirement already satisfied (use --upgrade to upgrade):
pip in /usr/local/lib/python2.7/dist-packages
More details:
] python3
Python 3.5.2 (default, Jul 29 2016, 09:41:38)
[GCC 6.1.1 20160511] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import site; site.getsitepackages()
['/usr/local/lib/python3.5/site-packages']
>>>
^^^-- That seems correct and does not mention anything about the 2.7 packages directory.
It looks like it should only be looking in /usr/local/lib/python3.5/site-packages
, but for some reason, it is also looking in /usr/local/lib/python2.7/dist-packages
where it has no business in looking.
For example, look at what happens when I try to install psycopg2
as a Python 3 module:
] python3 -m pip install psycopg2
Requirement already satisfied (use --upgrade to upgrade):
psycopg2 in /usr/local/lib/python2.7/dist-packages
It is finding it as an installed package in the 2.7 distribution and failing to install its Python 3 version in /usr/local/lib/python3.5/site-packages
.
To add even more confusion into the mix, I try going straight for pip 3, but to no avail:
] pip3 install psycopg2
Requirement already satisfied (use --upgrade to upgrade):
psycopg2 in /usr/local/lib/python2.7/dist-packages
] cat `which pip3`
#!/usr/local/bin/python3
# -*- coding: utf-8 -*-
import re
import sys
from pip import main
if __name__ == '__main__':
sys.argv[0] = re.sub(r'(-script\.pyw|\.exe)?$', '', sys.argv[0])
sys.exit(main())
Update: PYTHONPATH
was set to /usr/local/lib/python2.7/dist-packages
. This was the cause of the issue above. Credit goes to user be_good_do_good for helping me figure out which screw to turn to get things to work as they should.
When a package is installed globally, it's made available to all users that log into the system. Typically, that means Python and all packages will get installed to a directory under /usr/local/bin/ for a Unix-based system, or \Program Files\ for Windows.
there is a site package directory in a virtualenv. You can get the directory for site-specific modules inside/outside virtualenv using python -c "from distutils. sysconfig import get_python_lib; print(get_python_lib())" (it works on both Python 2 and 3 too).
PIP is automatically installed with Python 2.7. 9+ and Python 3.4+ and it comes with the virtualenv and pyvenv virtual environments. Before you install PIP on Windows, check if PIP is already installed. 1.
PYTHONPATH might have been set to 2.7 distribution packages, which might be causing this.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With