ubuntu 在python3虛擬環(huán)境安裝tensorflow

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 remove python-setuptools (2)卸載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

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書(shū)系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

友情鏈接更多精彩內(nèi)容