Linux离线安装keras报错解决方案

由于服务器处于断网状态,所以使用了离线下载whl文件安装的方法,具体操作可以参考这篇博客

https://blog.csdn.net/m511655654/article/details/85274861

https://pypi.org/下载了Keras-2.2.4-py2.py3-none-any.whl文件,使用 pip install 安装,发现报错

Processing ./Keras-2.2.4-py2.py3-none-any.whl
Collecting pyyaml (from Keras==2.2.4)
  Retrying (Retry(total=4, connect=None, read=None, redirect=None, status=None)) after connection broken by 'NewConnectionError('<pip._vendor.urllib3.connection.VerifiedHTTPSConnection object at 0x7f17979eeba8>: Failed to establish a new connection: [Errno 101] Network is unreachable',)': /simple/pyyaml/
  Retrying (Retry(total=3, connect=None, read=None, redirect=None, status=None)) after connection broken by 'NewConnectionError('<pip._vendor.urllib3.connection.VerifiedHTTPSConnection object at 0x7f17979eebe0>: Failed to establish a new connection: [Errno 101] Network is unreachable',)': /simple/pyyaml/
  Retrying (Retry(total=2, connect=None, read=None, redirect=None, status=None)) after connection broken by 'NewConnectionError('<pip._vendor.urllib3.connection.VerifiedHTTPSConnection object at 0x7f17979ee9b0>: Failed to establish a new connection: [Errno 101] Network is unreachable',)': /simple/pyyaml/
  Retrying (Retry(total=1, connect=None, read=None, redirect=None, status=None)) after connection broken by 'NewConnectionError('<pip._vendor.urllib3.connection.VerifiedHTTPSConnection object at 0x7f17979eb630>: Failed to establish a new connection: [Errno 101] Network is unreachable',)': /simple/pyyaml/
  Retrying (Retry(total=0, connect=None, read=None, redirect=None, status=None)) after connection broken by 'NewConnectionError('<pip._vendor.urllib3.connection.VerifiedHTTPSConnection object at 0x7f17979eb390>: Failed to establish a new connection: [Errno 101] Network is unreachable',)': /simple/pyyaml/
  Could not find a version that satisfies the requirement pyyaml (from Keras==2.2.4) (from versions: )
No matching distribution found for pyyaml (from Keras==2.2.4)

 上网百度了一发现是因为keras有一个安装死循环的大坑:

在安装Keras的过程中提示需要Keras_Applications,安装Keras_Applications的时候又需要Keras,陷入死循环;Keras_Preprocessing也有同样的问题。

所以解决方案是先安装一个低版本的keras,然后再安装Keras_Applications和Keras_Preprocessing,最后安装新版的Keras。

此处下载Keras-2.1.6.tar.gz,文件来源清华镜像pip下载点。

下载下来是Keras-2.1.6.tar.gz,使用pip install安装即可。

cd 安装文件所在文件夹绝对位置
pip install Keras-2.1.6.tar.gz

后续安装Keras_Applications和Keras_Preprocessing同理,以及keras2.2.4最新版本。

如果清华镜像点打不开,可以选择其他镜像源下载,打开网址后,ctrl+f搜索需要下载的python包名称,选择不同python版本和系统版本/位数进行下载。

  • 阿里云 http://mirrors.aliyun.com/pypi/simple/ 
  • 中国科技大学 https://pypi.mirrors.ustc.edu.cn/simple/ 
  • 豆瓣(douban) http://pypi.douban.com/simple/ 
  • 清华大学 https://pypi.tuna.tsinghua.edu.cn/simple/ 
  • 中国科学技术大学 http://pypi.mirrors.ustc.edu.cn/simple/

博主发现进行上述操作还是无法安装keras,后来发现是pyyaml包没有安装的原因。

打开阿里云镜像源pyyaml包下载地址http://mirrors.aliyun.com/pypi/simple/pyyaml/,由于服务器是linux系统,无法下载win系统的whl,所以选择下载PyYAML-3.12.tar.gz(可以选择其他版本号)。

cd 安装文件所在文件夹绝对位置
pip install PyYAML-3.12.tar.gz
pip install Keras-2.2.4-py2.py3-none-any.whl

 至此,安装成功。

打开python环境测试

python

import keras

 

keras模块可以导入,问题解决。

猜你喜欢

转载自blog.csdn.net/m511655654/article/details/86540336