don't sudo pip

it's insanely dangerous. don't believe me? try it:

sudo pip install russian_roulette

don't sudo pip install, ever

You're paranoid. What's the big deal?

Running sudo pip install package-x is insanely dangerous. It is equivalent to giving a complete stranger root access on your machine.
You run pip as sudo, and pip runs as sudo, and can run system commands. case you're wondering, that's bad.

happy to sad

What could possibly go wrong?

A couple of things.

First, typosquatting. You could make a typo or spelling mistake when installing a package, and a malicious typosquatting package could be installed instead. Imagine running sudo pip install uincode and installing a malicious package uincode, instead of sudo pip install unicode like you wanted.

Second, unintentional vulnerabilities. Developers of a package may unintentionally expose a security hole that, when run as root, turns a minor security risk into a major one. Say hello to bad dudes cruising the internet.

Third, you could squash your system python. Many modern operating systems come with a system python that should be updated infrequently. Tacking on a sudo command could install packages that break your system.

Last, malicious packages. People do evil shit, especially when money's involved.

some men just wanna watch the world burn

What should I do instead?

Use pyenv to maintain separate, side-by-side versions of Python.

Use virtualenv to install software into an isolated Python environment.

Add the --user flag to install to your home directory, obviating the need for sudo: pip install --user package-x

(At the very least, set up your Python so it doesn't require sudo access each time it installs things.)

How do I adjust my mindset?

So just remind yourself of this, each time you type pip: can run system commands. can run system commands. can run system commands.

Never forget. Don't be a sheep. Trust no one.

Contact charlesreid1

@charlesreid1 is a full-time data engineer and part-time bot-wrangler working on bioinformatics problems at UC Davis.

Get in touch:

charles (at)