MacOS 安裝 TensorFlow2.1.0


環境:

Mac  10.15.3 (19D76)

Python 3.6.8:https://www.python.org/ftp/python/3.6.8/python-3.6.8-macosx10.9.pkg

TensorFlow: 2.1.0

 

1.下載安裝Python安裝包,打開pkg並安裝。

wget -i -c https://www.python.org/ftp/python/3.6.8/python-3.6.8-macosx10.9.pkg

 

2.進入安裝目錄。設置軟件源、升級pip

cd /Library/Frameworks/Python.framework/Versions/3.6/bin
./pip3 config set global.index-url https://pypi.tuna.tsinghua.edu.cn/simple
./pip3 install pip -U

 

3.升級setuptools工具,因為安裝tensorflow一些包需要最新版本

./pip3 install --upgrade setuptools

 

4. 查詢可以安裝的TensorFlow版本

cd /Library/Frameworks/Python.framework/Versions/3.6/bin
./pip3 search tensorflow
➜  / pip3 search tensorflow
tensorflow (2.1.0)                                - TensorFlow is an open source machine learning framework for everyone.
tensorflow-qndex (0.0.22)                         - tensorflow-qnd x tensorflow-extenteten
tensorflow-plot (0.3.2)                           - TensorFlow Plot

 

5.指定安裝tensorflow2.1.0

./pip3 install tensorflow==2.1.0

期間可能會有版本依賴或版本太低,導致無法安裝,根據提示安裝依賴庫即可。如 ./pip3 install h5py 

 

6.驗證安裝是否成功

➜  bin ./python3
Python 3.6.8 (v3.6.8:3c6b436a57, Dec 24 2018, 02:04:31)
[GCC 4.2.1 Compatible Apple LLVM 6.0 (clang-600.0.57)] on darwin
Type "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!
>>> a = tf.constant(10)
>>> b = tf.constant(32)
>>> print sess.run(a+b)
42
>>>

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM