From 2b53bad9c9c5281f8c459701002740ea4b5b8bf8 Mon Sep 17 00:00:00 2001 From: Michele Cereda Date: Sat, 4 Feb 2023 15:49:31 +0100 Subject: [PATCH] Added pip article to the KB --- knowledge base/pip.md | 57 ++++++++++++++++++++++++++++++++++++++++ knowledge base/python.md | 23 ++++------------ 2 files changed, 62 insertions(+), 18 deletions(-) create mode 100644 knowledge base/pip.md diff --git a/knowledge base/pip.md b/knowledge base/pip.md new file mode 100644 index 0000000..f652bd7 --- /dev/null +++ b/knowledge base/pip.md @@ -0,0 +1,57 @@ +# PIP + +Package installer for Python. + +1. [TL;DR](#tldr) +2. [Configuration](#configuration) +3. [Further readings](#further-readings) + +## TL;DR + +```sh +# Install packages. +pip install 'yamllint' +pip install --user 'ansible' + +# Upgrade packages. +pip install -U 'pip' + +# Upgrade the included `pip` executable on Mac OS X. +~/Library/Python/3.8/bin/pip3 install --user --upgrade 'pip' + +# Upgrade all currently installed packages. +pip install --requirement <(pip freeze | sed 's/==/>=/') --upgrade + +# Generate a list of the outdated packages. +pip list --outdated + +# Remove orphaned dependencies. +# Requires `pip-autoremove`. +pip-autoremove +``` + +## Configuration + +INI format files, on those levels: + +Level | Scope | File locations +---|---|--- +global | System-wide, shared | The `pip` subdirectory in any of the directories defined in `XDG_CONFIG_DIRS` if it exists (i.e. `/etc/xdg/pip/pip.conf`)
`/etc/pip.conf` +user | Per-user | `$HOME/.config/pip/pip.conf`
`$HOME/.pip/pip.conf` (legacy) +site | Per-environment | `$VIRTUAL_ENV/pip.conf` +shell | Active shell session | Value of `PIP_CONFIG_FILE` + +When multiple configuration exist, pip **merges** them in the following order: + +1. shell +1. global +1. user +1. site + +Latter files override values from previous files, i.e. the global timeout specified in the global file will be superseded by the one defined in the user file. + +## Further readings + +- [Configuration] + +[configuration]: https://pip.pypa.io/en/stable/topics/configuration/ diff --git a/knowledge base/python.md b/knowledge base/python.md index aa7f5e9..7d840a6 100644 --- a/knowledge base/python.md +++ b/knowledge base/python.md @@ -18,23 +18,6 @@ F"{name.lower()} is funny." unique_list = list(set(redundant_list)) ``` -Maintenance: - -```sh -# Generate a list of the outdated packages. -pip list --outdated - -# Upgrade all packages. -pip install --requirement <(pip freeze | sed 's/==/>=/') --upgrade - -# Remove orphaned dependencies. -# Requires `pip-autoremove`. -pip-autoremove - -# Upgrade the included `pip` executable on Mac OS X. -~/Library/Python/3.8/bin/pip3 install --user --upgrade pip -``` - ## Web servers ### Flask @@ -93,10 +76,11 @@ python hello.py ## Further readings +- [PIP] - [How To Update All Python Packages] - [invl/pip-autoremove] - [Data types] -- [F-strings +- [F-strings] - [How to filter list elements in Python] - [Logging] - [Flask at first run: do not use the development server in a production environment] @@ -106,6 +90,9 @@ python hello.py - [An intro to threading in Python] - [ThreadPoolExecutor in Python: the complete guide] + +[pip]: ./pip.md + [*args and **kwargs in python]: https://www.geeksforgeeks.org/args-kwargs-python/ [an intro to threading in python]: https://realpython.com/intro-to-python-threading/