windows 10 64bit下安裝Tensorflow+Keras

趙安家發表於2017-07-03

windows 10 下 pip,conda 換國內源,安裝Tensorflow,Keras

修改pip源 參考 Python pip 國內映象大全及使用辦法

官方文件 Config file

windows 全部使用者需要在%APPDATA%\pip\pip.ini,當前使用者在%HOME%\pip\pip.ini

[global]
index-url=http://mirrors.aliyun.com/pypi/simple/
[install]
trusted-host=mirrors.aliyun.com複製程式碼

安裝Tensorflow

參考 Installing TensorFlow on Windows

# 切換到 python3.5 參考 詳見另外一篇博文 https://anjia.ml/2017/07/02/anaconda-install-and-configurating-jupyter/#切換python版本

#開啟Anaconda Prompt
(python35) C:\Users\xx> activate python35

#因為電腦無獨顯,所以安裝`CPU-only`版本
(python35) C:\Users\xx> pip install --ignore-installed --upgrade https://storage.googleapis.com/tensorflow/windows/cpu/tensorflow-1.2.1-cp35-cp35m-win_amd64.whl 

(python35) C:\Users\xx>python複製程式碼
>>> import tensorflow as tf
>>> hello = tf.constant('Hello, TensorFlow')
>>> sess = tf.Session()
2017-07-03 16:44:16.082952: W c:\tf_jenkins\home\workspace\release-win\m\windows\py\35\tensorflow\core\platform\cpu_feature_guard.cc:45] The TensorFlow library wasn't compiled to use SSE instructions, but these are available on your machine and could speed up CPU computations.
2017-07-03 16:44:16.085175: W c:\tf_jenkins\home\workspace\release-win\m\windows\py\35\tensorflow\core\platform\cpu_feature_guard.cc:45] The TensorFlow library wasn't compiled to use SSE2 instructions, but these are available on your machine and could speed up CPU computations.
2017-07-03 16:44:16.085590: W c:\tf_jenkins\home\workspace\release-win\m\windows\py\35\tensorflow\core\platform\cpu_feature_guard.cc:45] The TensorFlow library wasn't compiled to use SSE3 instructions, but these are available on your machine and could speed up CPU computations.
2017-07-03 16:44:16.085952: W c:\tf_jenkins\home\workspace\release-win\m\windows\py\35\tensorflow\core\platform\cpu_feature_guard.cc:45] The TensorFlow library wasn't compiled to use SSE4.1 instructions, but these are available on your machine and could speed up CPU computations.
2017-07-03 16:44:16.086312: W c:\tf_jenkins\home\workspace\release-win\m\windows\py\35\tensorflow\core\platform\cpu_feature_guard.cc:45] The TensorFlow library wasn't compiled to use SSE4.2 instructions, but these are available on your machine and could speed up CPU computations.
2017-07-03 16:44:16.086634: W c:\tf_jenkins\home\workspace\release-win\m\windows\py\35\tensorflow\core\platform\cpu_feature_guard.cc:45] The TensorFlow library wasn't compiled to use AVX instructions, but these are available on your machine and could speed up CPU computations.
2017-07-03 16:44:16.087014: W c:\tf_jenkins\home\workspace\release-win\m\windows\py\35\tensorflow\core\platform\cpu_feature_guard.cc:45] The TensorFlow library wasn't compiled to use AVX2 instructions, but these are available on your machine and could speed up CPU computations.
2017-07-03 16:44:16.087363: W c:\tf_jenkins\home\workspace\release-win\m\windows\py\35\tensorflow\core\platform\cpu_feature_guard.cc:45] The TensorFlow library wasn't compiled to use FMA instructions, but these are available on your machine and could speed up CPU computations.
>>> print(sess.run(hello))
b'Hello, TensorFlow'複製程式碼

如果要去掉4-12的警告資訊,需要自己編譯。詳見 "The TensorFlow library wasn't compiled to use SSE instructions, but these are available on your machine and could speed up CPU computations" in "Hello, TensorFlow!" program #7778

安裝Keras

參考 官方文件 Installation 中文文件 Keras安裝和配置指南(Windows)

(python35) C:\Users\xx>pip install keras -U --pre複製程式碼

但是我安裝一直報錯,

Running setup.py bdist_wheel for scipy ... error
  Complete output from command {Anaconda3_home}\envs\python35\python.exe -u -c "import setuptools, tokenize;__file__='{AppData}\\Local\\Temp\\pip-build-mgdjtt1d\\scipy\\setup.py';f=getattr(tokenize, 'open', open)(__file__);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, __file__, 'exec'))" bdist_wheel -d {AppData}\Local\Temp\tmpb_od_dlvpip-wheel- --python-tag cp35:
  lapack_opt_info:
  lapack_mkl_info:
    libraries mkl_rt not found in ['{Anaconda3_home}\\envs\\python35\\lib', 'C:\\', '{Anaconda3_home}\\envs\\python35\\libs']
    NOT AVAILABLE

## ...

Command "{Anaconda3_home}\envs\python35\python.exe -u -c "import setuptools, tokenize;__file__='{AppData}\\Local\\Temp\\pip-build-mgdjtt1d\\scipy\\setup.py';f=getattr(tokenize, 'open', open)(__file__);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, __file__, 'exec'))" install --record {AppData}\Local\Temp\pip-htcraop7-record\install-record.txt --single-version-externally-managed --compile" failed with error code 1 in {AppData}\Local\Temp\pip-build-mgdjtt1d\scipy\複製程式碼

網上有建議通過 pip install git+git://github.com/Theano/Theano.git 從github直接下最新程式碼安裝的,但是也是安裝失敗

我成功的方式

(python35) C:\Users\xx>conda install mingw libpython theano -y
(python35) C:\Users\xx>pip install keras複製程式碼

天朝網路不穩定,挺慢的,可以參考 另外一篇博文切換清華源 anjia.ml/2017/07/02/…

(python35) C:\Users\xx>python
Python 3.5.3 |Continuum Analytics, Inc.| (default, May 15 2017, 10:43:23) [MSC v.1900 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import keras
Using TensorFlow backend.複製程式碼

安裝成功,預設後端是TensorFlow

部落格 anjia.ml/2017/07/03/…
掘金 juejin.im/post/595a24…
簡書 www.jianshu.com/p/e0d9fa795…

相關文章