Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

sudo pip install VS pip install --user

Tags:

python

pip

sudo

Can't remember where I read this, but either somewhere on here or in the comments of a tutorial I was following, a person said:

'Never never ever use sudo pip install; you could overwrite important stuff without knowing it. Use pip install --user instead!'

I see lots of references to sudo pip install everywhere though, so did this person know what they were talking about and I should avoid it, or... ?

like image 978
Chockomonkey Avatar asked Mar 27 '15 21:03

Chockomonkey


People also ask

What is difference between pip install and sudo pip install?

Usually the system packages are installed without write privileges for normal users so you must use sudo to elevate the privilege so pip can install to system packages. You can install a local copy of packages, ideally using virtualenv , where you wouldn't need elevated privileges.

What is pip install user?

The --user flag to pip install tells Pip to install packages in some specific directories within your home directory. This is a good way to have your own default Python environment that adds to the packages within your system directories, and therefore, does not affect the system Python installation.

Should I use sudo with pip install?

Never use sudo to install with pip. This is the same as running a virus as root. Either add your local folder to your PATH or use a virtualenv.

What is the difference between pip install and apt-get install?

apt-get is pre-compiled, which installs much faster than pip . To install numpy, matplotlib, pandas, and other scipy-related modules, apt-get only takes seconds; pip can easily consume 10min+. If you have root access and don't mind a little outdated versions, apt-get is the fast & worry-free way to go.


2 Answers

$ sudo pip install  

Installs the package globally in your python installation, i.e. for all users.

$ pip install --user 

Installs to the local user directory, i.e. ~/.local/lib/python -- just you.

Example:

$ sudo pip install jupyter $ jupyter notebook 

Will run jupyter, open a web browser, allow you to work with notebooks.

$ pip install --user jupyter $ jupyter notebook 

Will do nothing until your local directory has been added to your PATH.

There was recently malicious code included in pypi. Never use sudo to install with pip. This is the same as running a virus as root. Either add your local folder to your PATH or use a virtualenv.

like image 182
John Doe Avatar answered Sep 22 '22 06:09

John Doe


sudo pip install probably means that you want to install a package system-wide. For some packages, such as virtualenvwrapper, that might be useful, but besides that I'd avoid installing system-wide packages and create a virtualenv for each application and pip install to that virtualenv (which can be done without sudo).

like image 32
Peter Avatar answered Sep 25 '22 06:09

Peter