简体   繁体   English

推荐使用 pip 和无 sudo 权限安装 Python 包的方法

[英]Recommended way to install a Python package with pip and no sudo privileges

I usually just use the command:我通常只使用命令:

pip install --user <package>

but I've seen here that this:但我在这里看到:

pip install <package> --install-option="--prefix=~"

can also be used to bypass the need for sudo privileges.也可用于绕过对sudo权限的需求。 About this command the site says:关于这个命令,网站说:

There is also a –user option with pip install, which installs into ~/.local. pip install 还有一个 –user 选项,它安装到 ~/.local 中。 This is fine for the python module, but it puts the corr2 executable into ~/.local/bin, which is probably not in your path.这对于 python 模块来说很好,但它会将 corr2 可执行文件放入 ~/.local/bin,它可能不在您的路径中。 The above command will instead install corr2 into ~/bin.上面的命令会将 corr2 安装到 ~/bin 中。

So apparently it does not behave the same way as the first command.所以显然它的行为方式与第一个命令不同。

Is one way preferred over the other and if so why?一种方式是否优于另一种方式,如果是,为什么?

The official Python package installation guide is here:官方 Python 包安装指南在这里:

https://packaging.python.org/en/latest/installing.html https://packaging.python.org/en/latest/installing.html

It recommends creating Python virtual environments per project using virtualenv command (or python3.4 -m venv ).它建议使用virtualenv命令(或python3.4 -m venv )为每个项目创建Python 虚拟环境

This is because if you are working with multiple Python projects they have different dependencies and having per project installation environments is the sane way to deal with this in Python.这是因为如果您正在处理多个 Python 项目,它们具有不同的依赖项,并且每个项目的安装环境都是在 Python 中处理此问题的明智方法。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM