转载地址:https://www.cnblogs.com/tiansheng/p/7281290.html,
<https://www.cnblogs.com/tiansheng/p/7281290.html>
http://wiki.jikexueyuan.com/project/tensorflow-zh/get_started/os_setup.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.首先,直接输入conda install tensorflow
出现错误(不知为何)。
2.然后根据提示输入:anaconda search -t conda tensorflow
这里(anaconda search -t conda 库名)可以选择自己安装的源
可以看出tensorflow这个库大部分版本是安装在linux上的!只有2个可以在win64上安装!
3.输入:anaconda show conda-forge/tensorflow
也可以输入:anaconda show
dhirschfeld/tensorflow安装另外一个源(本人最初安装时就是安装的这个,结果出现错误,所以安装的上一个!安装完后再安装第一个发现又可以安装了,不过没装,毕竟已经安装过一个了)。
4.根据最后一行提示输入:conda install --channel https://conda.anaconda.org/conda-forge
tensorflow
5.上一步最后Proceed ([y]/n)?后面输入y回车
6,至此已经安装成功,输入:conda list
可以看出已安装。
如果tensorflow没有安装成功,那重复一遍conda install --channel
https://conda.anaconda.org/conda-forge tensorflow即可安装上。
方式三:
1、下载安装包。
在https://pypi.org/project/tensorflow/#files上下载
tensorflow-1.8.0-cp36-cp36m-manylinux1_x86_64.whl
<https://files.pythonhosted.org/packages/22/c6/d08f7c549330c2acc1b18b5c1f0f8d9d2af92f54d56861f331f372731671/tensorflow-1.8.0-cp36-cp36m-manylinux1_x86_64.whl>
安装包。
2、下载之后,将whl文件重命名为tensorflow-1.0.0-py3-none-linux_x86_64.whl,否则会出现tensorflow-1.0.0-cp36-cp36m-linux_x86_64.whl
is not a supported wheel on this
platform一样的报错,具体参考https://github.com/tensorflow/tensorflow/issues/1990
3、切换到whl文件所在文件夹
pip install --ignore-installed --upgrade tensorflow-1.0.
0-py3-none-linux_x86_64.whl #切记,不要用sudo pip,也不要用pip3,然后--ignore-installed
--upgrade等参数也不能省略,否则会出错。
注意:使用pip install tensorflow命令安装的tensorflow版本,比上面提到的1.0.0版本要高,是1.7.0版。
其他链接:
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
热门工具 换一换