虚拟环境安装tensorflow

文章讲述了在Python3.11环境中安装TensorFlow-GPU时遇到的警告和错误,涉及版本不匹配、f2py.exe问题,以及如何升级protobuf以解决TypeError。最后介绍了API接口更新导致的list_physical_devices方法的变化。
摘要由CSDN通过智能技术生成

Tensorflow与Python、CUDA、cuDNN的版本对应表_tensorflow版本对应python3.11-CSDN博客

pip install tensorflow-gpu==2.0.0 -i https://pypi.tuna.tsinghua.edu.cn/simple

安装成功,但出现警告WARNING: The script f2py.exe is installed in 'C:\Users\**\AppData\Roaming\Python\Python37\Scripts' which is not on PATH.

WARNING: The script f2py.exe is installed in ‘C:\Users\linji\AppData\Roaming\Python\Python36\Scripts_warning: the script f2py.exe is installed in 'c:\u-CSDN博客

进行以下测试

import tensorflow as tf
print(tf.__version__)
print(tf.config.list_physical_devices('GPU'))
print(tf.config.list_physical_devices('CPU'))

tf.test.is_gpu_available() #true (表示:优先使用GPU)

import tensorflow报错

WARNING: The script f2py.exe is installed in TypeError: Descriptors cannot not be created directly. If this call came from a _pb2.py file, your generated code is out of date and must be regenerated with protoc >= 3.19.0.TypeError: Descriptors cannot not be created directly. If this call came from a _pb2.py file, your generated code is out of date and must be regenerated with protoc >= 3.19.0.

解决:TypeError: Descriptors cannot not be created directly-CSDN博客

查阅protoc --version,目前版本libprotoc 3.20.3

安装3.19.0版本的protobuf

pip install protobuf==3.19.0

尝试后成功import

print(tf.config.list_physical_devices('GPU'))再次报错

>>> print(tf.config.list_physical_devices('GPU'))
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: module 'tensorflow_core._api.v2.config' has no attribute 'list_physical_devices'

AttributeError: module 'tensorflow_core._api.v2.config' has no attribute 'list_physical_devices'-CSDN博客

原因为接口更新,按博客内容更改为

>>> print(tf.config.experimental.list_physical_devices('GPU'))
2024-02-22 19:51:51.464718: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library nvcuda.dll
2024-02-22 19:51:52.723557: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1618] Found device 0 with properties:
name: GeForce GT 730M major: 3 minor: 5 memoryClockRate(GHz): 0.758
pciBusID: 0000:09:00.0
2024-02-22 19:51:52.736315: I tensorflow/stream_executor/platform/default/dlopen_checker_stub.cc:25] GPU libraries are statically linked, skip dlopen check.
2024-02-22 19:51:52.755116: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1746] Adding visible gpu devices: 0
[PhysicalDevice(name='/physical_device:GPU:0', device_type='GPU')]

  • 8
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值