Tensorflow安装在conda环境中,但我无法访问其任何属性函数

3phpmpom  于 2023-03-30  发布在  其他
关注(0)|答案(1)|浏览(159)

我已经使用anaconda建立了一个虚拟环境,并且成功安装了相关的库来设置tensorflow。
我运行的命令是:

conda activate tf
conda install -c anaconda tensorflow

我尝试运行的代码是:

import tensorflow as tf
print("Hello, Tensorflow!")
print(tf.__version__)

我得到了以下错误:
你好,Tensorflow!Traceback(最近一次调用):文件“c:\Users\cocoh\OneDrive\Documents\Coding\MI\ForestCover\TensorflowTest.py”,第3行,打印(tf.版本)AttributeError:模块“tensorflow”没有属性“version
调用pip show tensorflow表明tensorflow实际上已安装在环境中:

Name: tensorflow
Version: 2.11.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\cocoh\anaconda3\envs\tf\lib\site-packages
Requires: tensorflow-intel
Required-by:

我不知道是什么问题,任何帮助都将不胜感激。

k10s72fa

k10s72fa1#

请重试以下代码以安装TensorFlow。同时确保您已安装正确的TensorFlow版本,该版本与您系统中已安装的python版本兼容。

conda install tensorflow #or

pip install tensorflow

请按照此链接中的分步说明了解有关tensorflow安装的更多详细信息。如果问题仍然存在,请告诉我们。

相关问题