Unable to upgrade pip package

I just tried to update the pip package, but it didn’t work. The error message is as follows:

poplar@c004-h0:~> pip install --upgrade mkdocs
error: externally-managed-environment

× This environment is externally managed
╰─> To install Python packages system-wide, try
    zypper install python311-xyz, where xyz is the package
    you are trying to install.
    
    If you wish to install a non-rpm packaged Python package,
    create a virtual environment using python3.11 -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-rpm packaged Python application,
    it may be easiest to use `pipx install xyz`, which will manage a
    virtual environment for you. Install pipx via `zypper install python311-pipx` .

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.
poplar@c004-h0:~> 
poplar@c004-h0:~> pip --version
pip 23.1.2 from /usr/lib/python3.11/site-packages/pip (python 3.11)
poplar@c004-h0:~> python3 --version
Python 3.11.4
Operating System: openSUSE Tumbleweed 20230822
KDE Plasma Version: 5.27.7
KDE Frameworks Version: 5.109.0
Qt Version: 5.15.10
Kernel Version: 6.4.11-1-default (64-bit)
Graphics Platform: X11
Processors: 8 × Intel® Core™ i5-8250U CPU @ 1.60GHz
Memory: 15.4 GiB of RAM
Graphics Processor: Mesa Intel® UHD Graphics 620

I’m not quite sure where the problem is. Currently I use python3 -m venv .venv to work around the inability to upgrade packages.

The message suggests how you can work around this, at the risk of breaking system-managed packages. I actually was looking at this yesterday for a different reason.

If an updated mkdocs Python isn’t available as python311-mkdocs, you can override this by using --break-system-packages. You might also use --user to limit that breakage (since that would put the package in ~/.local rather than in the system Python library locations).

1 Like

@white-poplar the openSUSE Tumbleweed version of python-mkdocs is the latest available upstream released version?

No, not the latest version (python311-mkdocs) available in the openSUSE repositories. I downloaded and installed mkdocs 1.5.2 using pip pull from pypi (I also use mkdocs-material and other packages).

Some repositories I use don’t allow the latest version of pypi packages, they only depend on specific versions of pypi packages. So I don’t give priority to pypi packages in openSUSE repositories.

In this case, I believe a venv is your best shot. The messaging suggests pipx, would that work (not sure about other supplementary packages)?

I haven’t tried pipx, maybe it works :grinning:

This is system-wide pip, do not upgrade pip module via this, you can do this by using yast or zypper.
If you are trying to write some code that will use this module, creating a virtual environment by conda or poetry is a better choice.

1 Like