首页 > 解决方案 > Python - ImportError: cannot import name - another question

问题描述

I've seen dozens of questions like this with different problems / solutions. After going through the first dozen or so on StackOverflow, I haven't found a solution to my problem which is:

I have a class like this:

class Flight:
    pass

in a file called airtravel.py and then on my REPL (in that directory) I use:

from airtravel import Flight

which immediately fails with:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: cannot import name Flight
>>> 

Any suggestions?

标签: python

解决方案


您可以尝试以下建议,看看是否有帮助。

  1. 您的文件的最新内容可能airtravel.py未保存。
  2. 尝试将您的文件重命名airtravel.py为其他名称说airtraveltest.py

推荐阅读