Python 使用与 Conda 环境不同的 Tensorflow 版本

Python using different Tensorflow version than Conda environment

我用pip安装了tensorflow。当我在 conda 环境中检查我的 tensorflow 版本时,它显示为我想要的 2.7.0。但是,当我在同一环境的 python 中检查它时,我得到 2.6.0。我怎样才能改变它,以便在这两种情况下我都得到 2.7.0?我已经尝试在环境中卸载并重新安装tensorflow并使用pip对其进行升级。

(dataset2vec) C:\Users\sozen>pip show tensorflow
Name: tensorflow
Version: 2.7.0
Summary: TensorFlow is an open source machine learning framework for everyone.
Home-page: https://www.tensorflow.org/
Author: Google Inc.
Author-email: packages@tensorflow.org
License: Apache 2.0
Location: c:\users\sozen\anaconda3\envs\dataset2vec\lib\site-packages
Requires: termcolor, numpy, grpcio, gast, protobuf, absl-py, h5py, typing-extensions, six, tensorflow-io-gcs-filesystem, google-pasta, flatbuffers, tensorboard, keras, wrapt, wheel, keras-preprocessing, libclang, tensorflow-estimator, opt-einsum, astunparse
Required-by: ismlldataset

(dataset2vec) C:\Users\sozen>pip install --upgrade tensorflow
Requirement already satisfied: tensorflow in c:\users\sozen\anaconda3\envs\dataset2vec\lib\site-packages (2.7.0)
Requirement already satisfied: gast<0.5.0,>=0.2.1 in c:\users\sozen\anaconda3\envs\dataset2vec\lib\site-packages (from tensorflow) (0.4.0)

(dataset2vec) C:\Users\sozen>python -c "import tensorflow as tf;print(tf.__version__)"
2.6.0

干杯

我不知道到底是什么问题,但我创建了一个新环境,在创建过程中直接安装了 tensorflow,在该环境中它仍然使用 2.6.0 和 python。然后我强制安装了 2.7.0,它神奇地工作了!

这是我使用的命令列表:

conda activate tensorTest
python --version
python -c "import tensorflow as tf;print(tf.__version__)"
pip install tensorflow
python -c "import tensorflow as tf;print(tf.__version__)"
>>Still showed 2.6.0
pip install tensorflow==2.7.0
python -c "import tensorflow as tf;print(tf.__version__)"
>>2.7.0!