安装tensorflow时遇到的坑

前言

由于之前发行的2.x版本不如1.x版本稳定,作为初学者我选择1.14.0版本的tensorflow安装。然而,安装时遇到了一些问题,故在此整理。

遇到的问题

本文中使用pip安装cpu版本。

ERROR

  • ReadTimeoutError: HTTPSConnectionPool(host=‘pypi.tuna.tsinghua.edu.cn’, port=443): Read timed out.

这个是下载时由于模块的下载源在国外,导致超时而引起的错误。
方法一:替换源下载

pip install tensorflow -i https://pypi.doubanio.com/simple/

使用清华源仍可能出现超时现象,多试几次一般就行了。

方法二:设置超时限制

pip install --default-timeout=100 tensorflow
  • ERROR: Cannot uninstall ‘wrapt’. It is a distutils installed project and thus we cannot accurately determine which files belong to it which would lead to only a partial uninstall.

输入命令行

pip install -U --ignore-installed wrapt enum34 simplejson netaddr

成功解决。

  • ERROR: tensorboard 1.14.0 has requirement setuptools>=41.0.0, but you’ll have setuptools 39.1.0 which is incompatible.

直接更新setuptools即可

pip install --upgrade setuptools

WARNING

  • FutureWarning: Passing (type, 1) or ‘1type’ as a synonym of type
    is deprecated

完成安装后,再导入tensorflow模块时抛出的错误,具体报错信息:

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)])
  还有很多相似行,这里就不列举了

原因是所下载的tensorflow版本与numpy版本不一致。经查询发现,我所安装的tensorflow 1.14.0版本对应的numpy版本号为 1.16.0。
故更新numpy,

pip install --upgrade numpy==1.16.0

warning消失。

  • 2020-05-19 18:37:08.735926: I tensorflow/core/platform/cpu_feature_guard.cc:142] Your CPU supports instructions that this TensorFlow binary was not compiled to use: AVX2

其实算不上warning,就是一条提示语句
大意是说CPU可以用AVX2,但是tensorflow编译时不能使用。这是因为pip下载的是通用版,根据指令集不同,需要进行不同的编译。

先用一个暂时的解决方案:

import os  
os.environ["TF_CPP_MIN_LOG_LEVEL"]='2'

可以暂时屏蔽这条信息,以后需要时再做处理吧。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值