[HowTo] Remove latest AUR Python before System Python upgrade

Remove latest AUR Python before System Python upgrade

CAUTION:

These instruction were written in June 2023, when a system
update containing a new version of Python became available.

DO NOT do them now
unless you are sure that you are in a similar situation,
as you might unintentionally uninstall your system Python,
and then your system will not start.


If you installed the latest version of Python from AUR
before it was available from Arch or Manjaro repositories
and those system repositories now have that latest version
you MUST remove the AUR package before upgrading the system.

The new system Python needs to be installed into the same directories
that are now occupied by your AUR Python, and it will not install correctly
if you do not uninstall your AUR Python.

This was written for Python 3.11,
and the version numbers are “hard-coded” in the text for now.


Note that the name of the AUR package is ‘python311’ with a small P and no dot.

Python 3.11 was so late arriving in Arch/Manjaro repos that it’s more
likely than usual that users have installed python311 from the AUR.

Your AUR-python311 is installed in exactly the same path that
system Python 3.11 will occupy after the upgrade: ‘/usr/lib/python3.11/’.
If you leave it there, pacman will not install the new system Python.

But if you leave ‘site-packages’ in place, the packages there
might be usable under the new system Python (explained under Option 2).

List your site-packages?

These lists can be used after the upgrade. When re-installing from Python 3.10
to the new system Python 3.11, you can add packages from these lists as well.

  • pacman -Qnq $(pacman -Qoq /usr/lib/python3.11/site-packages) > AUR311_SYS_pkgs.txt

  • pacman -Qmq $(pacman -Qoq /usr/lib/python3.11/site-packages) > AUR311_AUR_pkgs.txt

(pip won’t work if you didn’t install it; in which case you do not need to run this.)

  • python3.11 -m pip freeze --user > AUR311_PIP_pkgs.txt

Option 1: remove everything

If you do not want to keep any packages:

  • sudo pacman -Rsu python311

Make sure ‘site-packages’ is gone as well.
CAUTION! Don’t nuke the wrong version.

  • sudo rm -rIv /usr/lib/python3.11

It won’t hurt to skip the next command, because
pip packages will probably work under the new system Python.

  • rm -rIv $HOME/.local/lib/python3.11

Remove pip for 3.11 as well, as it may over-ride pip for 3.10.
(pip for 3.10 is in /usr/bin/, so this can’t remove it.)

  • rm -vi ~/.local/bin/pip ~/.local/bin/pip3 ~/.local/bin/pip3.11

That’s it, you’ve finished here.

Go back to re-installing packages around a system python upgrade


Option 2: keep some packages?

If you recently installed some very heavy packages
and you don’t have enough data allowance to download them again,
here are the points to consider.

When upgrading system Python,
pacman leaves ‘site-packages’ directories in place if they are not empty.
So your packages under python311 might survive the upgrade
and function correctly under the new system Python.

Keeping everything in ‘~/.local/lib/python3.11/site-packages’ is safe,
and up-to-date pip packages will probably work under the new system Python.

The rest of this is about ‘/usr/lib/python3.11/site-packages’,
where system and AUR packages are installed.

After the upgrade, packages that are of the latest version should work.
Packages that are older will likely cause version conflicts.

During the upgrade, AUR packages should be OK.

But with packages from Manjaro repos, I don’t know what pacman will do.
If it can recognize that it already has the required packages,
and not download them again, then keeping them might work.

It’s probably safe to keep them and see what happens, if you know
how to deal with “exists in file-system” errors, or version conflicts

If you want to uninstall only some packages, you can edit copies
of your list files and use the copies in the uninstall commands below.
(For pip you can comment out a package name with #,
but for pacman you may need to completely remove it.)

If you decide NOT to keep any packages, go back and do Option 1.
(The commands here are a bit different.)

  1. Uninstall some or all packages now (if you decided to do so)

    • sudo pacman -Rsu $(< AUR311_SYS_pkgs.txt)

    • sudo pacman -Rsu $(< AUR311_AUR_pkgs.txt)

    • python3.11 -m pip uninstall -r AUR311_PIP_pkgs.txt

  2. Uninstall AUR-python311

    Use your usual AUR helper, or do

    • sudo pacman -Rsu python311

    Remove pip as well:

    • rm -vi ~/.local/bin/pip ~/.local/bin/pip3 ~/.local/bin/pip3.11

    For this we do not delete ‘site-packages’ directories.


Back to re-installing packages around a system python upgrade.