问题:
I have four different files named: main.py
, vector.py
, entity.py
and physics.py
.我有一个名为四种不同的文件: main.py
, vector.py
, entity.py
和physics.py
。 I will not post all the code, just the imports, because I think that's where the error is (If you want, I can post more).我不会发布所有代码,只会发布导入,因为我认为这就是错误所在(如果您愿意,我可以发布更多)。
main.py:主要.py:
import time
from entity import Ent
from vector import Vect
#the rest just creates an entity and prints the result of movement
entity.py:实体.py:
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
vector.py:矢量.py:
from math import *
class Vect:
#holds i, j, k, and does vector math
physics.py:物理.py:
from entity import Ent
class Physics:
#physics class gets an entity and does physics calculations on it.
I then run from main.py
and I get the following error:然后我从main.py
运行,我收到以下错误:
Traceback (most recent call last): File "main.py", line 2, in <module> from entity import Ent File ".../entity.py", line 5, in <module> from physics import Physics File ".../physics.py", line 2, in <module> from entity import Ent ImportError: cannot import name Ent
I'm guessing that the error is due to importing entity twice, once in main.py
, and later in physics.py
, but I don't know a workaround.我猜的错误是由于进口单位两次,一次在main.py
,后来在physics.py
,但我不知道一个解决办法。 Can anyone help?任何人都可以帮忙吗?
解决方案:
参考一: https://stackoom.com/question/cp0Z参考二: ImportError: Cannot import name X