'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?



Solution 1:[1]

tf.contrib is deprecated from the latest version of TensorFlow 2.x and is replaced with TF Slim.

It is recommended to use the upgraded version of TensorFlow to have the benefit of the latest features and functionalities provided by TensorFlow.

However, To downgrade python

  1. You need to uninstall the existing python version and re-install the required python version and set up your environment.

  2. If you are using Anaconda IDE, then use the below command:

conda search python  #to check available python version
conda install python=<version>
    
conda create --name <env_name> python=<python_version> # Which also creates virtual environment
activate <env_name>

Please check this link for more details.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 TFer2