最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

python - ModuleNotFoundError: No module named 'backend' when running my make seed data script in django-admin -

programmeradmin1浏览0评论

I am trying to debug and figure out what the issue is. When trying to search, I just get annoying AI responses which I don't want.

Here is my traceback:

  Traceback (most recent call last):
  File "/api/manage.py", line 22, in <module>
    main()
  File "/api/manage.py", line 18, in main
    execute_from_command_line(sys.argv)
  File "/usr/local/lib/python3.9/site-packages/django/core/management/__init__.py", line 442, in execute_from_command_line
    utility.execute()
  File "/usr/local/lib/python3.9/site-packages/django/core/management/__init__.py", line 416, in execute
    django.setup()
  File "/usr/local/lib/python3.9/site-packages/django/__init__.py", line 24, in setup
    apps.populate(settings.INSTALLED_APPS)
  File "/usr/local/lib/python3.9/site-packages/django/apps/registry.py", line 116, in populate
    app_config.import_models()
  File "/usr/local/lib/python3.9/site-packages/django/apps/config.py", line 269, in import_models
    self.models_module = import_module(models_module_name)
  File "/usr/local/lib/python3.9/importlib/__init__.py", line 127, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 1030, in _gcd_import
  File "<frozen importlib._bootstrap>", line 1007, in _find_and_load
  File "<frozen importlib._bootstrap>", line 986, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 680, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 850, in exec_module
  File "<frozen importlib._bootstrap>", line 228, in _call_with_frames_removed
  File "/api/api/companies/models.py", line 5, in <module>
    from backend.api.models import BaseModel
ModuleNotFoundError: No module named 'backend.api'
make: *** [seed] Error 1

Here is my settings.py INSTALLED_APPS:

INSTALLED_APPS = [
    # Local apps
    'api',
    'apipanies',
    'api.assessments',
    'api.users',
    "django.contrib.admin",
    "django.contrib.auth",
    "django.contrib.contenttypes",
    "django.contrib.sessions",
    "django.contrib.messages",
    "django.contrib.staticfiles",
]

Here is my file structure if it helps. Is there something I am missing to get this working?

    neurointerview/
├── backend/                         # Django backend
│   ├── __init__.py                  # Backend package initialization
│   ├── api/                         # Django app for API
│   │   ├── __init__.py              # API package initialization
│   │   ├── assessments/             # Assessment functionality
│   │   │   ├── __init__.py          # Python package initialization
│   │   │   ├── models.py            # Assessment data models
│   │   │   ├── serializers.py       # API serializers for assessments
│   │   │   └── views.py             # API endpoints for assessments
│   │   │
│   │   ├── companies/               # Company functionality 
│   │   │   ├── __init__.py          # Python package initialization
│   │   │   ├── models.py            # Company data models
│   │   │   ├── serializers.py       # API serializers for companies
│   │   │   └── views.py             # API endpoints for companies
│   │   │
│   │   ├── management/              # Django management commands
│   │   │   └── commands/            
│   │   │       └── seed_demo_data.py # Data seeding utility
│   │   │
│   │   ├── migrations/              # Database migrations
│   │   │   └── 0001_initial.py      # Initial migration
│   │   │
│   │   ├── users/                   # User functionality
│   │   │   ├── __init__.py          # Python package initialization
│   │   │   ├── models.py            # User data models
│   │   │   ├── permissions.py       # Permission classes
│   │   │   └── serializers.py       # API serializers for users
│   │   │
│   │   ├── models.py                # Core API models
│   │   └── views.py                 # Core API views
│   │
│   ├── backend/                     # Django project configuration
│   │   ├── settings.py              # Project settings
│   │   └── urls.py                  # URL routing configuration
│   │
│   └── manage.py                    # Django command-line utility

For anyone further curious this is my GitHub. I've been working on this and trying to clean things up a bit more:

So far, I have tried redoing my project structure entirely to what I have mapped out, in addition to doing relative imports to see if that would alleviate the problem. What I expected was that when I ran my make seed, I can populate my test database with some data.

Relative import example:

from ..models import BaseModel

与本文相关的文章

发布评论

评论列表(0)

  1. 暂无评论