Reputation: 12859
When I try to install Python packages on my Mac at home, I frequently get permission errors from attempts to write to log files or to the site-packages
directory, like so:
Command /usr/bin/python -c "import setuptools;__file__='/Users/markwalker/build/pycrypto/setup.py';exec(compile(open(__file__).read().replace('\r\n', '\n'), __file__, 'exec'))" install --single-version-externally-managed --record /var/folders/tq/hy1fz_4j27v6rstzzw4vymnr0000gp/T/pip-k6f2FU-record/install-record.txt failed with error code 1 in /Users/markwalker/build/pycrypto
Storing complete log in /Users/markwalker/Library/Logs/pip.log
Traceback (most recent call last):
File "/usr/local/bin/pip", line 8, in <module>
load_entry_point('pip==1.1', 'console_scripts', 'pip')()
File "/Library/Python/2.7/site-packages/pip-1.1-py2.7.egg/pip/__init__.py", line 116, in main
return command.main(args[1:], options)
File "/Library/Python/2.7/site-packages/pip-1.1-py2.7.egg/pip/basecommand.py", line 141, in main
log_fp = open_logfile(log_fn, 'w')
File "/Library/Python/2.7/site-packages/pip-1.1-py2.7.egg/pip/basecommand.py", line 168, in open_logfile
log_fp = open(filename, mode)
IOError: [Errno 13] Permission denied: '/Users/markwalker/Library/Logs/pip.log'
I only want the package to be installed under my current user account. How do I resolve the permission errors? Should I use sudo
anyway?
Upvotes: 130
Views: 192306
Reputation: 42425
Using sudo
for Pip is not safe, and is discouraged.
To install Python package in your home directory you don't need root privileges. Instead, use Pip's --user
option.
Upvotes: 49
Reputation: 16122
I had a problem installing virtualenvwrapper
after successfully installing virtualenv
.
My terminal complained after I did this:
pip install virtualenvwrapper
So, I unsuccessfully tried this (NOT RECOMMENDED):
sudo pip install virtualenvwrapper
Then, I successfully installed it with this:
pip install --user virtualenvwrapper
Upvotes: 5
Reputation: 1746
Your original problem is that pip cannot write the logs to the folder.
IOError: [Errno 13] Permission denied: '/Users/markwalker/Library/Logs/pip.log'
You need to cd into a folder in which the process invoked can write like /tmp
so a cd /tmp
and re invoking the command will probably work but is not what you want.
BUT actually for this particular case (you not wanting to use sudo
for installing python packages) and no need for global package installs you can use the --user
flag like this :
pip install --user <packagename>
and it will work just fine.
I assume you have a one user python python installation and do not want to bother with reading about virtualenv (which is not very userfriendly) or pipenv.
As some people in the comments section have pointed out the next approach is not a very good idea unless you do not know what to do and got stuck:
Another approach for global packages like in your case you want to do something like :
chown -R $USER /Library/Python/2.7/site-packages/
or more generally
chown -R $USER <path to your global pip packages>
Upvotes: 28
Reputation: 291
Because I had the same problem, I want to stress that actually the first comment by Brian Cain is the solution to the "IOError: [Errno 13]"-problem:
If executed in the temp directory (cd /tmp
), the IOError does not occur anymore if I run sudo pip install foo
.
Upvotes: 9
Reputation: 34667
It looks like your permissions are messed up. Type chown -R markwalker ~
in the Terminal and try pip
again? Let me know if you're sorted.
Upvotes: 4
Reputation: 174622
Use a virtual environment:
$ virtualenv myenv
.. some output ..
$ source myenv/bin/activate
(myenv) $ pip install what-i-want
You only use sudo
or elevated permissions when you want to install stuff for the global, system-wide Python installation.
It is best to use a virtual environment which isolates packages for you. That way you can play around without polluting the global python install.
As a bonus, virtualenv does not need elevated permissions.
Upvotes: 110