I have tried to install any python packages on Ubuntu:24.04
, but found I cannot do that as in 22:04
PEP668 said it is for avoiding package conflict between system-wide package and user installed package.
But what's the differences between using pipx
and pip --user
? And why the --user
option not work, it also installs packages to the user's own home.
Example:
$ pip install setuptools --user
error: externally-managed-environment
× This environment is externally managed
╰─> To install Python packages system-wide, try apt install
python3-xyz, where xyz is the package you are trying to
install.
If you wish to install a non-Debian-packaged Python package,
create a virtual environment using python3 -m venv path/to/venv.
Then use path/to/venv/bin/python and path/to/venv/bin/pip. Make
sure you have python3-full installed.
If you wish to install a non-Debian packaged Python application,
it may be easiest to use pipx install xyz, which will manage a
virtual environment for you. Make sure you have pipx installed.
See /usr/share/doc/python3.11/README.venv for more information.
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.
But if I do that with pipx
:
$ pipx install pip
No apps associated with package pip or its dependencies. If you are attempting to install a library, pipx should not be used. Consider using pip or a similar tool instead.
I am really confused with current rules.
How can I manage my user global environment now? And how can I use latest pip
(not linux-distro version) and other packages by default for current user?
My environment:
FROM ubuntu:24.04
# add python
RUN apt install -y python3-pip python3-venv python-is-python3 pipx
USER ubuntu
WORKDIR /app
pip --user
is a function provided by pip, and pipx is a software package. Ubuntu can guarantee that the packages you install using pipx will not pollute the system environment, but pip does not have this guarantee.
Additionally, you should install setuptools using apt install python3-setuptools
.