sudo pip install VS pip install –user

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… ?

Answers:

Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.

Method 1

$ 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.

Method 2

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).


All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x