marksweb marksweb - 1 year ago 102
Python Question

Is it acceptable & safe to run pip install under sudo?

I've started to use my mac to install python packages in the same way I do with my Windows PC at work, however on my mac I've come across frequent

permission denied
errors writing log files & sometimes writing to site-packages.

Therefore I thought about running
pip install <package>
but is that a safe/acceptable use of sudo considering I'm just wanting this to be installed under my current user account.

Example traceback from a logfile I/O error;

Command /usr/bin/python -c "import setuptools;__file__='/Users/markwalker/build/pycrypto/';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/", line 116, in main
return command.main(args[1:], options)
File "/Library/Python/2.7/site-packages/pip-1.1-py2.7.egg/pip/", 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/", line 168, in open_logfile
log_fp = open(filename, mode)
IOError: [Errno 13] Permission denied: '/Users/markwalker/Library/Logs/pip.log'

I am able to install if I use
sudo pip install

Answer Source

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.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download