简体   繁体   中英

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. About this command the site says:

There is also a –user option with pip install, which installs into ~/.local. This is fine for the python module, but it puts the corr2 executable into ~/.local/bin, which is probably not in your path. The above command will instead install corr2 into ~/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:

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

It recommends creating Python virtual environments per project using virtualenv command (or python3.4 -m venv ).

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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