簡體   English   中英

ModuleNotFoundError:運行 Django + Docker 項目時沒有名為“djoser”的模塊

[英]ModuleNotFoundError: No module named 'djoser' while running Django + Docker project

為了向 django-project 添加注冊,我決定使用“djoser”庫。 但是在使用docker-compose run server python manage.py makemigrations進行遷移時,會出現同樣的錯誤:

Creating school-co_server_run ... done
Traceback (most recent call last):
  File "/home/web/server/manage.py", line 22, in <module>
    main()
  File "/home/web/server/manage.py", line 18, in main
    execute_from_command_line(sys.argv)
  File "/home/web/venv/lib/python3.9/site-packages/django/core/management/__init__.py", line 401, in execute_from_command_line
    utility.execute()
  File "/home/web/venv/lib/python3.9/site-packages/django/core/management/__init__.py", line 377, in execute
    django.setup()
  File "/home/web/venv/lib/python3.9/site-packages/django/__init__.py", line 24, in setup
    apps.populate(settings.INSTALLED_APPS)
  File "/home/web/venv/lib/python3.9/site-packages/django/apps/registry.py", line 91, in populate
    app_config = AppConfig.create(entry)
  File "/home/web/venv/lib/python3.9/site-packages/django/apps/config.py", line 90, in create
    module = import_module(entry)
  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 984, in _find_and_load_unlocked
ModuleNotFoundError: No module named 'djoser'
ERROR: 1

問題是我已經 pip 安裝了 djoser(使用 pip 的最新更新),我也在 requirements.txt 的幫助下凍結了 djoser:

asgiref==3.2.10
attrs==21.2.0
Django==3.1
django-environ==0.8.1
django-extensions==3.1.5
django-filter==21.1
djangorestframework==3.12.4
djangorestframework-camel-case==1.2.0
drf-spectacular==0.21.0
inflection==0.5.1
jsonschema==4.2.1
Markdown==3.3.6
mysqlclient==2.1.0
Pillow==8.4.0
pyrsistent==0.18.0
pytz==2021.3
PyYAML==6.0
sqlparse==0.4.2
uritemplate==4.1.1
djoser==2.0.1
pandas=1.1.3

但它仍然不起作用。 'settings.py' INSTALLED_APPS 部分也是正確的:

INSTALLED_APPS = [
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'base',
    'school_co',
    'django_extensions',
    'rest_framework',
    'rest_framework.authtoken',
    'drf_spectacular',
    'djoser',
    'rest_framework_simplejwt',
]

我使用 docker-compose,這里是操作發生的web/Dockerfile

FROM python:3.9-slim-bullseye

ENV PYTHONUNBUFFERED=1

RUN set -ex \
    && apt-get update \
    && apt-get install curl default-libmysqlclient-dev gcc -y \
    && rm -rf /var/lib/apt/lists/*

RUN useradd --create-home --shell /bin/bash --home /home/web web
USER web
WORKDIR /home/web

COPY etc/requirements.txt ./etc/requirements.txt

RUN set -ex \
    && python -m venv /home/web/venv \
    && ./venv/bin/pip install --upgrade pip \
    && ./venv/bin/pip install --no-cache-dir -r ./etc/requirements.txt

COPY etc/env ./etc/env

ENV VIRTUAL_ENV /home/web/venv
ENV PATH /home/web/venv/bin:$PATH
WORKDIR /home/web/server

似乎沒有“熊貓”,“djoser”就無法工作。

這就是為什么也需要添加這個庫的原因。 我的錯誤是我不小心在requirments.txt<\/code>中輸入了 '=' 而不是 '==' 。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM