在sudo下运行pip install是否可以接受并且安全? [英] Is it acceptable and safe to run pip install under sudo?

查看:96
本文介绍了在sudo下运行pip install是否可以接受并且安全?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经开始使用Mac来安装Python软件包,就像在工作Windows PC时一样.但是,在我的Mac上,写入日志文件或网站程序包时,经常遇到权限被拒绝错误.

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 while writing to log files or site-packages.

因此,我考虑过在sudo下运行pip install <package>,但是考虑到我只是想将此安装在我当前的用户帐户下,是安全/可接受的sudo使用吗?

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

从日志文件I/O错误回溯的示例:

Example traceback from a logfile I/O error:

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.

Update This was likely down to permissions, however the best approach is to use virtual environments for your python projects. Running sudo pip should be avoided unless absolutely necessary.

推荐答案

使用虚拟环境:

$ virtualenv myenv
.. some output ..
$ source myenv/bin/activate
(myenv) $ pip install what-i-want

要为全局,系统范围的Python安装安装内容时,仅使用sudo或提升的权限.

You only use sudo or elevated permissions when you want to install stuff for the global, system-wide Python installation.

最好使用虚拟环境为您隔离软件包.这样一来,您就可以在不影响全局python安装的情况下进行游戏.

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.

作为奖励,virtualenv不需要提升的权限.

As a bonus, virtualenv does not need elevated permissions.

这篇关于在sudo下运行pip install是否可以接受并且安全?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆