Shrimadhav U K

sudo pip install --user ThePythonPackage

Why this blog post?

Recently, I have seen various people recommending sudo pip install ThePythonPackage instead of pip install --user ThePythonPackage. So, why does it even matter? I tried to search on the Internet for a good reference that I can share when I am faced with this question, but was unable to find a good/ suitable one for the context. So, I decided to write one myself.

References Used

  • https://github.com/sindresorhus/guides/blob/master/npm-global-without-sudo.md

Why do people prefer the former command?

The fact is when we do a sudo pip install ThePythonPackage the package is installed to /usr/bin/ which is already in the $PATH environment variable, but the later recommended command does not offer this convenience. We need to manually add ${HOME}/.local/bin/ to the $PATH environment variable.

So, why bother with the inconvenience?

Let us take the example of the following Python package, (that I had written). Since, the people reading this blog can trust me, you will know that I have meant no harm, but the same cannot be said for the repositories with multiple contributors. In the open source world, trust is a simple and very complicated thing, and hence should be treated with great caution.

As you can see the above Python package has just two lines. A single os.system() command. So, it would be great if the readers of this blog could try to install the above package in a dummy system (maybe in a Virtual Machine or something ...) first with sudo python setup.py install and second with python setup.py install --user

Conclusion

Assuming that I have communicated clearly why it is injurious to run un-necassary commands with sudo. Debian users might be aware of the message that comes everytime they try to run sudo <command>!

1
2
3
4
5
6
7
8
9

We trust you have received the usual lecture from the local System
Administrator. It usually boils down to these three things:

#1) Respect the privacy of others.
#2) Think before you type.
#3) With great power comes great responsibility.

root's password:

Your friendly neighbourhood ഊളൻ, Shrimadhav U K