2

我对 python 和 linux 非常陌生,我试图从教程中创建一个应用程序,当我尝试运行我的模型测试时发生了这种情况。

(venv) kali@kali:~/machinelearning/backend/server$ python manage.py test apps.ml.tests
Traceback (most recent call last):
  File "manage.py", line 21, in <module>
    main()
  File "manage.py", line 17, in main
    execute_from_command_line(sys.argv)
  File "/home/kali/machinelearning/venv/lib/python3.7/site-packages/django/core/management/__init__.py", line 381, in execute_from_command_line
    utility.execute()
  File "/home/kali/machinelearning/venv/lib/python3.7/site-packages/django/core/management/__init__.py", line 357, in execute
    django.setup()
  File "/home/kali/machinelearning/venv/lib/python3.7/site-packages/django/__init__.py", line 24, in setup
    apps.populate(settings.INSTALLED_APPS)
  File "/home/kali/machinelearning/venv/lib/python3.7/site-packages/django/apps/registry.py", line 91, in populate
    app_config = AppConfig.create(entry)
  File "/home/kali/machinelearning/venv/lib/python3.7/site-packages/django/apps/config.py", line 116, in create
    mod = import_module(mod_path)
  File "/usr/lib/python3.7/importlib/__init__.py", line 127, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 1006, in _gcd_import
  File "<frozen importlib._bootstrap>", line 983, in _find_and_load
  File "<frozen importlib._bootstrap>", line 965, in _find_and_load_unlocked
ModuleNotFoundError: No module named 'apps.endpointsapps'

这也是我关于stackoverflow的第一个问题

4

2 回答 2

1

请在apps文件夹中添加空__init__.py文件,以便Python可以将其识别为包。

检查此链接。关联

你能发布你的项目结构吗?基本上只是想看看那些应用程序存在的地方。

于 2020-07-10T04:44:03.510 回答
0

您需要在应用程序文件夹中添加一个空的init .py(总共 4 个下划线)文件,以便 Python 将其识别为一个包。

查看文档以获取更多信息。

于 2020-07-10T04:41:24.520 回答