Ubuntu16.04 虛擬環(huán)境中安裝 TensorFlow 2.0(CPU)
第一步——TensorFlow 2.0 系統(tǒng)要求
第二步——設(shè)置虛擬環(huán)境
參考:https://blog.csdn.net/frozennet/article/details/105420207
第三步——安裝TensorFlow 2.0
新建工程文件夾
$ mkdir ~/tf-demo
進(jìn)入工程文件夾
$ cd ~/tf-demo
新建虛擬環(huán)境
$ python3 -m venv tensorflow-dev
啟動(dòng)虛擬環(huán)境
$ source tensorflow-dev/bin/activate
關(guān)閉虛擬環(huán)境
$ deactivate
安裝TensorFlow 2.0,非GPU版本
$ pip3 install tensorflow==2.0.0-alpha0
出現(xiàn)的錯(cuò)誤
錯(cuò)誤描述:
ERROR: markdown 3.1.1 has requirement setuptools>=36, but you’ll have setuptools 20.7.0 which is incompatible.
原因:
setuptools版本不匹配
解決方法:
(1)卸載原有的setuptools
sudo apt-get autoremove
(3)重新安裝其它版本setuptools
$ sudo pip install setuptools==39.0.0
參考:
關(guān)于cleaning up with apt-get:https://www.networkworld.com/article/3453032/cleaning-up-with-apt-get.html
關(guān)于解決錯(cuò)誤:https://blog.csdn.net/chengyq116/article/details/93654175
http://www.itdecent.cn/p/2bd9c42c4027
第四步——驗(yàn)證安裝
新建hello.py文件
$ vim hello.py
編寫(xiě)代碼
import tensorflow as tf
tf.compat.v1.disable_eager_execution()
hello=tf.constant("Hello TensorFlow")
sess=tf.compat.v1.Session()
print(sess.run(hello))
參考:http://www.tensorfly.cn/tfdoc/get_started/os_setup.html#virtualenv_install
https://www.cnblogs.com/123456www/p/12584427.html
運(yùn)行.py文件
$ python3 hello.py
過(guò)程輸出信息
過(guò)程描述:
執(zhí)行
python
導(dǎo)入tensorflow 模塊
import tensorflow as tf
輸出信息
FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated;
in a future version of numpy,
it will be understood as (type, (1,)) / '(1,)type'. _np_qint8 = np.dtype([("qint8", np.int8, 1)])
原因:安裝numpy的版本過(guò)高
解決方法:安裝低版本的numpy
pip install -U numpy==1.16.0
再次,導(dǎo)入tensorflow 模塊,未出現(xiàn)錯(cuò)誤信息
參考: https://blog.csdn.net/kobe_academy/article/details/99706595