Ubuntu16.04 虚拟环境中安装 TensorFlow 2.0(CPU)
第一步——TensorFlow 2.0 系统要求
第二步——设置虚拟环境
参考:https://blog.csdn.net/frozennet/article/details/105420207
第三步——安装TensorFlow 2.0
新建工程文件夹
$ mkdir ~/tf-demo
进入工程文件夹
$ cd ~/tf-demo
新建虚拟环境
$ python3 -m venv tensorflow-dev
启动虚拟环境
$ source tensorflow-dev/bin/activate
关闭虚拟环境
$ deactivate
安装TensorFlow 2.0,非GPU版本
$ pip3 install tensorflow==2.0.0-alpha0
出现的错误
错误描述:
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
参考:
关于cleaning up with apt-get:https://www.networkworld.com/article/3453032/cleaning-up-with-apt-get.html
关于解决错误:https://blog.csdn.net/chengyq116/article/details/93654175
https://www.jianshu.com/p/2bd9c42c4027
第四步——验证安装
新建hello.py文件
$ vim hello.py
编写代码
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
运行.py文件
$ python3 hello.py
过程输出信息
过程描述:
执行
python
导入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的版本过高
解决方法:安装低版本的numpy
pip install -U numpy==1.16.0
再次,导入tensorflow 模块,未出现错误信息
参考: https://blog.csdn.net/kobe_academy/article/details/99706595