OK, this is just strange. I am helping a colleague on a Mac (Yosemite), running the shipped Python executable in /usr/bin/python
(2.7.10). I used the shipped easy_install
to install pip
(9.0.1), which was deposited in /usr/local/bin
with a shebang line of #!/usr/bin/python
. I then used pip
to install some modules, including six
, only to find out that pip and python somehow disagree about that module's version:
Tail of 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 of 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
is not set in the environment. But they are still looking in different places. As you can see from the pip
output, it's looking/storing in /Library/Python/2.7/site-packages/
. But if I loop over sys.path
, the first place I find six
is in /System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/
.
So where's the disconnect?
The issue turned out to be the order of the load path. On my Sierra machine (where I verified that I was able to install a new six
for the default /usr/bin/python
), /Library/Python/2.7/site-packages
comes before /System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python
in sys.path
. But on the coworker's machine, /Library/Python/2.7/site-packages
is the very last entry, coming after the Extras
folder, so the pip
-installed version is masked by the system install.
I suspect this is a problem with the Yosemite Python installation that was fixed by Sierra, but in any case I can see no easy fix. So the options are to install a separate Python instance (my preference; I usually use pyenv
anyway) or manually set PYTHONPATH
to put site-packages
out front. Or upgrade to a newer macOS, I suppose.
Thanks to everyone for the help figuring this out.
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