user2495207
user2495207

Reputation: 861

How switch tensorflow versions between 2.0 and 1.x?

Is there a way to switch versions of tensorflow?, when I installed tensorflow 2.0 using conda, it updated many things even python. On runing conda list it shows both versions;

tensorflow 2.0.0 mkl_py37h66b46cc_0
tensorflow 1.13.1 < pip>

In order to use the 1.x version it's recommended here to replace import tensorflow as tf for the following :

import tensorflow.compat.v1 as tf tf.disable_v2_behavior()

It is safe to use this method, just adding these lines?, in my case it shows a warning:

WARNING:tensorflow:From /home/common/anaconda3/lib/python3.7/site-packages/tensorflow_core/python/compat/v2_compat.py:65: disable_resource_variables (from tensorflow.python.ops.variable_scope) is deprecated and will be removed in a future version. Instructions for updating: non-resource variables are not supported in the long term

Upvotes: 2

Views: 12662

Answers (1)

Denver
Denver

Reputation: 639

I would personally use two different virtual environments here. This would make sure you don't have dependency issues when using 2.0 vs 1.x. Conda environments are very easy to use. For example:

create the environment

conda create --tensorflow1

activate the environment

conda activate tensorflow1

When you have the environment activated you can conda/pip install TensorFlow 1.x and all dependencies will be contained within the environment. You can do the same thing with TensorFlow 2.0.

I can't comment on the above solution you have posted, but these are the cases where virtual environments are extremely useful.

Full docs here:

https://docs.conda.io/projects/conda/en/latest/user-guide/tasks/manage-environments.html

Upvotes: 3

Related Questions