python nameerror import_Python-ImportError:无法导入名称X
我有四個不同的文件,分別命名為:main,vector,entity和physics。我不會發布所有代碼,而只會發布導入代碼,因為我認為這就是錯誤所在。(如果需要,我可以發布更多信息)
主要:
import time
from entity import Ent
from vector import Vect
#the rest just creates an entity and prints the result of movement
實體:
from vector import Vect
from physics import Physics
class Ent:
#holds vector information and id
def tick(self, dt):
#this is where physics changes the velocity and position vectors
向量:
from math import *
class Vect:
#holds i, j, k, and does vector math
物理:
from entity import Ent
class Physics:
#physics class gets an entity and does physics calculations on it.
然后,我從main.py運行,出現以下錯誤:
Traceback (most recent call last):
File "main.py", line 2, in
from entity import Ent
File ".../entity.py", line 5, in
from physics import Physics
File ".../physics.py", line 2, in
from entity import Ent
ImportError: cannot import name Ent
我對Python非常陌生,但是已經使用C ++了很長時間。我猜測該錯誤是由于兩次導入實體引起的,一次是在主體中,一次是在物理中,但是我不知道解決方法。有人可以幫忙嗎?
總結
以上是生活随笔為你收集整理的python nameerror import_Python-ImportError:无法导入名称X的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 两个场景怎样合在一起_Spring AO
- 下一篇: 北交所临时停牌规则