win10使用conda安装TensorFlow等组件问题总结

本文通过四部分,对使用TensorFlow相关的问题进行总结,便于后面方便查询,其中

  • 第一部分:尝试一些操作没成功的方法
    第二部分:TensorFlow安装详细步骤
    第三部分:使用TensorFlow中,出现的错误及解决方案
    第四部分:运行TensorFlow相关程序时,其它组件安装及相关命令脚本总结

我的开发环境为:Win10 + IDEA(Pycharm) + Python3.6 + TensorFlow1.5.x + Anaconda2.X

第一部分:尝试一些操作没成功的方法

直接使用pip安装TensorFlow会出现各种错误,相关的错误信息如下所示:

尝试方法一

C:\Users\Administrator>pip install --upgrade https://storage.googleapis.com/tensorflow/linux/cpu/tensorflow-1.1.0-cp27-none-linux_x86_64.whl

tensorflow-1.1.0-cp27-none-linux_x86_64.whl is not a supported wheel on this platform.

尝试方法二

C:\Users\Administrator>pip install tensorflow

Collecting tensorflow

Could not find a version that satisfies the requirement tensorflow (from versions: )

No matching distribution found for tensorflow

第二部分:TensorFlow安装详细步骤

本文重点介绍基于Anaconda安装TensorFlow,详细的步骤如下所示:

步骤一:Anaconda安装

本文略,详情请参考https://www.sharebook.site/articles/tensorflow-install-and-using/

步骤二:检查Anaconda相关的信息

1、查询安装信息

C:\Users\Administrator>conda info

Using Anaconda Cloud api site https://api.anaconda.org

Current conda install:

platform : win-64

conda version : 4.0.5

conda-build version : 1.20.0

python version : 2.7.11.final.0

requests version : 2.9.1

root environment : D:\Anaconda2  (writable)

default environment : D:\Anaconda2

envs directories : D:\Anaconda2\envs

package cache : D:\Anaconda2\pkgs

channel URLs : https://repo.continuum.io/pkgs/free/win-64/

https://repo.continuum.io/pkgs/free/noarch/

https://repo.continuum.io/pkgs/pro/win-64/

https://repo.continuum.io/pkgs/pro/noarch/

config file : None

is foreign system : False

 

2、查询当前已经安装的库

C:\Users\Administrator>conda list

# packages in environment at D:\Anaconda2:

[31mDEPRECATION: The default format will switch to columns in the future. You can use --format=(legacy|columns) (or define a format=(legacy|columns) in your pip.conf under the [list] section) to disable this warning.[0m

alabaster                 0.7.7                    py27_0    defaults

anaconda                  4.0.0               np110py27_0    defaults

3、安装库(*代表库名称)

conda install *

4、更新库(*代表库名称)

conda update *

步骤三:TensorFlow的安装(Python3.X的环境准备)

以前使用的是TensorFlow1.2.X的版本,现在尝试使用TensorFlow1.5.X的版本,TensorFlow1.X的版本使用Python3.X的版本与之对应。由于我win10安装的Anaconda是2.X的版本,这个对应的Python是2.X的版本,因此,我将用conda创建一个3.X的环境。

参考命令如下:

C:\Users\Administrator>conda create -n tensorflow_study python=3.6

Fetching package metadata .............

Solving package specifications: .

Package plan for installation in environment D:\Anaconda2\envs\tensorflow_study:

The following NEW packages will be INSTALLED:

certifi:        2018.1.18-py36_0

pip:            9.0.1-py36h226ae91_4

python:         3.6.4-h6538335_1

setuptools:     38.4.0-py36_0

vc:             14-h0510ff6_3

vs2015_runtime: 14.0.25123-3

wheel:          0.30.0-py36h6c3ec14_1

wincertstore:   0.2-py36h7fe50ca_0

Proceed ([y]/n)? y

vs2015_runtime 100% |###############################| Time: 0:00:19 110.72 kB/s

vc-14-h0510ff6 100% |###############################| Time: 0:00:00   3.28 MB/s

python-3.6.4-h 100% |###############################| Time: 0:04:26  84.12 kB/s

certifi-2018.1 100% |###############################| Time: 0:00:02  66.88 kB/s

setuptools-38. 100% |###############################| Time: 0:00:05 101.83 kB/s

wheel-0.30.0-p 100% |###############################| Time: 0:00:00 147.61 kB/s

pip-9.0.1-py36 100% |###############################| Time: 0:00:30  85.33 kB/s

#

# To activate this environment, use:

# > activate tensorflow_study

#

# To deactivate an active environment, use:

# > deactivate

#

# * for power-users using bash, you must source

#

步骤四:TensorFlow的安装(使用conda安装组件)

通过上面的命令:activate tensorflow_study

    进入Python3.x的环境,之后安装TensorFlow即可。

在终端或cmd中输入以下命令搜索当前可用的tensorflow版本

(tensorflow_study)C:\Users\Administrator>anaconda search -t conda tensorflow

Using Anaconda Cloud api site https://api.anaconda.org

Run 'anaconda show <USER/PACKAGE>' to get more details:

…….

aaronzs/tensorflow        |    1.5.0 | conda           | linux-64, win-64, osx-64

: TensorFlow helps the tensors flow

aaronzs/tensorflow-gpu    |    1.5.0 | conda           | linux-64, win-64

: TensorFlow helps the tensors flow

………

步骤五:选择较新的CPU版本进行安装

这里选的版本为,如aaronzs/tensorflow的1.5.0版本,及aaronzs/tensorflow-gpu的1.5.0版本,输入如下命令查询安装命令

(tensorflow_study)C:\Users\Administrator>anaconda show aaronzs/tensorflow

Using Anaconda Cloud api site https://api.anaconda.org

Name:    tensorflow

Summary: TensorFlow helps the tensors flow

Access:  public

Package Types:  conda

Versions:

+ 1.3.0

+ 1.4.0rc0

+ 1.4.0rc1

+ 1.4.0

+ 1.5.0

To install this package with conda run:

conda install --channel https://conda.anaconda.org/aaronzs tensorflow

步骤六:使用最后一行的提示命令进行安装,相关的命令如下:

(tensorflow_study)C:\Users\Administrator>conda install --channel https://conda.anaconda.org/aaronzs tensorflow

Using Anaconda Cloud api site https://api.anaconda.org

Fetching package metadata: ......

Solving package specifications: ....

…….

步骤七:GPU版本进行安装

(tensorflow_study)C:\Users\Administrator>anaconda show aaronzs/tensorflow-gpu

Using Anaconda Cloud api site https://api.anaconda.org

Name:    tensorflow-gpu

Summary: TensorFlow helps the tensors flow

Access:  public

Package Types:  conda

Versions:

+ 1.3.0

+ 1.4.0rc1

+ 1.4.0

+ 1.5.0

To install this package with conda run:

conda install --channel https://conda.anaconda.org/aaronzs tensorflow-gpu

步骤八:使用最后一行的提示命令进行安装,相关的命令如下:

第三部分:使用TensorFlow中,出现的错误及解决方案

AError:  Dependencies missing in current win-64 channels:

(tensorflow_study)C:\Users\Administrator>conda install --channel https://conda.anaconda.org/aaronzs tensorflow-gpu

Using Anaconda Cloud api site https://api.anaconda.org

Fetching package metadata: ......

Solving package specifications: .

Error:  Dependencies missing in current win-64 channels:

- tensorflow-gpu -> tensorflow-tensorboard <1.6.0,>=1.5.0 -> protobuf >=3.4.0

- tensorflow-gpu -> tensorflow-tensorboard <0.5.0,>=0.4.0rc1 -> protobuf >=3.3.0

- tensorflow-gpu -> protobuf >=3.4.0

- tensorflow-gpu -> protobuf >=3.3.0

- tensorflow-gpu -> cudnn 6.0.*

You can search for this package on anaconda.org with

anaconda search -t conda protobuf >=3.4.0

(and similarly for the other packages)

解决方案

1、安装protobuf大于4.0的版本

(tensorflow_study)C:\Users\Administrator>anaconda search -t conda protobuf

Using Anaconda Cloud api site https://api.anaconda.org

Run 'anaconda show <USER/PACKAGE>' to get more details:

Packages:

Name                      |  Version | Package Types   | Platforms

…….

conda-forge/protobuf      |    3.5.1 | conda           | linux-64, win-32, osx-64, win-64

…….

*********************

(tensorflow_study)C:\Users\Administrator>anaconda show conda-forge/protobuf

Using Anaconda Cloud api site https://api.anaconda.org

Name:    protobuf

Summary: Protocol Buffers - Google's data interchange format.

Access:  public

Package Types:  conda

Versions:

+ 3.0.0b2

+ 3.0.0b2.post2

+ 3.0.0b3

+ 3.0.0

+ 3.1.0

+ 3.2.0

+ 3.3.0

+ 3.3.2

+ 3.4.0

+ 3.4.1

+ 3.5.0

+ 3.5.1

To install this package with conda run:

conda install --channel https://conda.anaconda.org/conda-forge protobuf

使用使用上面的方法进行安装即可。

 

2、安装cudnn大于6.0的版本

(tensorflow_study)C:\Users\Administrator>anaconda search -t conda cudnn

Using Anaconda Cloud api site https://api.anaconda.org

Run 'anaconda show <USER/PACKAGE>' to get more details:

Packages:

Name                      |  Version | Package Types   | Platforms

------------------------- |   ------ | --------------- | ---------------

alexbw/lua-cudnn          |    0.1.1 | conda           | linux-64

anaconda/cudnn            |    7.0.5 | conda           | linux-ppc64le, linux-64, win-64, osx-64

: NVIDIA's cuDNN deep neural network acceleration library

…..

Found 18 packages

 

(tensorflow_study)C:\Users\Administrator>anaconda show anaconda/cudnn

Using Anaconda Cloud api site https://api.anaconda.org

Name:    cudnn

Summary: NVIDIA's cuDNN deep neural network acceleration library

Access:  public

Package Types:  conda

Versions:

+ 5.1

+ 6.0.21

+ 6.0

+ 5.1.10

+ 7.0.5

To install this package with conda run:

conda install --channel https://conda.anaconda.org/anaconda cudnn

运行这个脚本继续安装CUDNN即可。

问题三:LOCKERROR: It looks like conda is already doing something.

Fetching packages ...

LOCKERROR: It looks like conda is already doing something.

The lock [u'D:\\Anaconda2\\pkgs\\.conda_lock-12180'] was found. Wait for it to finish before continuing.

If you are sure that conda is not running, remove it and try again.

You can also use: $ conda clean --lock

解决方案:

C:\Users\Administrator>conda clean --lock

removing: D:\Anaconda2\pkgs\.conda_lock-12180

问题四:NameError: name 'xrange' is not defined

for step in xrange(201):

NameError: name 'xrange' is not defined

解决方案:原因分析,由于python版本为python 3.5,而xrange( )函数时在python 2.x中的一个函数,在Python3中,range()的实现方式与xrange()函数相同,所以就不存在专用的xrange( ),因此,当遇到这种问题时,有两种方法可以解决这个问题。

第一种:若你想在python 3中运行程序,将xrange( )函数全部换为range( )即可

第二种:将出现此问题的程序放在python 2.x版本的环境中运行即可

参考网址:http://blog.csdn.net/u010412719/article/details/47088095

问题五:AttributeError: 'module' object has no attribute 'Variable'

b = tf.Variable(tf.zeros([1]))

AttributeError: 'module' object has no attribute 'Variable'

解决方案:原因是包路径中包含tensorflow,解决方法,包路径中不能包含tensorflow,修改路径进行解决。

问题六:ImportError: Could not find 'cudnn64_7.dll'.

ImportError: Could not find 'cudnn64_7.dll'. TensorFlow requires that this DLL be installed in a directory that is named in your %PATH% environment variable. Note that installing cuDNN is a separate step from installing CUDA, and this DLL is often found in a different directory from the CUDA DLLs. You may install the necessary DLL by downloading cuDNN 7 from this URL: https://developer.nvidia.com/cudnn

 

解决方案:出现上面的情况,即使吧CuDnn的bin路径配置到环境变量中,也不生效。需要接将CuDNN中的文件夹bin/include/lib中的文件拷贝到对应Cuda的bin/include/lib文件夹中进行解决。

CuDNN7的安装位置:E:\开发工具备份\CUDA_Toolkit_20171201\cudnn-9.0-windows10-x64-v7

Cuda的安装位置:C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v9.0\

问题7:ERROR conda.core.link:_execute(481): An error occurred while installing package 'anaconda::qt-5.6.2-vc14_6'.

ERROR conda.core.link:_execute(481): An error occurred while installing package 'anaconda::qt-5.6.2-vc14_6'.

UnicodeDecodeError('ascii', 'D:\\Anaconda2\\Library\\bin;D:\\Anaconda2\\envs\\tensorflow_study;D:\\Anaconda2\\envs\\tensorflow_study\\Library\\mingw-w64\\bin;D:\\Anaconda2\\envs\\tensorflow_study\\Library\\usr\\bin;D:\\Anaconda2\\envs\\tensorflow_study\\Library\\bin;D:\\Anaconda2\\envs\\tensorflow_study\\Scripts;D:\\Anaconda2\\envs\\tensorflow_study\\bin;C:\\Program Files\\NVIDIA GPU Computing Toolkit\\CUDA\\v9.0\\bin;C:\\Program Files\\NVIDIA GPU Computing Toolkit\\CUDA\\v9.0\\libnvvp;C:\\ProgramData\\Oracle\\Java\\javapath;C:\\Windows\\system32;C:\\Windows;C:\\Windows\\System32\\Wbem;C:\\Windows\\System32\\WindowsPowerShell\\v1.0\\;d:\\Program Files\\MiKTeX 2.9\\miktex\\bin\\x64\\;D:\\Anaconda2;D:\\Anaconda2\\Scripts;C:\\Program Files (x86)\\NVIDIA Corporation\\PhysX\\Common;C:\\Program Files\\MySQL\\MySQL Utilities 1.6\\;C:\\WINDOWS\\system32;C:\\WINDOWS;C:\\WINDOWS\\System32\\Wbem;C:\\WINDOWS\\System32\\WindowsPowerShell\\v1.0\\;E:\\\xe5\xbc\x80\xe5\x8f\x91\xe5\xb7\xa5\xe5\x85\xb7\xe5\xa4\x87\xe4\xbb\xbd\\CUDA_Toolkit_20171201\\cudnn-9.0-windows10-x64-v7\\cuda\\bin;C:\\Users\\Administrator\\AppData\\Local\\Microsoft\\WindowsApps;C:\\Program Files\\Bandizip\\;D:\\SSH_Secure_Shell;', 837, 838, 'ordinal not in range(128)')

问题原因及解决方案:这种情况可能是编码问题引起的,用户可以通过打开D:\Anaconda2\Lib\site-packages\conda\core\link.py,添加如下代码(放到文件的最后面):

import sys

default_encoding = 'utf-8'

if sys.getdefaultencoding() != default_encoding:

reload(sys)

sys.setdefaultencoding(default_encoding)

参考截图如下所示:

 

如果编码环境不一样可以试着用下面这两套脚本试试:

脚本一:

if sys.getdefaultencoding() != 'gbk':

reload(sys)

sys.setdefaultencoding('gbk')

 

脚本二:

if sys.getdefaultencoding() != 'gbk':

reload(sys)

sys.setdefaultencoding('gb18030')

参考网址:http://blog.csdn.net/u013863751/article/details/72330041

参考网址(conda安装qt时报错UnicodeDecodeError):http://blog.csdn.net/zahuopuboss/article/details/54928037

第四部分:运行TensorFlow相关程序时,其它组件安装及相关命令脚本总结

1、安装matplotlib

anaconda search -t conda matplotlib

anaconda show anaconda/matplotlib

conda install --channel https://conda.anaconda.org/anaconda matplotlib

2、安装ipython

anaconda search -t conda ipython

anaconda show conda-forge/ipython

conda install --channel https://conda.anaconda.org/conda-forge ipython

参考资料:http://ipython.org/install.html

3、安装jupyter

anaconda search -t conda jupyter

anaconda show conda-forge/jupyter_client

conda install --channel https://conda.anaconda.org/conda-forge jupyter_client

jupyer运行使用命令:

(tensorflow_study) C:\Users\Administrator>jupyter notebook

参考资料:https://jupyter.org/install

4、安装PIL(一个图像处理库)

#注解:该库只支持Python2.X的版本

anaconda search -t conda PIL

anaconda show anaconda/pil

conda install --channel https://conda.anaconda.org/anaconda pil

注解说明(深度扩展)PIL(Python Imaging Library),已经是Python平台事实上的图像处理标准库了。PIL功能非常强大,但API却非常简单易用。由于PIL仅支持到Python 2.7,加上年久失修,于是一群志愿者在PIL的基础上创建了兼容的版本,名字叫Pillow,支持最新Python 3.x,又加入了许多新特性,因此,我们可以直接安装使用Pillow。相关的命令如下所示:

anaconda search -t conda PIL

anaconda show conda-forge/pillow

conda install --channel https://conda.anaconda.org/conda-forge pillow

参考资料:

Python Imaging Library (PIL)

http://www.pythonware.com/products/pil/

5、安装opencv

# opencv3的安装

anaconda search -t conda opencv

anaconda show anaconda/opencv

conda install --channel https://conda.anaconda.org/anaconda opencv

# opencv2的安装

anaconda search -t conda opencv

anaconda show menpo/opencv

conda install --channel https://conda.anaconda.org/menpo opencv

# 注解:移除环境tensorflow_study中的opencv

conda remove -n tensorflow_study opencv

6、安装caffe

anaconda search -t conda caffe
anaconda show conda-forge/onnx-caffe2
conda install --channel https://conda.anaconda.org/conda-forge onnx-caffe2

 

附件:其它的相关参考资料:

Cuda开发工具:https://developer.nvidia.com/cuda-toolkit-70

Cudnn库:https://developer.nvidia.com/rdp/cudnn-archive

CS 20: Tensorflow for Deep Learning Research

https://web.stanford.edu/class/cs20si/

Classification datasets results

http://rodrigob.github.io/are_we_there_yet/build/classification_datasets_results.html

Improving the way neural networks learn

http://neuralnetworksanddeeplearning.com/chap3.html#softmax

发表评论

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen: