I follow some simple rules for Python packages.
- Never touch the OS site-packages with
- Never run pip with escalated privileges (
- Always use a local (
- Use the OS package manager when installing to
site-packagesto avoid competing package managers (pip and 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 2 packages in the user-environment:
pipsi. Make sure you are actually using the local pip by running
pip install virtualenv --user
Grab pipsi from GitHub and install it:
pipsi installs each package into
~/.local/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
pipsi to install
pew (a virtualenv manager):
pipsi install pew
pipsi --version 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.