(1)Anaconda、TensorFlow安装

1. Anaconda安装

到官网找到并下载安装,安装好进行如下步骤:
(https://blog.csdn.net/gangeqian2/article/details/79358543)
1.检查Anaconda是否成功安装:conda --version
2.检测目前安装了哪些环境:conda info --envs
在这里插入图片描述
3.检查目前有哪些版本的python可以安装:conda search --full-name python
4.安装不同版本的python:
对于GPU版本:conda create --name tensorflow-gpu python=3.7
对于CPU版本:conda create --name tensorflow python=3.7
安装时候出现(y/n)?,选y
5.按照提示,激活之:activate tensorflow
在这里插入图片描述
6.确保名叫tensorflow的环境已经被成功添加:conda info --envs
在这里插入图片描述
7.安装 tensorflow

2.TensorFlow安装

TensorFlow分为CPU和GPU版本
安装CPU版本:

pip install tensorflow

安装GPU版本:

pip install tensorflow-gpu

2.1:下载太慢原因及解决办法

但是pip安装的默认下载路径是python官网,下载tensorflow时调用的是国外的安装包,非常慢!!!!,因此有以下三种解决办法
法一(使用豆瓣的tensorflow镜像包):

python -m pip install tensorflow -i https://pypi.douban.com/simple
python -m pip install tensorflow-gpu -i https://pypi.douban.com/simple

法二(采用清华的镜像库):

pip3 install -i https://pypi.tuna.tsinghua.edu.cn/simple --upgrade tensorflow-gpu==1.8

法三:
修改pip的下载源为国内的镜像库,常用的镜像库有阿里、豆瓣和清华等:
具体修改步骤为:
  找到你系统下的pip.conf 文件(若找不到,可以自己新建,我自己新建了一个,放在/root/.pip/下),并在其中添加如下内容:

[global]
index-url=http://pypi.douban.com/simple
extra-index-url=http://mirrors.aliyun.com/pypi/simple/

[install]
trusted-host=
    pypi.douban.com
    mirrors.aliyun.com

以上保存之后,则每次pip安装时都会先从index-url中查找,若没有则依次去其他extra-index-url中查找。
若不想修改配置文件,则可以手动在命令行中指明要使用的镜像库:

pip install tensorflow -i https://pypi.douban.com/simple

2.2 pip安装成功,引用报错

通过pip安装成功后,运行 import tensorflow报错如下:ImportError: DLL load failed: 找不到指定的模块。
原因:tensorflow版本过高,而机器cpu较低
解决:最后选用1.15.0的 tensorflow,代码如下:

pip uninstall tensorflow(卸载原来版本)
pip install tensorflow==1.15.0 -i http://mirrors.aliyun.com/pypi/simple --trusted-host mirrors.aliyun.com(下载新版本)
发布了63 篇原创文章 · 获赞 3 · 访问量 1691

猜你喜欢

转载自blog.csdn.net/qq_34405401/article/details/104312229