我在加载ipython笔记本时遇到问题,导入时间似乎有误:
//anaconda/python.app/Contents/lib/python2.7/logging/__init__.py:26: RuntimeWarning: import threads:
cannot import name time
(ImportError: cannot import name time)
import sys, os, time, cStringIO, traceback, warnings, weakref, collections
Traceback (most recent call last):
File "//anaconda/bin/ipython", line 4, in <module>
from IPython import start_ipython
File "//anaconda/lib/python2.7/site-packages/IPython/__init__.py", line 45, in <module>
from .config.loader import Config
File "//anaconda/lib/python2.7/site-packages/IPython/config/__init__.py", line 16, in <module>
from .application import *
File "//anaconda/lib/python2.7/site-packages/IPython/config/application.py", line 23, in <module>
import logging
File "//anaconda/python.app/Contents/lib/python2.7/logging/__init__.py", line 95, in <module>
_startTime = time.time()
AttributeError: 'module' object has no attribute 'time'
奇怪(对我来说),我也无法将时间模块加载到python中,除非我还导入了sys!
Python 2.7.8 |Anaconda 2.0.1 (x86_64)| (default, Jul 2 2014, 15:36:00)
[GCC 4.2.1 (Apple Inc. build 5577)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
Anaconda is brought to you by Continuum Analytics.
Please check out: http://continuum.io/thanks and https://binstar.org
>>> import time
__main__:1: RuntimeWarning: import threads: cannot import name time
(ImportError: cannot import name time)
>>> import sys
>>> import time
>>>
这是在我通过删除注释掉的行来清理我的.bash_profile和.profile之后发生的。 任何帮助/解释都将非常感激。
感谢。
答案 0 :(得分:4)
您有一个名为time.py
的本地文件,它掩盖了内置类型。删除或重命名它。您可以通过输入以下内容来查看屏蔽模块的文件名:
import time
print time
在第二次导入中,您收到了警告,而不是错误。 import time
行工作,但它触发的代码也会因正在加载的错误time
模块而跳闸。再次导入它会重新使用已导入的模块对象,即使它确实再次运行导入,警告也只会记录一次。