form1.cn
Make a little progress every day

ubuntu 16.04 64位 虚拟环境与本地安装tensorflow

15th of November 2019 Linux tensorflow 1448

一,虚拟环境安装tensorflow


1,更新源

apt-get update


2,安装python3或python2.7 和 pip dev 

python3安装:

sudo apt install python3
sudo apt install python3-pip
sudo  apt  install python3-dev
sudo apt install python3-tk # 图形化库


python2安装:

sudo apt install python
sudo apt install python-pip
sudo  apt  install python-dev
sudo  apt  install python-tk # 图形化库


卸载pip或pip3(如果需要的话)

python -m pip uninstall pip
sudo apt-get remove python-pip python-pip
sudo apt-get remove python3-pip python3-pip


3,安装虚拟环境

apt-get install python-virtualenv
virtualenv --version # 查看版本


4,创建虚拟环境 tensorflow

virtualenv --system-site-packages tensorflow


5,进入虚拟环境

source /home/zjwlgr/tensorflow/bin/activate


6,在虚拟环境中安装高版本的pip

easy_install -U pip


7,安装tensorflow

pip3 install  --upgrade tensorflow
pip install  --upgrade tensorflow
# or install gpu
pip3 install  --upgrade tensorflow-gpu
pip install  --upgrade tensorflow-gpu


8,查看安装后的虚拟环境占用空间大小

(tensorflow) root@machine:/home/zjwlgr/tensorflow# du -sh


9,进入python环境,测试安装

>>> import tensorflow
>>>


10,退出虚拟环境

deactivate


11,删除虚拟环境

rm -rf /home/zjwlgr/tensorflow


二,本地环境安装tensorflow


1,更新源

apt-get update


2,安装python3或python2.7 和 pip dev 

python3安装:

sudo apt install python3
sudo apt install python3-pip
apt-get install python3-dev


python2安装:

sudo apt install python
sudo apt install python-pip
apt-get install python-dev


3,安装tensorflow

pip3 install  --upgrade tensorflow
pip install  --upgrade tensorflow
# or install gpu
pip3 install  --upgrade tensorflow-gpu
pip install  --upgrade tensorflow-gpu


4,进入python环境,测试安装

>>> import tensorflow
>>>


5,卸载tensorflow

pip3 uninstall tensorflow
pip uninstall tensorflow


三,安装固定版本的tensorflow

pip install tensorflow==1.4.0


可能遇到的问题

问题1:import tensorflow 之后出现这些提示符
/usr/local/lib/python3.6/dist-packages/tensorflow/python/framework/dtypes.py:493: 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)])
/usr/local/lib/python3.6/dist-packages/tensorflow/python/framework/dtypes.py:494: 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_quint8 = np.dtype([(“quint8”, np.uint8, 1)])
/usr/local/lib/python3.6/dist-packages/tensorflow/python/framework/dtypes.py:495: 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_qint16 = np.dtype([(“qint16”, np.int16, 1)])
/usr/local/lib/python3.6/dist-packages/tensorflow/python/framework/dtypes.py:496: 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’.
等等;
原因是:numpy版本太高了(in a future version of numpy) 我的numpy是1.17.1,我把版本降低到1.15.0
解决办法: 先卸载numpy: sudo pip3 uninstall numpy
再安装比较低的版本: sudo python3 -m pip install -i https://pypi.tuna.tsinghua.edu.cn/simple numpy==1.15.0


问题2:python3.6无法正常使用tensorflow
/usr/lib/python3.6/importlib/_bootstrap.py:219: RuntimeWarning: compiletime version 3.5 of module 'tensorflow.python.framework.fast_tensor_util' does not match runtime version 3.6
  return f(*args, *kwds)
解决方案:
python3.6 -m pip install --upgrade --user tensorflow