Cornspierre
Cornspierre

Reputation: 332

Cannot import time until after sys module. Python

I'm having problems loading up ipython notebook, there seems to be an error with importing time:

//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'

Weirdly (to me), I also cannot load the time module into python unless I have also imported 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
>>> 

This occurred after I cleaned up my .bash_profile and .profile by removing commented out lines. Any help/explanation would be much appreciated.

Thanks.

Upvotes: 0

Views: 3213

Answers (1)

Martijn Pieters
Martijn Pieters

Reputation: 1122152

You have a local file named time.py that is masking the built-in type. Remove or rename it. You can see the filename of the masking module by entering:

import time
print time

In your second import, you got a warning, not an error. The import time line worked, but it triggered code that also tripped over the wrong time module being loaded. Importing it again re-used the already imported module object, and even if it did run the import in full again warnings are only logged once normally.

Upvotes: 4

Related Questions