Windows7安装TensorFlow步骤

TensorFlow在Windows7和Mac中的安装步骤

一,Windows7安装TensorFlow步骤:

1,按照官网安装步骤使用原生pip进行安装,要是网速慢可以按照廖雪峰网站给出的镜像安装Python,注意要安装64位且是Python 3.5.x 和 3.6.x。

镜像网址:https://pan.baidu.com/s/1kU5OCOB#list/path=%2Fpub%2Fpython

2,安装TensorFlow:pip3 install –upgrade tensorflow

3,验证TensorFlow安装是否成功:

$python

import tensorflow as tf

报错如下:

3.1,Failed to load the native TensorFlow runtime

 原因:用命令pip3 install --upgrade tensorflow 安装的tensorflow版本过高

 解决办法:手动安装1.5版本:pip3 install tensorflow==1.5

3.2,ImportError:DLL load failed: 找不到指定的程序

 原因:自动安装tensorflow时, protobuf安装的是最新版本3.6.1, 出现了不兼容的问题

 解决办法:手动安装protobuf 3.6.0版本:pip3 install protobuf==3.6.0

继续输入

hello = tf.constant(‘Hello, TensorFlow!’)

sess = tf.Session()

print(sess.run(hello))

打印输出

b’Hello, TensorFlow!’

表明TensorFlow安装成功!

4,去官网下载PyCharm编辑器,会自带一个python解释器,通过 File —-> Settings —-> Project:PyCharm —-> Project Interpreter

手动将python解释器更改为已经安装的python.exe路径。

二,Mac电脑安装TensorFlow步骤:

1,按照官网使用原生pip进行安装,可以使用以下两种方式安装Python:

方式一:如果安装了Homebrew,直接通过命令brew install python3安装即可。但是安装的Python版本是最新的3.7.0,没有对应的TensorFlow版本。

网上有教程可以用brew安装指定版本的python:

cd /usr/local/Homebrew/Library/Taps/homebrew/homebrew-core/Formula

git log python.rb

然后会显示python 3.6版本:

commit f2a764ef944b1080be64bd88dca9a1d80130c558

Author: BrewTestBot <[email protected]>

Date:   Sun Jun 17 13:24:46 2018 +0000

python: update 3.6.5_1 bottle.

但是我这边实际情况显示的是

commit 01e1aa80a6e7af4ad839d66d91f7538753ac69b1 (grafted, HEAD -> master, origin/master, origin/HEAD)

Author: BrewTestBot <[email protected]>

Date:   Tue Sep 11 11:00:47 2018 +0000

    pulumi: update 0.15.1 bottle.

没有出现预期的3.6版本,所以只能按照方式二进行安装了。

方式二:在上述镜像网址下载对应于Mac电脑的Python3.6.0版本,然后手动进行安装。安装完成后会覆盖3.7.0版本。

2, 安装TensorFlow: pip3 install tensorflow

安装过程可能会有些错误,多来几次就可以了。

3,验证TensorFlow安装是否成功:

$python3

import tensorflow as tf

报错:/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/importlib/_bootstrap.py:205: RuntimeWarning: compiletime version 3.5 of module ‘tensorflow.python.framework.fast_tensor_util’ does not match runtime version 3.6

return f(*args, **kwds)

原因:Python3.6与tensorflow不匹配,大意就是你安装的tensorflow是Python3.5编译的,而你用的Python版本是3.6。

解决办法:仿照 Windows7安装方法手动安装1.5版本:pip3 install tensorflow==1.5

接着再仿照Windows7执行验证指令,输出b’Hello, TensorFlow!’表明TensorFlow安装成功!

4,去官网下载PyCharm编辑器,通过 File —-> Preferences for New Projects —-> Project Interpreter

手动将python解释器更改为已经安装的python路径。

可以在终端中通过命令查询路径信息:

$which python3

/Library/Frameworks/Python.framework/Versions/3.6/bin/python3

至此tensorflow在Windows和Mac中的安装环境都搭建好啦,尽情开始你的开发之旅吧!

猜你喜欢

转载自blog.csdn.net/weixin_41480546/article/details/82590386