Python
Python is a scripting language ideal for that is unfortunately used as a systems language. Incompatible versions of the interpreter are dispatched by shebang and path resolution. Incompatible versions of libraries have to be strictly vendored.
System Installation
Arch
The very best, like no one ever was.
sudo pacman -Syyu python python-pip python-setuptools # or, sudo pacman -Syyu python2 python2-pip python2-setuptools
Older versions are available on the AUR as python37, python36, python26, etc.
Debian
Debian vendors Python heavily. Namely, they patch out the ensurepip module to enforce apt package control.
sudo apt install python3 python3-virtualenv python3-venv python3-setuptools python3-pip # or, sudo apt install python python-virtualenv python-venv python-setuptools python-pip
Ubuntu
A default version of Python is installed as a system dependency. Installing alternate versions of python that would hijack the path resolution of python3 is impossible.
The deadsnakes PPA provides alternate versions of Python with versioned names.
sudo add-apt-repository ppa:deadsnakes/ppa sudo apt-get update sudo apt install python3.8
Environment Setup
The python interpretor looks for modules on $PATH, appending its own libraries. Additional appends can be set in $PYTHONPATH.
Python has the ability to import modules from a zip archive, if the file's path is on $PATH.
A startup script can be set with $PYTHONSTARTUP.
Package Management
Before manually installing a Python package, check if your distribution offers the package. This will preempt incompatibility issues with system software later on, and ensure that the package is kept up-to-date.
pip
pip is the built-in tool for installing a Python package, either locally or from a repository such as PyPI.
It is always recommended to install packages as an individual user. The only reason that the default installation is global is for backwards compatibility. To install a package as a user, use pip --user.
Packages installed globally are found in /usr/lib/python#.#/site-packages, with executable scripts typically added to usr/bin. Packages installed for a user are found in ~/.local/lib/python#.#/site-packages, with executable scripts added to ~/.local/bin.
Pip will noisily complain about the format of its output changing years ago. To suppress the complaint, explicitly set the default behavior:
export PIP_FORMAT=columns
pipx
If a package is being installed solely for an executable, consider instead the pipx script. This is modeled after the tools available for NodeJS. It is a wrapper around pip and will only work with properly-configured packages (i.e., entry points declared in setup.py).
pipx generates virtual environments and managed symlinks to the executable. Virtual environments created by pipx are found in ~/.local/pipx (or $PIPX_HOME), with executable scripts linked to in ~/.local/bin (or PIPX_BIN_DIR).
