I know, my question is the noobiest, but I’m not a programmer and I restarted to get into coding after a couple of years. So, I need to install a module that pipx won’t install because it says to use pip. But if I use pip, the terminal says to use pipx. Not so easy to understand how the two works for a total newbie (and imho, absolutely incompatible with the easy approach of python)… anyway, how can I solve this incredibly easy task?
pip and pipx are used for fundamentally different things: the former for installing packages you want use via and import and the latter for programs you want use from the commandline.
While you can use pip for the latter usecase, you cannot use pipx for the former. Which of those two usecases do you want to do? What is the exact & complete output pip gives you?
pip install constantserror: externally-managed-environment
× This environment is externally managed╰─> To install Python packages system-wide, try ‘pacman -Spython-xyz’, where xyz is the package you are trying toinstall.
If you wish to install a non-Arch-packaged Python package,
create a virtual environment using 'python -m venv path/to/venv'.
Then use path/to/venv/bin/python and path/to/venv/bin/pip.
If you wish to install a non-Arch packaged Python application,
it may be easiest to use 'pipx install xyz', which will manage a
virtual environment for you. Make sure you have python-pipx
installed via pacman.
note: If you believe this is a mistake, please contact your Python installation or OS distribution provider. You can override this, at the risk of breaking your Python installation or OS, by passing --break-system-packages.
hint: See PEP 668 for the detailed specification.
It sounds like what’s happening is that your default Python environment is the one managed by your operating system (Arch). This environment is used for tools you may have installed by your system package manager (pacman).
A system package ‘X’ may depend on a Python package in this environment, pip
doesn’t know about ‘X’ as it only cares about Python packages so it would happily replace or remove the Python package that ‘X’ depends on if asked, likely breaking ‘X’ and potentially the whole system.
Anyway it sounds like you are trying to install a library so you can use it from within Python code.
For development the most direct solution is to create a virtual environment in the folder where you are working on your code.
# Create the virtual environment
python -m venv .venv
# Make this new virtual environment the default in this shell session
# Note that in every new shell you will need to rerun this command
source .venv/bin/activate
# Install packages into this new environment
python -m pip install <packagename>
# Launch interactive python in this environment
python
If you are using an editor to work on code it may automatically detect the .venv
folder and use it for you.
There are other tools such as uv that provide more streamlined workflows but internally they are roughly doing the same as the steps given above[1].
For example with uv
you could approximate the series of commands given above with this one command:
uv run --with <packagename> python
Although in the case of
uv
with their own implementation ofpip
andvenv
functionality. ↩︎