Feb 16 '21

PIP and the user directory

This is a quick note about python + pip best practices: never use sudo pip! It creates files only readable by root and breaks your python install.

Instead, always run pip install with –user:

# E.g.
pip install --user <package>

# Or
/path/to/specific/python -m pip install --user <package>

After installing packages, python should already be searching the user director as part of sys.path.

Related error from not doing this: stackoverflow.com: ImportError: No module named virtualenv

What’s the difference? stackoverflow.com: sudo pip install VS pip install –user

Also, versioned dependencies is a nightmare and not installing random packages system wide is a good thing. Using virtualenv and alternatives is also good: stackoverflow.com: What is a virtualenv, and why should I use one?

python -m venv env
. env/bin/activate

which python
# prints /here/env/bin/python
which pip
# prints /here/env/bin/pip

pip install <package>
There are no comments yet.