
聽說谷歌的第二代機器學習的框架tensorflow開源了,我也心血來潮去探探大牛的產品.怎奈安裝就折騰了一天,現在整理出來備忘.
tensorflow官方網站給出的安裝步驟很簡單:
# Only CPU-version is available at the moment.$ pip install https://storage.googleapis.com/tensorflow/mac/tensorflow-0.5.0-py2-none-any.whl用到了一個pip的工具,查了一下pip類似RedHat里面的yum,安裝Python包非常方便.
好吧,那就裝一個pip.pip的安裝方法也很簡單,就是前提需要先安裝python.然后去下載pip的安裝包,pip安裝命令如下:
qyfmac$ tar zxvf pip-7.1.2.tar.gzqyfmac$ cd pip-7.1.2qyfmac$ python setup.py install安裝時報錯了:
qyfmac$ python setup.py installrunning installChecking .pth file support in /Library/Python/2.7/site-packages/error: can't create or remove files in install directoryThe following error occurred while trying to add or remove files in theinstallation directory: [Errno 13] Permission denied: '/Library/Python/2.7/site-packages/test-easy-install-38643.pth'The installation directory you specified (via --install-dir, --PRefix, orthe distutils default setting) was: /Library/Python/2.7/site-packages/Perhaps your account does not have write access to this directory? If theinstallation directory is a system-owned directory, you may need to sign inas the administrator or "root" account. If you do not have administrativeaccess to this machine, you may wish to choose a different installationdirectory, preferably one that is listed in your PYTHONPATH environmentvariable.For information on other options, you may wish to consult thedocumentation at: https://pythonhosted.org/setuptools/easy_install.htmlPlease make the appropriate changes for your system and try again.里面有個Permission denied意思是權限不足,我們加個sudo繼續執行.
qyfmac$ sudo python setup.py install安裝完后執行命令pip freeze列出安裝的packages驗證一下pip安裝好沒.
qyfmac$ pip freezealtgraph==0.10.2bdist-mpkg==0.5.0bonjour-py==0.3macholib==1.5.1matplotlib==1.3.1modulegraph==0.10.4numpy==1.10.1py2app==0.7.3...列出了好多包,我唯一沒搞懂的就是我什么時候裝了這么多包.
到了我們的主角出場了.執行安裝命令安裝tensorflow.
qyfmac$ pip install https://storage.googleapis.com/tensorflow/mac/tensorflow-0.5.0-py2-none-any.whl悲劇依舊發生了,googleapis.com這個鬼要弄把梯子才能訪問,下載各種超時.
黃天不負苦心人,有一有心人已經下好并上傳的了百度云 http://pan.baidu.com/s/1ntjaMnf 密碼:sznb.
下載下來安裝之.
qyfmac$ pip install --upgrade tensorflow-0.5.0-py2-none-any.whlvirtualenv是python的沙箱工具.我們畢竟是在自己機器上做實驗,為了不來回修改各種環境變量,我們一般還是弄個沙箱完比較好.測試完直接刪除就行,不用再去改各種配置文件.
用pip命令來安裝:
qyfmac$ sudo pip install --upgrade virtualenv安裝好后創建一個工作目錄,我直接在home里創建了個文件夾.
qyfmac$ virtualenv --system-site-packages ~/tensorflow然后進入目錄激活沙箱.
qyfmac$ cd ~/tensorflowqyfmac$ source bin/activate (tensorflow) qyfmac$ 把下載下來的tensorflow-0.5.0-py2-none-any.whl文件放到~/tensorflow目錄里.
進入沙箱后,執行命令來安裝tensorflow在沙箱中.
(tensorflow) qyfmac$ pip install --upgrade tensorflow-0.5.0-py2-none-any.whl我是在virtualenv里運行的.直接在系統里執行方式是一樣的.
照著官方文檔敲了個簡單例子.
(tensorflow) qyfmac$ pythonPython 2.7.10 (default, Aug 22 2015, 20:33:39)[GCC 4.2.1 Compatible Apple LLVM 7.0.0 (clang-700.0.59.1)] on darwinType "help", "copyright", "credits" or "license" for more information.>>> import tensorflow as tf>>> hello = tf.constant('Hello,TensorFlow!')>>> sess = tf.session()>>> print sess.run(hello)Hello, TensorFlow!>>> 在敲see = tf.Session()這行時會報一個錯
can't determine number of CPU cores: assuming 4 I tensorflow/core/common_runtime/local_device.cc:25] Local device intra op parallelism threads: 4can't determine number of CPU cores: assuming 4I tensorflow/core/common_runtime/local_session.cc:45] Local session inter op parallelism threads: 4可以先不用理會,不影響最終執行結果.
新聞熱點
疑難解答