I follow some simple rules for Python packages.
- Never touch the OS site-packages with
- Never run
pipwith escalated privileges (
- Always use a local (
- Use the OS package manager when installing to
site-packagesto avoid competing package managers (
yum, for example)
python3 -m site python3 -m user-site
Read up on the Python docs and the pip docs to get a better understanding.
how to win
Assuming you have no traces of pip left.
get-pip.py from the official pip website and install it under
python3 get-pip.py --user --ignore-installed
After this command succeeds, a
pip binary will be placed in
~/.local/bin. Make sure you have this folder prepended to your
Once pip is installed and set up we will install only one more package
in the user-environment:
Make sure you are actually using the local pip by running
pip install --user pipx
pipx installs each package into
~/.local/pipx/venvs/PKGNAME and then
symlinks the scripts (CLI entry points) into
~/.local/bin. This makes
it so you don’t have to activate the virtual environments manually to
use the programs.
We can use
pipx to install
pew (a virtualenv manager):
pipx install pew
pipsi as it lets you easily upgrade the virtual
environments after a system upgrade of Python (see #146):
pipx --version pipx list pip -V
I like to follow the same principles for Jupyter notebooks.
pipsi install notebook
Create a virtualenv that can be used as a notebook kernel:
pew new pandas3 --python=python3 pip install ipykernel pip install pandas
Create the kernel spec:
ipykernel install --user --name 'python3-pandas' --display-name 'Python 3 (venv pandas3)'
It will be placed in
Whenever you want to use
pandas in Jupyter you create a new notebook with this kernel.
I use the OS package manager to install some packages, for example
python2-neovim in the Debian repos. Hopefully they are
optimized to work with the
Now, tell me how to do it even better.
- <2020-02-16 Sun> - Recommend
- <2020-02-16 Sun> - Don’t install
python3 -m venvinstead)