【问题标题】:How to fix ModuleNotFoundError: No module named 'rest_auth'如何修复 ModuleNotFoundError:没有名为“rest_auth”的模块
【发布时间】:2019-07-10 05:04:06
【问题描述】:

我在虚拟环境中使用 docker 和 pipenv,运行 docker-compose up 时出现以下错误:

ModuleNotFoundError: No module named 'rest_auth'

我尝试了 pip install django-rest-authpipenv 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",

]

预计在 localhost:8000 上运行 docker 容器并访问后端

实际:docker-compose up > ModuleNotFoundError: No module named '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

【问题讨论】:

  • 你能发布 Dockerfile 和/或任何 docker 相关的配置吗?谢谢
  • 好的。见主帖。谢谢。
  • a) 你能展示你的 Pipfile 吗? b) 如果您将 RUN pipenv install --system 更改为 RUN pipenv install django-rest-auth --system 会变成什么 - 我知道这不是您想要的,但为了实验,c) 您可以尝试将 python manage.py runserver 更改为 pipenv run manage.py runserver 吗?

标签: docker django-rest-framework pipenv django-rest-auth


【解决方案1】:

我遇到了同样的错误并这样做了:

首先我做到了:

pip 卸载 django-rest_auth

然后:

pip3 安装 django-rest_auth。

希望这行得通。

【讨论】:

    猜你喜欢
    • 2023-03-16
    • 2019-10-06
    • 2019-09-18
    • 2021-07-03
    • 2019-07-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多