本文介绍我的整个安装过程,非教程,包含我在安装中遇到的一些问题以及我是如何解决的。
本文亮点为末尾在Anaconda中安装好TensorFlow以后如何在Pycharm中使用。
查看Python版本
改变anaconda源
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/
conda config --set show_channel_urls yes
查看路径
conda info
安装
conda create -n tensorflow python=3.7.6
可能问题1
网络波动
Collecting package metadata: failed
CondaHTTPError: HTTP 000 CONNECTION FAILED for url <https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/win-64/repodata.json>
Elapsed: -
An HTTP error occurred when trying to retrieve this URL.
HTTP errors are often intermittent, and a simple retry will get you on your way.
ConnectionError(MaxRetryError('HTTPSConnectionPool(host=\'mirrors.tuna.tsinghua.edu.cn\', port=443): Max retries exceeded with url: /anaconda/pkgs/free/win-64/repodata.json (Caused by ReadTimeoutError("HTTPSConnectionPool(host=\'mirrors.tuna.tsinghua.edu.cn\', port=443): Read timed out. (read timeout=9.15)"))'))
解决办法
相同指令多输入几次
可能问题2
权限问题
在输入y确认后出现权限问题
[Errno 13] Permission denied: 'D:\\Anaconda3\\pkgs\\vs2015_runtime-14.16.27012-hf0eaf9b_1\\Library\\bin\\ucrtbase.dll'
解决办法
安装TensorFlow要修改dll文件
①把正在占用Python的程序关了
②360自动拦截了,把360或其他安全软件关了
剩余步骤
conda activate tensorflow
pip install -i https://mirrors.tuna.tsinghua.edu.cn/pypi/web/simple/tensorflow/ tensorflow-2.1.0rc2-cp37-cp37m-win_amd64.whl
算了,我还是下载下来安装吧
WARNING: Url 'C:\Users\Administrator/astor/' is ignored. It is either a non-existing path or lacks a specific scheme.
ERROR: Could not find a version that satisfies the requirement astor>=0.6.0 (from tensorflow==2.1.0rc2) (from versions: none)
ERROR: No matching distribution found for astor>=0.6.0 (from tensorflow==2.1.0rc2)
WARNING: Url 'C:\Users\Administrator/pip/' is ignored. It is either a non-existing path or lacks a specific scheme.
说我Python版本过高
(修改:其实并不是版本问题,只是这个astor库下载失败,后面又出现了几次这样的情况,我都手动下载了)
降Python至3.5.3,还是不行,其实是网络连接问题,在安装过程中许多包下载不了,我就在清华源下载了TensorFlow安装
网址
https://mirrors.tuna.tsinghua.edu.cn/pypi/web/simple/tensorflow/
安装过程中会出现错误
ERROR: Exception: Traceback (most recent call last)
又是所需包无法下载问题,我决定手动下载试一下
pip install six
可以成功
然后遇到无法下载的包就手动安装,最后终于成功安装了
检测安装成果
>>>python
>>>import tensorflow as tf
没有报错,关于这两行提示
Could not load dynamic library 'cudart64_101.dll'; dlerror: cudart64_101.dll not found
Ignore above cudart dlerror if you do not have a GPU set up on your machine.
因为我没有GPU,所以自动退回CPU
在Pycharm中调用
新建工程
在弹出窗口中如下选择
电击右侧“…”,弹出窗口,选择“Conda environment”,此时未检测到interpreter
电击右侧“…”,弹出窗口,你需要手动输入路径,因为路径是隐藏的,你要输入你anaconda中Python的路径
此时我们可以Ctrl+R,输入cmd
在窗口中输入“where python”,会显示所有Python路径,复制你所安装TensorFlow的路径
粘贴到刚才的窗口中,会自动锁定,点OK
返回之前界面,在下拉菜单中出现TensorFlow,选择就可以用啦