Differences between revisions 4 and 5
Revision 4 as of 2020-01-15 14:14:09
Size: 3261
Comment:
Revision 5 as of 2021-11-20 22:04:58
Size: 1596
Comment:
Deletions are marked like this. Additions are marked like this.
Line 1: Line 1:
= Python = = Python Installation =
Line 3: Line 3:
'''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. '''Python''' is a scripting language that is unfortunately used as a systems language.

<<T
ableOfContents>>
Line 8: Line 10:
== System Installation == == Windows ==
Line 10: Line 12:
=== Arch === ----
Line 12: Line 14:
The very best, like no one ever was.

== macOS ==

`brew`

----



== Linux ==

=== Arch Linux ===

On '''Arch Linux''' systems, `python` points to the most recent version. Older versions are available on the AUR as `python37`, `python36`, `python26`, etc.

Major libraries are offered as packages and should be preferred over [[Python/Pip|manual installation]].
Line 16: Line 34:
# or, sudo pacman -Syyu python2 python2-pip python2-setuptools
Line 18: Line 35:

Older versions are available on the AUR as `python37`, `python36`, `python26`, etc.
Line 25: Line 40:
On '''Debian''' systems, use `python3` rather than `python`. This operating system supported (and used) both Python 2 and Python 3 for an extended period of time, leading to widespread use of shebang lines as the method of dispatching to the correct executable.
Line 29: Line 46:
# or, sudo apt install python python-virtualenv python-venv python-setuptools python-pip
Line 36: Line 52:
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.
'''Ubuntu''' inherits the problems of Debian. The deadsnakes PPA provides alternate versions of Python with versioned names.
Line 50: Line 64:
== Environment Setup == == Configuration ==
Line 54: Line 68:
Python has the ability to import modules from a zip archive, if the file's path is on `$PATH`.
Line 57: Line 69:

----



== 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 [[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`.


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

Python Installation

Python is a scripting language that is unfortunately used as a systems language.


Windows


macOS

brew


Linux

Arch Linux

On Arch Linux systems, python points to the most recent version. Older versions are available on the AUR as python37, python36, python26, etc.

Major libraries are offered as packages and should be preferred over manual installation.

sudo pacman -Syyu python python-pip python-setuptools

Debian

On Debian systems, use python3 rather than python. This operating system supported (and used) both Python 2 and Python 3 for an extended period of time, leading to widespread use of shebang lines as the method of dispatching to the correct executable.

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

Ubuntu

Ubuntu inherits the problems of Debian. 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


Configuration

The python interpretor looks for modules on $PATH, appending its own libraries. Additional appends can be set in $PYTHONPATH.

A startup script can be set with $PYTHONSTARTUP.


CategoryRicottone

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