如何在2.0和1.x之间切换tensorflow版本?

时间:2020-01-03 18:07:27

标签: python tensorflow anaconda

有没有一种方法可以切换tensorflow的版本?当我使用conda安装tensorflow 2.0时,它甚至更新了很多东西,甚至是python。运行conda list时会显示两个版本;

tensorflow 2.0.0 mkl_py37h66b46cc_0
tensorflow 1.13.1

为了使用1.x版本,建议使用here替换以下内容的import tensorflow as tf

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

使用此方法安全吗,只需添加以下几行?,在我的情况下,它会显示警告:

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

1 个答案:

答案 0 :(得分:2)

我个人将在这里使用两个不同的虚拟环境。这样可以确保您在使用2.0和1.x时没有依赖性问题。 Conda环境非常易于使用。例如:

创建环境

conda create --tensorflow1

激活环境

conda activate tensorflow1

激活环境后,您可以conda / pip安装TensorFlow 1.x,所有依赖项都将包含在环境中。您可以使用TensorFlow 2.0做同样的事情。

我无法评论您发布的上述解决方案,但是在这些情况下,虚拟环境非常有用。

此处提供完整文档:

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