我有macOS Sierra,使用python 2.7作家庭作業。 我作爲跟隨進口問題:Python 2.7 - 文件threading.py似乎不工作 - ImportError:無法導入名稱時間
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
我打開腳本threading.py並嘗試運行它,一切似乎工作。 當我寫
from time import time as _time, sleep as _sleep
在我的控制檯上,導入工程。 所以我不知道是什麼問題,我該如何解決它..
非常感謝! Mia
總之,你在這裏隱藏着名字。不要將腳本命名爲'time.py'。 – idjaw
問題在於你命名了你的腳本'time.py',所以當你輸入時間時,你正在導入你自己的文件而不是時間模塊。 –