[英]Import error no module in Django
I am importing a module named python_contextual_test_manager
in forms.py as follows: 我正在python_contextual_test_manager
中导入名为python_contextual_test_manager
的模块,如下所示:
from python_contextual_test_manager.main_runner import main as main_runner
Both python_contextual_test_manager.py
and forms.py
are in the same directory but it shows me the following error: python_contextual_test_manager.py
和forms.py
都在同一目录中,但是它显示了以下错误:
ImportError: No module named python_contextual_test_manager
What to do? 该怎么办?
I think adding a dot in front of the file name should get you sorted. 我认为在文件名前面添加一个点应该可以使您排序。 Like this: 像这样:
from .python_contextual_test_manager.main_runner import main as main_runner
. from .python_contextual_test_manager.main_runner import main as main_runner
。
The dot specifies that you want to import from the same folder that the file is in. Another way is to make the path absolute to the project directory, for example if all of that exists inside a Django app called app
, then you could also import 点表示您要从文件所在的文件夹中导入。另一种方法是使路径绝对指向项目目录,例如,如果所有路径都存在于名为app
的Django应用app
,那么您也可以导入
from app.python_contextual_test_manager.main_runner import main as main_runner
. from app.python_contextual_test_manager.main_runner import main as main_runner
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.