无法导入类 - 导入错误

时间:2021-06-02 22:59:57

My app looks like this:

我的应用程序如下所示:

myproject
  - my_app1
  -- lib
  --- my_module1
  ---- __init__.py
  ---- file1.py
  ---- file2.py
  ---- file3.py

  -- views.py

In lib/my_module1.file1.py

在lib / my_module1.file1.py中

  class MyClass1(...):.....

And this gives me an import error:

这给了我一个导入错误:

In views.py I have:

在views.py我有:

  from my_module1.file1 import MyClass1 #Not found

Why is that?

这是为什么?

1 个解决方案

#1


1  

You forgot to add __init__.py into the lib directory.

您忘了将__init__.py添加到lib目录中。

Also I suspect that you should import like this:

另外我怀疑你应该像这样导入:

from my_app1.lib.my_module1.file1 import MyClass1

#1


1  

You forgot to add __init__.py into the lib directory.

您忘了将__init__.py添加到lib目录中。

Also I suspect that you should import like this:

另外我怀疑你应该像这样导入:

from my_app1.lib.my_module1.file1 import MyClass1