運行docker-compose run server python manage.py makemigrations(進行遷移)并收到此錯誤時:
django.template.library.InvalidTemplateLibrary: Invalid template library specified.
ImportError raised when trying to load 'rest_framework.templatetags.rest_framework': No mo
dule named 'pytz'
我的docker-compose.yml:
version: '3'
services:
db:
build: ./etc/docker/db
restart: always
volumes:
- ./var/volumes/dbdata:/var/lib/mysql
env_file:
- ./etc/docker/db/env
healthcheck:
test: mysqladmin ping -h 127.0.0.1 -u root --password=example
interval: 1s
timeout: 5s
retries: 10
server: &web
build:
context: .
dockerfile: ./etc/docker/web/Dockerfile
volumes:
- ./server:/home/web/server
# depends_on:
# db: {condition: service_healthy}
ports:
- "8080:8080"
command: ["python", "manage.py", "runserver", "0.0.0.0:8080"]
我嘗試pytz通過 pip install pytz 安裝,但仍然出現相同的錯誤。現在我很困惑,請解釋可能是什么問題。
uj5u.com熱心網友回復:
您需要在 Dockerfile 中安裝所有依賴項。您的 dockerfile 應該包含類似的內容
COPY requirements.txt /app/requirements.txt
RUN pip install -r /app/requirements.txt
您的 requirements.txt 包含運行服務器所需的所有庫。
或者你可以在 dockerfile 中安裝你需要的庫
RUN pip install pytz django etc...
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/377702.html
