47

I have tensorflow 1.2.1 installed, and I need to downgrade it to version 1.1 to run a specific tutorial. What is the safe way to do it? I am using windows 10, python 3.5. Tensorflow was installed with pip3, but "pip3 show tensorflow" returns blank.

Is it possible to have multiple version of tensorflow on the same OS?

Yee
  • 861
  • 1
  • 8
  • 13

9 Answers9

61

Pip allows to specify the version

pip install tensorflow==1.1

Jürg W. Spaak
  • 2,057
  • 1
  • 15
  • 34
  • 1
    Do I need to uninstall version 1.2 first? pip uninstall tensorflow doesn't work. – Yee Aug 18 '17 at 07:07
  • 4
    @Yee no, you don't have to first uninstall it, pip will do this directly. However right now I'm not able to reinstall tensorflow aswell, so not sure what the problem is... – Jürg W. Spaak Aug 18 '17 at 07:15
  • 4
    If you have tensorflow 2, then running this will remove tensorflow 2 and install a lower version. – mikey Dec 10 '19 at 19:37
  • 2
    This only works for the given set of versions. In my case (a good lot later), this is only `(from versions: 2.2.0rc1, 2.2.0rc2, 2.2.0rc3, 2.2.0rc4, 2.2.0, 2.3.0rc0, 2.3.0rc1)` – Cadoiz Jul 11 '20 at 15:36
13

I discovered the joy of anaconda: https://www.continuum.io/downloads. It allows multiple virtual environments to host different versions of phyton and tensorflow. For example the following creates a virtual environment with pyton3.5 and tensorflow1.1

C:> conda create -n tensorflow1.1 python=3.5
C:> activate tensorflow1.1
(tensorflow1.1) 
C:> pip install --ignore-installed --upgrade https://storage.googleapis.com/tensorflow/windows/gpu/tensorflow_gpu-1.1.0-cp35-cp35m-win_amd64.whl

voila, a virtual environment is created.

Yee
  • 861
  • 1
  • 8
  • 13
11

Is it possible to have multiple version of tensorflow on the same OS?

Yes, you can use python virtual environments for this. From the docs:

A Virtual Environment is a tool to keep the dependencies required by different projects in separate places, by creating virtual Python environments for them. It solves the “Project X depends on version 1.x but, Project Y needs 4.x” dilemma, and keeps your global site-packages directory clean and manageable.

After you have install virtualenv (see the docs), you can create a virtual environment for the tutorial and install the tensorflow version you need in it:

PATH_TO_PYTHON=/usr/bin/python3.5
virtualenv -p $PATH_TO_PYTHON my_tutorial_env 
source my_tutorial_env/bin/activate # this activates your new environment
pip install tensorflow==1.1

PATH_TO_PYTHON should point to where python is installed on your system. When you want to use the other version of tensorflow execute:

deactivate my_tutorial_env

Now you can work again with the tensorflow version that was already installed on your system.

GeertH
  • 1,738
  • 9
  • 18
6

If you are using python3 on windows then you might do this as well

pip3 install tensorflow==1.4

you may select any version from "(from versions: 1.2.0rc2, 1.2.0, 1.2.1, 1.3.0rc0, 1.3.0rc1, 1.3.0rc2, 1.3.0, 1.4.0rc0, 1.4.0rc1, 1.4.0, 1.5.0rc0, 1.5.0rc1, 1.5.0, 1.5.1, 1.6.0rc0, 1.6.0rc1, 1.6.0, 1.7.0rc0, 1.7.0rc1, 1.7.0)"

I did this when I wanted to downgrade from 1.7 to 1.4

Omkar
  • 119
  • 1
  • 4
  • 6
    I got this ERROR: Could not find a version that satisfies the requirement tensorflow==1.6.0rc1 (from versions: 1.13.0rc1, 1.13.0rc2, 1.13.1, 1.14.0rc0, 1.14.0rc1, 1.14.0, 2.0.0a0, 2.0.0b0, 2.0.0b1) ERROR: No matching distribution found for tensorflow==1.6.0rc1 – Mohammad Jun 21 '19 at 13:59
  • 1
    This only works for the given set of versions. In my case (a good lot later), this is only `(from versions: 2.2.0rc1, 2.2.0rc2, 2.2.0rc3, 2.2.0rc4, 2.2.0, 2.3.0rc0, 2.3.0rc1)` – Cadoiz Jul 11 '20 at 15:34
6

Pay attention: you cannot install arbitrary versions of tensorflow, they have to correspond to your python installation, which isn't conveyed by most of the answers here. This is also true for the current wheels like here (from this answer above). For this example, the cp35-cp35m found inside the url hints that it is for Python 3.5.x

A huge list of different wheels/compatibilities can be found here on github. By using this, you can downgrade to almost every availale version in combination with the respective for python. For example:

pip install tensorflow==2.0.0

(note that previous to installing Python 3.7.8 alongside version 3.8.3 in my case, you would get this:

ERROR: Could not find a version that satisfies the requirement tensorflow==2.0.0 (from versions: 2.2.0rc1, 2.2.0rc2, 2.2.0rc3, 2.2.0rc4, 2.2.0, 2.3.0rc0, 2.3.0rc1)
ERROR: No matching distribution found for tensorflow==2.0.0

this also holds true for other non-compatible combinations.)

This should also be useful for legacy CPU without AVX support or GPUs with a compute capability that's too low.


If you only need the most recent releases (which it doesn't sound like in your question) a list of urls for the current wheel packages is available on this tensorflow page. That's from this SO-answer.

Note: This link to a list of different versions didn't work for me.

Cadoiz
  • 1,446
  • 21
  • 31
  • More Information that could be useful can be found in this answer: https://stackoverflow.com/a/63102518/4575793 – Cadoiz Jul 26 '20 at 16:10
1

You can try to use the options of --no-cache-dir together with -I to overwrite the cache of the previous version and install the new version. For example:

pip3 install --no-cache-dir -I tensorflow==1.1

Then use the following command to check the version of tensorflow:

python3 -c ‘import tensorflow as tf; print(tf.__version__)’

It should show the right version got installed.

Jack Chan
  • 1,077
  • 1
  • 10
  • 15
  • For me, this did not work, but simply running `pip install tensorflow==[version]` did work to downgrade. – mheavers Apr 11 '19 at 15:50
  • What do you mean this did not work? --no-cache-dir -I option did not help to overwrite the cache of the previous version? Usually a simple pip install command with no options (as you and other solutions above mentioned) would work. But, just in some systems, as the cache of the previous session is there, it doesn't allow the older version to be installed. That's why I suggested use the above options to overwrite the cache. – Jack Chan May 11 '19 at 00:43
  • 1
    This only works for the given set of versions. In my case (a good lot later), this is only `(from versions: 2.2.0rc1, 2.2.0rc2, 2.2.0rc3, 2.2.0rc4, 2.2.0, 2.3.0rc0, 2.3.0rc1)` – Cadoiz Jul 11 '20 at 15:35
1

If you have anaconda, you can just install desired version and conda will automatically downgrade the current package for you.

For example:

conda install tensorflow=1.1
1

Click to green checkbox on installed tensorflow and choose needed versionscreenshot Anaconda navigator

redflasher
  • 677
  • 9
  • 17
0

You can downgrade TensorFlow version to a lower version by running:

1.Check the version of TensorFlow that currently installed by:

pip3 show tensorflow

2.Then, Downgrade TensorFlow to a lower version by running:

pip3 install --upgrade tensorflow==<version>

Set the version to a lower number than the currently installed release. When choosing, make sure the version is compatible with the Python release.

If you are using a Notebook environment, run the following command and restart the kernel when the installation completes:

!pip install --upgrade tensorflow==<version>

Although the best practice is to use the latest version of Python and TensorFlow since older versions have vulnerability issues. So be cautious when downgrading.