From 1f9c5e2f857547d1ec5bd7c5bc3c12f7a861c2c1 Mon Sep 17 00:00:00 2001 From: tiyn Date: Tue, 14 Jul 2026 02:50:37 +0200 Subject: [PATCH] Python: Added Arch-Migration for Globally Installed pip Packages --- wiki/linux/package_manager/pacman_and_aur.md | 69 +++++++++++++++++++- wiki/programming_language/python/pip.md | 31 ++++----- 2 files changed, 79 insertions(+), 21 deletions(-) diff --git a/wiki/linux/package_manager/pacman_and_aur.md b/wiki/linux/package_manager/pacman_and_aur.md index 5e2bdc5..576d194 100644 --- a/wiki/linux/package_manager/pacman_and_aur.md +++ b/wiki/linux/package_manager/pacman_and_aur.md @@ -2,13 +2,13 @@ In [Arch Linux](/wiki/linux/arch-linux.md) there are 2 main types of package managers. -The first is pacman, the default package manager. +The first is Pacman, the default package manager. For the second type there are many different managers to chose from. Those managers are handling for the Arch User Repositories (AUR). In this article yay is used as the go to AUR manager. -yay is also a wrapper for pacman so yay can be used instead of pacman to +yay is also a wrapper for Pacman so yay can be used instead of Pacman to install and update both AUR and main repository programs. It features the same syntax. @@ -204,6 +204,71 @@ pacman -F For example, this can be used to determine which package provides a missing binary, library or configuration file. +### Replacing Globally Installed Python Packages + +[Python](/wiki/programming_language/python.md) packages installed using +[pip](/wiki/programming_language/python/pip.md) are not managed by Pacman or Yay. +Whenever possible, Python packages should instead be installed using a +[package manager](/wiki/linux/package_manager.md) and the official repositories or the AUR. +This allows them to be updated together with the rest of the system and avoids conflicts with the +system package manager. + +However, project-specific dependencies should generally be installed inside +[virtual environments](/wiki/programming_language/python.md#venv-virtual-environments) instead of +globally. + +To begin replacing globally installed Python packages, first list all explicitly installed Python +packages. + +```sh +pacman -Qet | grep -E '^(python-|python3-)' +``` + +These packages are usually candidates to keep, as they are already managed by the system package +manager. + +Next check for Python packages that exist on the file system but are not owned by Pacman. +The following command searches the global Python installation for unmanaged packages. + +```sh +find /usr/lib/python*/site-packages -maxdepth 1 \ +| while read package; do + pacman -Qo "$package" >/dev/null 2>&1 || echo "$package" +done +``` + +Some manually installed packages may instead reside in `/usr/local`. +These can be listed using the following command. + +```sh +find /usr/local/lib/python*/site-packages -maxdepth 1 +``` + +For each package that is unmanaged or managed by another source than Pacman or Yay determine the +package name. +Then search whether it is available using Pacman or Yay. + +```sh +pacman -Ss +yay -Ss +``` + +If it is, uninstall the package. +For this pip could be used like shown in the following command. +Finally, reinstall the package using the Pacman or Yay. + +```sh +yay -S +``` + +Note that the packages may not have the same name. +Often the package has a prepended `python-` for Pacmand and Yay packages, however, this does not +have to be the case. + +Packages that are not available in either the official repositories or the AUR can still be +installed using tools such as [pip](/wiki/programming_language/python/pip.md) or +[uv](/wiki/programming_language/python/uv.md). + ### Hooks Hooks are commands that are run before or after installation of one or more packages. diff --git a/wiki/programming_language/python/pip.md b/wiki/programming_language/python/pip.md index 6800ce8..293fd9f 100644 --- a/wiki/programming_language/python/pip.md +++ b/wiki/programming_language/python/pip.md @@ -19,31 +19,24 @@ It is generally recommended to install packages inside a Alternatively, project-based package managers such as [uv](/wiki/programming_language/python/uv.md) can be used. -On some Linux distributions global installation may require the +Global installation using pip is not recommended and +[system package manager](/wiki/linux/package_manager.md#list-of-package-managers) should be +preferred. +When installing globally, however, on some Linux distributions global installation may require the `--break-system-packages` flag. ```sh pip install --break-system-packages ``` -This option should only be used if the package cannot be installed using the -[system package manager](/wiki/linux/package_manager.md#list-of-package-managers) or inside a -virtual environment. -### Removing Packages +### Migrating Global Packages to the System Package Manager -Installed packages can be removed by replacing `` with the package -name. +Due to it being more favorable to install global packages using a +[system package manager](/wiki/linux/package_manager.md) or a +[Python](/wiki/programming_language/python.md) package manager such as +[uv](/wiki/programming_language/python/uv.md) which is able to handle global installations, it may +be useful to migrate to a system package manager. -```sh -pip uninstall -``` - -### Creating a `requirements.txt` File - -To automatically create a `requirements.txt` file for the current project, -navigate to the project directory and run `pipreqs`. - -```sh -pipreqs . -``` +For [Arch Linux](/wiki/linux/arch-linux.md) systems the process for this is explained in the +[Pacman and AUR entry](/wiki/linux/package_manager/pacman_and_aur.md).