-1

I have macOS Sierra, using python 2.7 for a homework. I have an import problem as followed :

File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/networkx/release.py", line 43, in <module>
import time
File "/Users/chen/Desktop/minesparis/JE/Chronomap/scripts/time.py", line 3, in <module>
import matplotlib.pyplot as plt
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/matplotlib/__init__.py", line 122, in <module>
from matplotlib.cbook import is_string_like, mplDeprecation, dedent, get_label
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/matplotlib/cbook.py", line 33, in <module>
  import numpy as np
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/numpy/__init__.py", line 201, in <module>
  from . import random
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/numpy/random/__init__.py", line 99, in <module>
  from .mtrand import *
File "mtrand.pyx", line 151, in init mtrand (numpy/random/mtrand/mtrand.c:37668)
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/dummy_threading.py", line 45, in <module>
  import threading
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/threading.py", line 15, in <module>
  from time import time as _time, sleep as _sleep
  ImportError: cannot import name time

I open the script threading.py and try to run it and everything seems working. When I write

 from time import time as _time, sleep as _sleep 

on my console, the import works. so I don't know what is the problem and how can I solve it..

Thank you very much! Mia

Mia Chen
  • 173
  • 2
  • 10
  • In short, you are shadowing names here. Don't name your script `time.py`. – idjaw Dec 29 '16 at 01:56
  • The problem is that you named your script `time.py`, so when you import time, you are importing your own file rather than the time module. – Bryan Oakley Dec 29 '16 at 01:59

1 Answers1

1

You named your script time.py. It relies on the builtin module time.

Now, if you were the Python Interpreter, how would you tell the difference between your time script and the builtin one? It can't! Instead, local files take precedence.

Simply rename your script to something else.

noɥʇʎԀʎzɐɹƆ
  • 9,967
  • 2
  • 50
  • 67