TensorFlow 2 软件包现已推出
tensorflow:最新稳定版(适用于 Ubuntu 和 Windows),**支持 CPU 和 GPU **(CPU、GPU版本已经合并)tf-nightly:预览 build(不稳定)。Ubuntu 和 Windows 均包含 GPU 支持。旧版 TensorFlow
对于 TensorFlow 1.x,CPU 和 GPU 软件包是分开的: tensorflow==1.15:仅支持 CPU 的版本tensorflow-gpu==1.15:支持 GPU 的版本(适用于 Ubuntu 和 Windows) 1. 安装安装方法比较简单,直接使用pip3 install tensorflow命令进行安装。如果要安装指定版本,直接在后面指定版本即可:pip3 install tensorflow==2.2.0。
为了避免出错,建议使用pip3 --default-timeout=60 install tensorflow -i https://pypi.douban.com/simple/进行安装,来源见下面的问题…
注意:py3.8只能安装 tf2以上的版本。
2. 遇到的问题 2.1 tf下载慢tensorflow的安装包比较大,可以使用国内的镜像进行安装。如,pip3 install tensorflow -i https://pypi.tuna.tsinghua.edu.cn/simple,
2.2 使用清华源安装tf报错 OpenSSL.SSL.WantReadError使用pip3 install tensorflow -i https://pypi.tuna.tsinghua.edu.cn/simple命令安装tf,下载一部分之后报错:
ERROR: Exception:Traceback (most recent call last): File "/usr/share/python-wheels/urllib3-1.25.8-py2.py3-none-any.whl/urllib3/contrib/pyopenssl.py", line 313, in recv_into return self.connection.recv_into(*args, **kwargs) File "/usr/lib/python3/dist-packages/OpenSSL/SSL.py", line 1840, in recv_into self._raise_ssl_error(self._ssl, result) File "/usr/lib/python3/dist-packages/OpenSSL/SSL.py", line 1646, in _raise_ssl_error raise WantReadError()OpenSSL.SSL.WantReadError后面更换为,豆瓣源进行下载安装(pip3 install tensorflow -i https://pypi.douban.com/simple/),下载中,最后一秒钟被kill,安装失败,问题解决方法见 2.3
2.3 使用豆瓣源,在最后几秒钟程序被kill使用命令pip3 install tensorflow -i https://pypi.tuna.tsinghua.edu.cn/simple安装,在还剩1s时,出现killed字样,如下所示
看了下pip man手册,发现有–timeout参数,默认为15s,再次安装,在出现eta 0:00:01时开始计时,15s后,被kill。所以这里kill是因为超时了,修改默认超时参数,问题终于解决。
这里修改方法为:pip3 --default-timeout=60 install tensorflow -i https://pypi.douban.com/simple/
安装成功:
自己下载安装包,进行离线安装,离线安装命令为:
pip3 install tensorflow --no-index --find-links ./tensorflow-2.2.0-cp38-cp38-manylinux2010_x86_64.whl因为tf会依赖其他库,如果采用离线安装,遇到没有的库,需要自己一个个进行单独安装,比较麻烦,可以见下面的相关错误,在此不推荐离线安装。(此处仅仅为了说明pip如何进行离线安装)
安装TensorFlow,遇到如下错误:
ERROR: Could not find a version that satisfies the requirement gast==0.3.3 (from tensorflow) (from versions: none)
ERROR: No matching distribution found for gast==0.3.3 (from tensorflow)
这里是,使用pip3 install gast==0.3.3 -i https://pypi.tuna.tsinghua.edu.cn/simple命令安装gast。
ERROR: Could not find a version that satisfies the requirement tensorboard<2.3.0,>=2.2.0 (from tensorflow) (from versions: none)
ERROR: No matching distribution found for tensorboard<2.3.0,>=2.2.0 (from tensorflow)
ERROR: Could not find a version that satisfies the requirement wrapt>=1.11.1 (from tensorflow) (from versions: none)
ERROR: No matching distribution found for wrapt>=1.11.1 (from tensorflow)
对上面用到的几种方法进行总结
3.1 离线安装方法 pip3 install tensorflow --no-index --find-links ./tensorflow-2.2.0-cp38-cp38-manylinux2010_x86_64.whl 3.2 超时时间参数设置单次下载的超时参数修改,对应命令为:
pip3 --default-timeout=60 install ... 3.3