Pip and Python do not agree on module location

Well, that’s just weird. I help a colleague on Mac (Yosemite) by running the Python executable in /usr/bin/python (2.7.10). I used the easy_install sent to install pip (9.0.1), which was placed in /usr/local/bin using the shebang line #!/usr/bin/python . Then I used pip to install some modules, including six , only to find out that pip and python somehow disagree with this version of the module:

Tail pip install -vvv -U six :

 Installed version (1.10.0) is most up-to-date (past versions: 0.9.0, 0.9.1, 0.9.2, 1.0.0, 1.1.0, 1.2.0, 1.3.0, 1.4.0, 1.4.1, 1.5.0, 1.5.1, 1.5.2, 1.6.0, 1.6.1, 1.7.0, 1.7.1, 1.7.2, 1.7.3, 1.8.0, 1.9.0, 1.10.0) Requirement already up-to-date: six in /Library/Python/2.7/site-packages 

Output python -c 'import six; print six.__version__' python -c 'import six; print six.__version__' :

 1.4.1 

Relevant Locations:

 $ type pip pip is /usr/local/bin/pip $ type python python is /usr/bin/python $ head -n 1 $(type -p pip) #!/usr/bin/python 

$PYTHONPATH not set in the environment. But they still look in different places. As you can see from pip output, it searches / stores in /Library/Python/2.7/site-packages/ . But if I go through sys.path , the first thing I find six is in /System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/ .

So where to disconnect?

+5
source share
1 answer

The question turned out to be the order of the download path. On my Sierra machine (where I checked that I was able to install the new six by default /usr/bin/python ), /Library/Python/2.7/site-packages preceded by /System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python in sys.path . But on the machine of the /Library/Python/2.7/site-packages collective, /Library/Python/2.7/site-packages is the most recent entry that appears after the Extras folder, so the pip -installed version is masked by the installation of the system.

I suspect this is a problem with the Yosemite Python installation that Sierra installed, but in any case I don't see an easy fix. Thus, to install a separate Python instance (for example, I usually use pyenv ) or manually, set PYTHONPATH to put site-packages in the foreground. Or perhaps upgrade to a newer macOS.

Thanks to everyone for helping me figure this out.

+1
source

Source: https://habr.com/ru/post/1270790/


All Articles