Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Downgrade Python version in virtual environment

I am always getting the same error regarding TensorFlow: ModuleNotFoundError: No module named 'tensorflow.contrib'.

I am actually using Python version 3.9 but, reading online, it seems that version 3.7 is the last stable one that can work with TensorFlow version >2.0.

Unfortunately I have started my project in a venv with the wrong version of Python and I would like to downgrade it, how can I do that?

like image 910
Stefø Avatar asked Jan 18 '26 16:01

Stefø


1 Answers

Building on @chepner's comment above, since venvs are just directories, you can save your current state and start a fresh virtual environment instead.

# Save current installs
(venv) -> pip freeze -r > requirements.txt

# Shutdown current env
(venv) -> deactivate

# Copy it to keep a backup
-> mv venv venv-3.9

# Ensure you have python3.7
-> python3.7 -V

# Create and activate a 3.7 venv
-> python3.7 -m venv venv-3.7
-> source venv-3.7/bin/activate

# Reinstall previous requirements
(venv-3.7) -> pip install -r requirements.txt

# Install new requirements

Hope that helps!

like image 165
radoshi Avatar answered Jan 20 '26 05:01

radoshi



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!