更新pip10后,使用pip安装keras出现错误:ImportError: cannot import name 'main'

1、安装好anaconda, cuda, cudnn, tensorflow后,由于更新了pip到10版本,安装keras时出错:

(base) C:\Users\Administrator>pip install keras --pre
Traceback (most recent call last):
  File "C:\ProgramData\Anaconda3\Scripts\pip-script.py", line 6, in <module>
    from pip import main
ImportError: cannot import name 'main'

2、找到出错的文件C:\ProgramData\Anaconda3\Scripts下的pip-script.py:


修改为:

# -*- coding: utf-8 -*-

import re

import sys

from pip._internal import main as _main

if __name__ == '__main__':

  sys.argv[0] = re.sub(r'(-script\.pyw?|\.exe)?$', '', sys.argv[0])

  sys.exit(_main())

3、修改后,keras成功安装,但是jupyter notebook需要ipykernel,但是提示没有安装。


(base) C:\Users\Administrator>pip install keras --pre
Looking in indexes: http://mirrors.aliyun.com/pypi/simple/
Collecting keras
  Downloading http://mirrors.aliyun.com/pypi/packages/54/e8/eaff7a09349ae9bd40d3ebaf028b49f5e2392c771f294910f75bb608b241/Keras-2.1.6-py2.py3-none-any.whl (339kB)
    100% |████████████████████████████████| 348kB 2.7MB/s
Requirement already satisfied: h5py in c:\programdata\anaconda3\lib\site-packages (from keras) (2.7.1)
Requirement already satisfied: six>=1.9.0 in c:\programdata\anaconda3\lib\site-packages (from keras) (1.11.0)
Requirement already satisfied: pyyaml in c:\programdata\anaconda3\lib\site-packages (from keras) (3.12)
Requirement already satisfied: numpy>=1.9.1 in c:\users\administrator\appdata\roaming\python\python36\site-packages (from keras) (1.14.3)
Requirement already satisfied: scipy>=0.14 in c:\programdata\anaconda3\lib\site-packages (from keras) (1.0.0)
notebook 5.4.0 requires ipykernel, which is not installed.
jupyter 1.0.0 requires ipykernel, which is not installed.
jupyter-console 5.2.0 requires ipykernel, which is not installed.
ipywidgets 7.1.1 requires ipykernel>=4.5.1, which is not installed.
Installing collected packages: keras
Successfully installed keras-2.1.6

4、安装notebook,并成功

敲入指令:pip install --user notebook



5、再检验keras,没有报错,且成功安装


jupyter notebook中导入keras不报错


参考文档:

https://www.cnblogs.com/dylan9/p/8981155.html

https://blog.csdn.net/qq_23031939/article/details/80041591

阅读更多
个人分类: 环境搭建
想对作者说点什么? 我来说一句

没有更多推荐了,返回首页

关闭
关闭
关闭