一、创建虚拟环境
打开anaconda prompt,添加镜像源:
添加镜像源:conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/
添加镜像源:conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main/
设置搜索时显示通道地址:conda config --set show_channel_urls yes
显示镜像源设置情况:conda config --show channels
删除镜像源使用:
删除镜像源:conda config --remove channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main/
创建虚拟环境并安装tensorflow-gpu:
conda create -n tensorflow-gpu tensorflow-gpu
查看一下包的版本:
conda list
python是3.6.2版本的
在下面的网站中查找对应版本:
在 Windows 环境中从源代码构建 | TensorFlow (google.cn)
对应的最低tensorflow-gpu是1.2.0版本的
选择一个合适的2.0.0版本的
pip install tensorflow-gpu==2.1.0
但是报错,需要更高版本的python,于是需要在虚拟环境中升级python
报错信息:protobuf requires Python '>=3.7' but the running Python is 3.6.2
解决方法:更新pip后重新安装tensorflow。
更新命令:python -m pip install --upgrade pip
重新执行:
pip install tensorflow-gpu==2.1.0
报错:
Traceback (most recent call last):
File "C:\Users\30296\anaconda3\envs\tensorflow-gpu\lib\site-packages\tensorflow\python\platform\self_check.py", line 75, in preload_check
ctypes.WinDLL(build_info.cudart_dll_name)
File "C:\Users\30296\anaconda3\envs\tensorflow-gpu\lib\ctypes\__init__.py", line 348, in __init__
self._handle = _dlopen(self._name, mode)
OSError: [WinError 126] 找不到指定的模块。
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\Users\30296\anaconda3\envs\tensorflow-gpu\lib\site-packages\tensorflow\__init__.py", line 24, in <module>
from tensorflow.python import *
File "C:\Users\30296\anaconda3\envs\tensorflow-gpu\lib\site-packages\tensorflow\python\__init__.py", line 49, in <module>
from tensorflow.python import pywrap_tensorflow
File "C:\Users\30296\anaconda3\envs\tensorflow-gpu\lib\site-packages\tensorflow\python\pywrap_tensorflow.py", line 30, in <module>
self_check.preload_check()
File "C:\Users\30296\anaconda3\envs\tensorflow-gpu\lib\site-packages\tensorflow\python\platform\self_check.py", line 82, in preload_check
% (build_info.cudart_dll_name, build_info.cuda_version_number))
ImportError: Could not find 'cudart64_80.dll'. TensorFlow requires that this DLL be installed in a directory that is named in your %PATH% environment variable. Download and install CUDA 8.0 from this URL: https://developer.nvidia.com/cuda-toolkit
是没有安装cuda的原因,然后下载了2.1.0对应的10.1的cuda,管理员身份安装:
python常见错误:Cannot uninstall ‘six‘.
文章来源地址https://www.toymoban.com/news/detail-734375.html
Cannot uninstall 'six'. It is a distutils installed project and thus we cannot accurately determine which files belong to it which would lead to only a partial uninstall.
解决方式
直接忽略旧版本进行升级:
pip install six --upgrade --ignore-installed six
终于安装成功:
测试是否安装成功:
python
import tensorflow as tf
tf.__version__
得到输出:文章来源:https://www.toymoban.com/news/detail-734375.html
到了这里,关于安装tensorflow-gpu的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!