[英]ModuleNotFoundError: No module named 'djoser' while running Django + Docker project
To add registration to django-project, I decided to use 'djoser' library.为了向 django-project 添加注册,我决定使用“djoser”库。 But while making migrations with docker-compose run server python manage.py makemigrations
, the same error raises:但是在使用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
The thing is that I already pip installed djoser (using the newest update of pip), I froze djoser too with the help of requirements.txt:问题是我已经 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
But it still doesn't work.但它仍然不起作用。 Section of 'settings.py' INSTALLED_APPS also is correct: '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',
]
I use docker-compose, and here is the web/Dockerfile
in which the operation happens:我使用 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
Seems that 'djoser' doesn't work without 'pandas'.似乎没有“熊猫”,“djoser”就无法工作。
That is why it is needed to add this library too.这就是为什么也需要添加这个库的原因。 My mistake was that I accidentally typed '=' instead of '==' in requirments.txt<\/code> .
我的错误是我不小心在
requirments.txt<\/code>中输入了 '=' 而不是 '==' 。
"
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.