Python使用pip安装TensorFlow模块 - jack_Meng

Python使用pip安装TensorFlow模块

1.首先确保已经安装python,然后用pip来安装matplotlib模块。

2.进入到cmd窗口下,建议执行python -m pip install -U pip setuptools进行升级。

3.如果之前已经安装了Numpy,则需要先卸载之前的安装,因为每个Tensorflow都有一个版本的numpy对应,故要卸载之前numpy

4.接着键入python -m pip install --upgrade tensorflow 进行自动的安装,系统会自动下载安装包。

命令提交以后,你唯一能做的就是等待了。你唯一能祈祷的,就是这该死的GFW不会坏了你好事。 还好这次运气不错,一次搞定。

验证安装

在桌面上创建a.py文件,写入以下代码

import tensorflow as tf
import os
os.environ[\'TF_CPP_MIN_LOG_LEVEL\']= \'2\'
hello = tf.constant(\'Hello, TensorFlow!\')
sess = tf.Session()
print(sess.run(hello))

a = tf.constant(10)
b = tf.constant(25)
print(sess.run(a + b))

参考:

win10安装TensorFlow填坑笔记:http://blog.csdn.net/chewinggum/article/details/70373098

【TensorFlow】Windows10 64 位下安装 TensorFlow - 官方原生支持:http://blog.csdn.net/u010099080/article/details/53418159

Windows下安装tensorflow步骤:http://blog.csdn.net/chongtong/article/details/53905625?locationNum=6&fps=1

TensorFlow 安装教程:http://blog.csdn.net/bitcarmanlee/article/details/52749488

学习:

知乎:https://www.zhihu.com/question/49909565

极客:http://wiki.jikexueyuan.com/project/tensorflow-zh/

异常处理:

下面是从网上找到的,别人在安装的过程中出现的错误或异常,以及解决方法:

后来直接pip install tensorflow,tensorflow装完,自动装numpy却报错了。因为我之前自己用了numpy,早就装了。而每个tensorflow都有一个版本的numpy对应,故要卸载之前numpy。解决方法如下

1.Exception:

Traceback (mostrecent call last):

……

PermissionError:[Errno 13]

Permission denied:\'D:\\software\\Anaconda\\Lib\\site-packages\\numpy\\core\\multiarray.cp36-win_amd64.pyd\'

解决办法:关闭所有正在运行的python程序

2. Installing collected packages:numpy, tensorflow-tensorboard, tensorflow

Found existing installation: numpy 1.11.3

Uninstalling numpy-1.11.3:

Exception……

无法卸载numpy

解决办法:pip install tensorflow –ignore-installed numpy

出处:https://blog.csdn.net/xuyunyunaixuexi/article/details/81036156

=============================================================

官方安装链接

tensorflow 0.12.0开始支持Windows下安装了

环境要求:

安装过程:

安装python3.5

python.exe -m pip install --upgrade pip

安装tensorflow

  • cpu版本
pip install --upgrade tensorflow
  • gpu版本
pip install --upgrade tensorflow-gpu

gpu版本tensorflow安装gpu支持包

安装cuda8.0

安装cudnn5.1

添加解压后的bin目录到PATH环境变量

测试tensorflow

$ python
...
>>> import tensorflow as tf
>>> hello = tf.constant(\'Hello, TensorFlow!\')
>>> sess = tf.Session()
>>> print(sess.run(hello))
b\'Hello, TensorFlow!\'
>>> a = tf.constant(10)
>>> b = tf.constant(32)
>>> print(sess.run(a + b))
42
>>>

如果import报错,需要下载安装Microsoft Visual C++ 2015 Redistributable

另外需确认CUDA CUDNN与TensorFlow版本是否匹配

  • gpu使用情况查看
nvidia-smi -l # 实时返回GPU使用情况

出处:https://blog.csdn.net/chongtong/article/details/53905625