简体   繁体   中英

“/lib/python2.7/site-packages/ does NOT support .pth files” installing pip on MacOS

I ran into some issues using pip on my mac, and uninstalled it altogether.

Now when I try to reinstall it, running $sudo easy_install pip I get:

TEST FAILED: /lib/python2.7/site-packages/ does NOT support .pth files
error: bad install directory or PYTHONPATH

You are attempting to install a package to a directory that is not
on PYTHONPATH and which Python does not read ".pth" files from.  The
installation directory you specified (via --install-dir, --prefix, or
the distutils default setting) was:

    /lib/python2.7/site-packages/

and your PYTHONPATH environment variable currently contains:

    ''

[this pasted output cut short for brevity]


I've tried adding the directory listed (/lib/python2.7/site-packages/) into my pythonpath using both ./profile and ./bash_profile, but neither affect the sys.path variable when I run python, which includes only

/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python27.zip
/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7
/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-darwin
/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-mac
/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-mac/lib-scriptpackages
/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-tk
/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-old
/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-dynload
/Library/Python/2.7/site-packages
/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python
/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/PyObjC

Is my problem that I have two versions of python installed (under the two directories listed)?

Or is it my pythonpath is screwed up in a way that I've been unable to remedy?


Edit:

$ which python returns /usr/bin/python

and $ which easy_install returns /usr/bin/easy_install

I figured it out.

When I tried to install python2 via brew, then ran brew doctor I got the following warning.

Warning: A .pydistutils.cfg file was found in $HOME, which may cause Python
builds to fail. See:
  https://bugs.python.org/issue6138
  https://bugs.python.org/issue4655

Sure enough, when I deleted .pydistutils.cfg the problem cleared up.


FWIW, here's the SO question that got me to create the file to begin with:

Combine --user with --prefix error with setup.py install

(The answer there does mention it may cause unintended consequences. I just figure that linking to it may help search visibility for anyone who currently has the same problem that I had, but has forgotten that they created that file.)

While I don't have an exact answer I can fill in some blanks for you.

Your sys.path doesn't show two versions of Python installed, it shows one installed according to the slightly strange way Apple installs Python 2.

The directories under /System/Library/Frameworks/Python.framework/Versions/2.7/ are the libraries and modules for your Python. As the /System/Library/ directories are "protected" on a Mac they can't be written to with SIP active so Apple provide the directory /Library/Python/2.7/site-packages which is where Python packages such as pip are installed.

On my system sudo /usr/bin/easy_install pip does the install into /Library/Python/2.7/site-packages/ .

Since your pip doesn't run the next step I would suggest is see if you can get it bootstrapped from the standard library - sudo python -m ensurepip --default-pip . If that doesn't work you can find instructions on how to get it running here .

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