Communities

Writing
Writing
Codidact Meta
Codidact Meta
The Great Outdoors
The Great Outdoors
Photography & Video
Photography & Video
Scientific Speculation
Scientific Speculation
Cooking
Cooking
Electrical Engineering
Electrical Engineering
Judaism
Judaism
Languages & Linguistics
Languages & Linguistics
Software Development
Software Development
Mathematics
Mathematics
Christianity
Christianity
Code Golf
Code Golf
Music
Music
Physics
Physics
Linux Systems
Linux Systems
Power Users
Power Users
Tabletop RPGs
Tabletop RPGs
Community Proposals
Community Proposals
tag:snake search within a tag
answers:0 unanswered questions
user:xxxx search by author id
score:0.5 posts with 0.5+ score
"snake oil" exact phrase
votes:4 posts with 4+ votes
created:<1w created < 1 week ago
post_type:xxxx type of post
Search help
Notifications
Mark all as read See all your notifications »
Q&A

Welcome to Software Development on Codidact!

Will you help us build our independent community of developers helping developers? We're small and trying to grow. We welcome questions about all aspects of software development, from design to code to QA and more. Got questions? Got answers? Got code you'd like someone to review? Please join us.

Post History

77%
+5 −0
Q&A Reinstall old Python libraries after update

It depends. Pure Python is usually forward-compatible with newer minor versions, but this is not always the case. Features/modules that were available in a previous minor version may no longer be ...

posted 7mo ago by Hackysack‭

Answer
#1: Initial revision by user avatar Hackysack‭ · 2024-06-01T17:47:46Z (7 months ago)
It depends.

Pure Python is usually forward-compatible with newer minor versions, but this is not always the case. Features/modules that were available in a previous minor version may no longer be available in the next minor version. Some features may not behave in the same way as in a previous minor version.

Packages that make use of C extensions, such as `numpy`, are even more likely to have compatibility issues between minor versions (and even micro/patch versions). Cython makes for a good example, here. Cython takes Python code and converts it to C code. If you use Cython to compile Python 3.11 code, it will work in all micro/patch versions of 3.11 (meaning 3.11.0, 3.11.1, 3.11.2, etc), but not for any other minor version. Then again, the same Python code that was compiled with Cython may be valid in multiple minor versions (in other words, the underlying Python 3.11 code may also be valid 3.12 code and compile with Cython just fine).

In short, it's difficult to know which specific packages will be forward-compatible with newer minor versions, meaning that simply copying the package directories from one installation of Python to another is risky, at best. Unless one is willing to scour the source code of each package in order to verify compatibility, then your best bet is to just use the traditional/conventional methods of reinstalling the packages.

---

I'm not sure how your Python is installed, but it sounds like it might be your system Python, since that is usually when a Python installation gets replaced with a newer version. If that's the case, and you installed your Python packages through your system's package manager (I would avoid doing this in the future), then your distro's package repos should already contain the updated packages to go along with the new Python version. If you are instead using `pip`'s "user install" feature or a venv (created by `python -m venv somevenv`), then I'm afraid you'll have to use `pip` to reinstall the packages.

A quick and easy way to reinstall a list of specific packages and their versions is to use `pip freeze` to output a list of the installed packages and their versions:

```sh
pip freeze > /tmp/requirements.txt
```

And then use that file to install the same packages and the same versions of said packages:

```sh
pip install -r /tmp/requirements.txt
```

If you would like to avoid having your Python installation replaced/upgraded like this, you could always build one from source. Once built, it will never change. Personally, I keep multiple Python installations under `~/.pythons/`, but I keep every version isolated from each other (even micro/patch versions).

Going into detail about the different methods of maintaining a Python built from source (or multiple) is beyond the scope of this post, though, so that's where I'll leave this answer.