pip is trying to install packages with C extensions into global directories on OSX

1k views Asked by At

I have a virtualenv with Python 2.7 and I'm trying to install some packages that have C extensions (in this case, pygame and/or pyaudio):

$ which pip
/Users/fyhuang/env/bin/pip
$ pip -V
pip 1.4 from /Users/fyhuang/env/lib/python2.7/site-packages (python 2.7)

When I try to install these packages, however, pip decides that it wants to install the compiled C extensions into the system directories, instead of the virtualenv:

running install_lib

creating /lib

error: could not create '/lib': Permission denied

Is this expected behavior from pip? If not, has anyone else run into this issue before? This is on OSX 10.8.

1

There are 1 answers

0
fyhuang On BEST ANSWER

Figured out a workaround. I had previously seen this question/answer on SO:

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

Which suggested the creation of a ~/.pydistutils.cfg file to solve the --user problem. However, that file also creates incorrect behavior (as above) for installing packages with C extensions into --user. A better workaround is to, instead of having the ~/.pydistutils.cfg file, call pip with the following arguments:

pip install --user --install-option="--prefix" pygame

That installs pygame into --user without messing up the C extension install directories, at least on OSX.