Differences between revisions 3 and 4
Revision 3 as of 2019-12-07 17:08:18
Size: 1696
Comment:
Revision 4 as of 2020-01-15 14:14:09
Size: 3261
Comment:
Deletions are marked like this. Additions are marked like this.
Line 1: Line 1:
= System Installation = = Python =
Line 3: Line 3:
== Arch == '''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.
Line 14: Line 23:
== Debian == === Debian ===

Debian vendors Python heavily. Namely, they patch out the `ensurepip` module to enforce `apt` package control.
Line 21: Line 32:
Debian patches out the `ensurepip` module to enforce `apt` package control.
Line 24: Line 34:
=== Ubuntu ===
Line 25: Line 36:
== 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.
Line 27: Line 38:
A default version of Python should work out-of-the-box. For alternate versions, use the deadsnakes PPA: The deadsnakes PPA provides alternate versions of Python with versioned names.
Line 32: Line 43:
sudo apt install python#.# sudo apt install python3.8
Line 34: Line 45:

----
Line 37: Line 50:
= Environment Setup =

== Python Path ==
== Environment Setup ==
Line 47: Line 58:
----
Line 49: Line 61:
== Pip ==
Line 51: Line 62:
Packages installed globally are found in `/usr/lib/python#.#/site-packages`; packages installed for a user are found in `~/.local/lib/python#.#/site-packages`. == Package Management ==
Line 53: Line 64:
Virtual environments created by pipx are found in `~/.local/pipx`; executables are installed to `~/.local/bin`. These are configurable by `$PIPX_HOME` and `PIPX_BIN_DIR` respectively. 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 [[https://pypi.org/|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`.
Line 63: Line 85:
=== 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`).


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).


CategoryRicottone

Python/Installation (last edited 2021-11-20 22:05:16 by DominicRicottone)