在ipython下输入命令import keras,出现如下错误,如何解决?

依依雨柔
  • 233
>>> import keras
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/user1/anaconda2/lib/python2.7/site-packages/keras/__init__.py", line 3, in <module>
    from . import activations
  File "/home/user1/anaconda2/lib/python2.7/site-packages/keras/activations.py", line 3, in <module>
    from . import backend as K
  File "/home/user1/anaconda2/lib/python2.7/site-packages/keras/backend/__init__.py", line 6, in <module>
    from .common import epsilon
  File "/home/user1/anaconda2/lib/python2.7/site-packages/keras/backend/common.py", line 1, in <module>
    import numpy as np
  File "/home/user1/anaconda2/lib/python2.7/site-packages/numpy/__init__.py", line 142, in <module>
    from . import add_newdocs
  File "/home/user1/anaconda2/lib/python2.7/site-packages/numpy/add_newdocs.py", line 13, in <module>
    from numpy.lib import add_newdoc
  File "/home/user1/anaconda2/lib/python2.7/site-packages/numpy/lib/__init__.py", line 8, in <module>
    from .type_check import *
  File "/home/user1/anaconda2/lib/python2.7/site-packages/numpy/lib/type_check.py", line 11, in <module>
    import numpy.core.numeric as _nx
  File "/home/user1/anaconda2/lib/python2.7/site-packages/numpy/core/__init__.py", line 74, in <module>
    from numpy.testing import _numpy_tester
  File "/home/user1/anaconda2/lib/python2.7/site-packages/numpy/testing/__init__.py", line 12, in <module>
    from . import decorators as dec
  File "/home/user1/anaconda2/lib/python2.7/site-packages/numpy/testing/decorators.py", line 6, in <module>
    from .nose_tools.decorators import *
  File "/home/user1/anaconda2/lib/python2.7/site-packages/numpy/testing/nose_tools/decorators.py", line 20, in <module>
    from .utils import SkipTest, assert_warns
  File "/home/user1/anaconda2/lib/python2.7/site-packages/numpy/testing/nose_tools/utils.py", line 15, in <module>
    from tempfile import mkdtemp, mkstemp
  File "/home/user1/anaconda2/lib/python2.7/tempfile.py", line 35, in <module>
    from random import Random as _Random
  File "random.py", line 16, in <module>
    generateRand(1)
  File "random.py", line 10, in generateRand
    tempInt=random.randint(A,B)
AttributeError: 'module' object has no attribute 'randint'
回复
阅读 4.6k
1 个回答

把你当前目录下文件名为random.py的文件,换个名字,例如改成myrandom.py
不要使用库中的名字给文件起名

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
宣传栏