【发布时间】:2013-02-22 16:21:22
【问题描述】:
我已经开始使用我的 Mac 安装 Python 包,就像在工作中使用我的 Windows PC 一样;但是在我的 Mac 上,我在写入日志文件或站点包时经常遇到 permission denied 错误。
因此我考虑在sudo 下运行pip install <package>,但考虑到我只是希望将其安装在我当前的用户帐户下,这是安全/可接受的使用 sudo 吗?
来自日志文件 I/O 错误的示例回溯:
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'
更新
这可能取决于权限,但是最好的方法是为您的 python 项目使用虚拟环境。除非绝对必要,否则应避免运行sudo pip。
【问题讨论】:
-
我发现 '
cd /tmp; sudo pip install foo' 是一个合适的解决方法。 -
@pradyunsg 为什么要举报这么老的问题?
-
本质上,当前接受的答案(以及问题中的更新)建议运行“sudo pip”——pip 的维护者(我自己就是其中之一)积极地告诉人们不要这样做这可能会导致您在 MacOS 和许多(全部?)主要 Linux 发行版上的操作系统崩溃。我登陆这里时使用的术语是有人调试他们的情况可能并且只是想让这将人们重定向到一个有更好建议的位置。没有考虑过实际提出这个问题,它的答案更好地符合上述陈述。 (超出字符)
-
@markwalker_ 您是否愿意从问题中删除该建议并可能用更好的建议(使用 --user 或 virtualenv)替换它?