我在虚拟环境中使用docker和pipenv,并且在运行docker-compose up时遇到以下错误:
ModuleNotFoundError: No module named 'rest_auth'
我尝试了pip install django-rest-auth
和pipenv install django-rest-auth
并将以下内容添加到我的INSTALLED_APPS
# Django REST Framework Apps
'rest_framework',
'rest_framework.authtoken',
'rest_auth',
INSTALLED_APPS = [
"django.contrib.admin",
"django.contrib.auth",
"django.contrib.contenttypes",
"django.contrib.sessions",
"django.contrib.messages",
"django.contrib.staticfiles",
# Other Package Apps
"storages",
# Django REST Framework Apps
'rest_framework',
'rest_framework.authtoken',
'rest_auth',
# Internal Apps
"authentication",
]
预期运行docker容器并访问localhost:8000上的后端
实际:docker-compose up> ModuleNotFoundError:没有名为“ rest_auth”的模块
Dockerfile:
FROM python:3.7
ENV PYTHONUNBUFFERED 1
RUN apt-get update -y && \
apt-get install -y postgresql postgresql-contrib && \
apt-get clean
RUN mkdir /code
WORKDIR /code
ADD . /code/
RUN pip install pipenv
RUN pipenv install --system
ENTRYPOINT ["./docker-entrypoint.sh"]
docker-entrypoint.sh:
#!/bin/bash
case "$1" in
web_app)
until psql postgres://postgres:$POSTGRES_PASSWORD@db -c '\q'; do
>&2 echo "Postgres is unavailable - sleeping"
sleep 1
done
>&2 echo "Postgres is up!"
case "$2" in
migrate)
python manage.py migrate
;;
static)
python manage.py collectstatic --clear --noinput
python manage.py collectstatic --noinput
;;
migrate_and_static)
python manage.py migrate
python manage.py collectstatic --clear --noinput
python manage.py collectstatic --noinput
;;
esac
case "$3" in
prod)
echo "Starting Gunicorn."
exec gunicorn service_health.wsgi:application \
--bind 0.0.0.0:8000 \
--workers 3 \
--access-logfile '-'
;;
local)
pipenv install --system
echo "Starting local server"
python manage.py runserver 0.0.0.0:8000
;;
esac
;;
esac
docker-compose.yml:
version: '3'
services:
postgres:
image: postgres:11.1
environment:
- POSTGRES_PASSWORD=password
ports:
- "5432:5432"
api:
build:
context: backend
environment:
- POSTGRES_PASSWORD=password
volumes:
- $PWD/backend:/code
ports:
- 8000:8000
links:
- postgres:db
command: web_app migrate local
frontend:
build:
context: frontend
volumes:
- $PWD/frontend:/code
environment:
- NODE_ENV=development
ports:
- 3000:3000
答案 0 :(得分:0)
首先是:
<块引用>pip 卸载 django-rest_auth
然后:
<块引用>pip3 安装 django-rest_auth。
希望这有效。