为什么在每次安装pip之前都必须输入`sudo`? [英] Why do I have to type `sudo` before every pip install?

查看:303
本文介绍了为什么在每次安装pip之前都必须输入`sudo`?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在安装软件包时,以我的用户名登录,除非执行以下操作,否则我总是会被拒绝权限:

When installing packages, logged as my username, I always get permission denied unless I do:

sudo pip install.

我如何做到这一点,所以这是没有必要的?还是应该这样?

How can I make it so this is not necessary? Or is this supposed to be like that?

推荐答案

或者,如问题注释中所述,我将使用virtualenv,或者利用python的PYTHON_USERBASE为您的用户安装模块:

Either, I would use virtualenv, as mentioned in comments to the question, or, leverage python's PYTHON_USERBASE to install modules only for your user:

在您的.bashrc中添加:

In your .bashrc add:

export PYTHON_USERBASE=~/python_userbase

然后下载您的软件包,将其解压缩,进入生成的目录,然后运行:

then download your package, extract it, go inside the resulting dir, and run:

python setup.py install --user

或简单地使用:

pip install <package> --user

它们都将以〜/python_userbase/lib/pythonXXX/site-packages结尾,并且不会损坏系统的site-packages

They'll all end up in ~/python_userbase/lib/pythonXXX/site-packages and not damage your system's site-packages

参考:

pep-0370

最后一次,这是与Unix相关的,您可以修改/etc/sudoers并授予您用户以root用户身份执行pip的权限.但我强烈劝阻您不要这样做.

The last thing, this time, Unix related, you could modify /etc/sudoers and grant your user the rights to execute pip as root. But I would highly discourage you from doing this.

这篇关于为什么在每次安装pip之前都必须输入`sudo`?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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