问题描述
在安装服务器上安装TensorFlow经常出现网络原因的报错,导致下载失败,但是服务器科学上网又是比较麻烦,所以通过使用国内镜像源来解决。
报错
WARNING: Retrying (Retry(total=4, connect=None, read=None, redirect=None, status=None))
after connection broken by 'ReadTimeoutError("HTTPSConnectionPool(host='pypi.org', port=443): Read timed out. (read timeout=15)")':
/simple/tensorflow/
环境
服务器环境
- 服务器环境:ubuntu 22.04
- python版本:python 3.10.0
- pip版本:pip 23.3.1
TensorFlow版本
- tensorflow_gpu-2.10.0
关于TensorFlow版本说明
以下是官网截取图片,详细可见:TensorFlow官网
解决方法
利用国内镜像源进行替代
镜像源选择
- 清华:https://pypi.tuna.tsinghua.edu.cn/simple
- 阿里云:http://mirrors.aliyun.com/pypi/simple/
- 中国科技大学: https://pypi.mirrors.ustc.edu.cn/simple/
- 豆瓣:http://pypi.douban.com/simple/
使用方法
#安装命令:
> pip install tensorflow-gpu==2.10.0 -i https://pypi.tuna.tsinghua.edu.cn/simple
下载结束后,测试是否成功:
> python
进入python后:
> import tensorflow as tf
> print(tf.__version__)
> print(tf.test.is_gpu_available())
output:
检验 CUDA 加速是否可用:
python -c "import tensorflow as tf;print(tf.config.list_physical_devices('GPU'))"
能正确输出各显卡的索引就表示安装成功了
[PhysicalDevice(name='/physical_device:GPU:0', device_type='GPU'), PhysicalDevice(name='/physical_device:GPU:1', device_type='GPU'), PhysicalDevice(name='/physical_device:GPU:2', device_type='GPU'), PhysicalDevice(name='/physical_device:GPU:3', device_type='GPU'), PhysicalDevice(name='/physical_device:GPU:4', device_type='GPU'), PhysicalDevice(name='/physical_device:GPU:5', device_type='GPU'), PhysicalDevice(name='/physical_device:GPU:6', device_type='GPU'), PhysicalDevice(name='/physical_device:GPU:7', device_type='GPU')]