在anaconda环境下,安装tensorflow

在anaconda环境下,安装tensorflow
转载地址:https://www.cnblogs.com/tiansheng/p/7281290.html,http://wiki.jikexueyuan.com/project/tensorflow-zh/get_started/os_setup.html,

安装环境:Centos7,anaconda3,python3.6

方式一:

(1) 建立一个 conda 计算环境名字叫tensorflow:
conda create -n tensorflow python=3.6
一定要指定python版本,否则安装失败。

(2)激活tensorflow环境,然后使用其中的 pip 安装 TensorFlow。当使用easy_install使用–ignore-installed标记防止错误的产生。

$ source activate tensorflow
(tensorflow)$ # Your prompt should change
(3)安装tensorflow

(tensorflow)$ pip install tensorflow

(4)验证安装

$ (tensorflow)python
import tensorflow as tf
表示成功。

问题:重新启动centos7后,使用import tensorflow as tf 时,tensorflow模块是不存在的,因为在上面安装中存在激活tensorflow环境步骤,把tensorflow安装到anaconda3的环境envs下面了,没有安装到libs/python3.6/site-packages目录下,因此需要将envs下面的安装都复制到site-packages下面。

$ \cp -Rp /root/anaconda3/envs/tensorflow/lib/python3.6/site-packages/* /root/anaconda3/lib/python3.6/site-packages/
其中使用\cp命令(在cp前加一个‘\’)表示文件或者文件夹进行覆盖的时候,不用询问,直接覆盖即可。

再次验证:

$ (tensorflow)python
import tensorflow as tf
/root/anaconda3/lib/python3.6/site-packages/h5py/init.py:36: FutureWarning: Conversion of the second argument of issubdtype from float to np.floating is deprecated. In future, it will be treated as np.float64 == np.dtype(float).type.
from ._conv import register_converters as _register_converters
出现上面的警告,原因是numpy已安装的版本是1.14.2。

解决方法:

$ conda install numpy==1.13.0
这样就可以了。

备注:在安装新的第三包的时候,可以先进行conda和所有第三方的更新

更新conda

$ conda update -n base conda

更新已安装的第三方包

$ conda update --al

更新指定包,例如numpy

$ pip install numpy

其他链接:

1、https://blog.csdn.net/linking234/article/details/79336869

2、Centos6.5 安装基于Python3.6 的TensorFlow

  https://blog.csdn.net/guotch/article/details/72983856?utm_source=itdadao&utm_medium=referral

猜你喜欢

转载自blog.csdn.net/weixin_43668325/article/details/84954212