1

To preface, I'm currently running OSX 10.9.1 with Python 2.7.

I would like to install Python packages using easy_install (in this example, pip). First I try:

easy_install pip

And then I get an error that says that I do not have write access to the site-packages directory. No problem:

sudo easy_install pip

Everything downloads fine. The following shows the Bash session I have after installing pip:

$ pip
-bash: /usr/local/bin/pip: Permission denied
$ cd /usr/local/bin/pip
$ ls -l

...
-rwx------  1 root   admin       275 Jan 10 11:05 pip
...

$ chmod 754 pip
chmod: Unable to change file mode on pip: Operation not permitted
$ sudo chmod 754 pip
$ pip
Traceback (most recent call last):
  File "./pip", line 5, in <module>
    from pkg_resources import load_entry_point
  File "build/bdist.macosx-10.8-intel/egg/pkg_resources.py", line 3007, in <module>

  File "build/bdist.macosx-10.8-intel/egg/pkg_resources.py", line 728, in require
    requirements specified when this environment was created, or False
  File "build/bdist.macosx-10.8-intel/egg/pkg_resources.py", line 626, in resolve

pkg_resources.DistributionNotFound: pip==1.5

Ok, so maybe there some of the permissions are still messed up. Here's what Finder shows me when I view /Library/Python/2.7/site-packages/:

No permission

And here's what ls -l returns when viewing that same directory:

...
drwx------   4 root  wheel     136 Jan 10 11:24 pip-1.5-py2.7.egg
...

Ok, so I obviously don't have permission to use pip still because I don't have execute permission on the archive file. How about:

$ chmod 754 pip-1.5-py2.7.egg
chmod: Unable to change file mode on pip-1.5-py2.7.egg/: Operation not permitted
$ sudo chmod 754 pip-1.5-py2.7.egg
$ pip
Traceback (most recent call last):
  File "/usr/local/bin/pip", line 9, in <module>
    load_entry_point('pip==1.5', 'console_scripts', 'pip')()
  File "build/bdist.macosx-10.8-intel/egg/pkg_resources.py", line 378, in load_entry_point
    def get_resource_stream(manager, resource_name):
  File "build/bdist.macosx-10.8-intel/egg/pkg_resources.py", line 2565, in    load_entry_point
    section = line[1:-1].strip()
ImportError: Entry point ('console_scripts', 'pip') not found

My hypothesis is that all of the permissions are screwed up because I used sudo and now I'm just chasing around permissions. This may be wrong, though. I never remember having this problem before upgrading to OSX 10.9.

My questions are: do Unix systems always do this with sudo, even though I'm the computer's administrator? Is there a way for me to permanently correct this so that I actually have permission to run installed packages? Do you think there is a setting somewhere on my system that's incorrect?

Thanizer
  • 382
  • 1
  • 6
  • 21
  • 1
    reason number 273 not to upgrade to Mavericks... – MattDMo Jan 10 '14 at 17:46
  • 1
    @Thanizer, have you run `disk utility` and repaired permissions? that might be a good place to start. also chmod 754 isn't going to cut it, you need to use 755 and have `owner root`, `group wheel` for that. – l'L'l Jan 10 '14 at 19:33
  • @I'L'I, I just repaired the permissions to no avail. Right now I'm just using the Python formula for Homebrew and everything seems to be working fine. I'd still like to know why I can't use OSX's native `easy_install` script, though, without having permissions issues. – Thanizer Jan 11 '14 at 18:18

1 Answers1

1

Your hypothesis is correct all of the permissions are screwed up because you used sudo. Start by breaking yourself of that habit of using sudo to 'fix' problems. You should think just as long and hard about doing stuff with sudo as you would logging in as root. If your attitude is "no problem: sudo ..." you are (eventually) in for a world of hurt. Every time you use sudo you are making one more change to the way OSX arrived out of the box.

Next, get out of the habit of trying to put everything into the operating system's version of python. I'd recommend first clearing out your /usr/local, although that may be asking a lot.

Then brew install python - get yourself a pristine python. Good - you've already done that.

which pip - make sure you are using the pip brew just installed in /usr/local; if not adjust your ~/.bashrc start up file as necessary.

Next brew install virtualenv and brew install virtualenvwrapper - make it so when you pip install something to support a project that that only effects that one project. While you are at it add export PIP_REQUIRE_VIRTUALENV=true to your ~/.bashrc so you don't forget and mess up in the future.

Now get to know virtualenv and start understanding the true dependencies of your projects and stop fighting conflicts caused by different projects' requirements interfering with each other and the general bit rot that the indiscriminate use of sudo will cause you.

jwd630
  • 4,529
  • 1
  • 20
  • 22
  • awesome answer. Although, are you sure about `brew install virtualenv` because doing that gives the error - `No available formula with the name "virtualenv" . These similarly named formulae were found:pyenv-virtualenv ` ? – user1993 May 23 '18 at 21:34
  • The answer above was based on 2014 reality. The world of Python has changed a lot since then. This [What is the relationship between virtualenv and pyenv](https://stackoverflow.com/a/29950604/1124740) might be helpful. – jwd630 May 25 '18 at 11:23