【发布时间】:2019-12-05 09:54:33
【问题描述】:
我已经在我的 django rest 框架中实现了 mypy,但是在运行 mypy 时出现错误 ModuleNotFoundError: No module named 'config'。我的 mypy.ini 文件中的 django_settings_module 有什么问题吗?
我曾经使用命令 python manage.py runserver --settings=config.settings.development 运行我的项目,该命令运行良好,但是在 mypy 中配置此设置时,它给了我错误。我可能做错了什么?
任何帮助将不胜感激。
mypy.ini
[mypy]
plugins =
mypy_django_plugin.main,
mypy_drf_plugin.main
ignore_missing_imports = True
warn_unused_ignores = True
strict_optional = True
check_untyped_defs = True
follow_imports = silent
show_column_numbers = True
[mypy.plugins.django-stubs]
export PYTHONPATH=$PYTHONPATH:D:\DjangoProjects\project\config
django_settings_module = config.settings.development
设置目录
/project
/config
__init__.py
urls.py
wsgi.py
/settings
__init__.py
base.py
development.py
wsgi.py
app_path = os.path.abspath(
os.path.join(os.path.dirname(os.path.abspath(__file__)), os.pardir)
)
sys.path.append(os.path.join(app_path, "project"))
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'config.settings')
application = get_wsgi_application()
【问题讨论】:
-
看起来像 PYTHONPATH 问题,您能否将您的
config添加到其中并检查问题是否仍然存在 -
如何将我的配置添加到 PYTHONPATH @SardorbekImomaliev
-
export PYTHONPATH=$PYTHONPATH:/path/to/your/config,查找更多信息
-
-
不,应该在你的 shell 环境中设置
标签: django django-rest-framework mypy