Home > Software design >  Docker error while running: no module named 'pytz'
Docker error while running: no module named 'pytz'

Time:12-09

When running docker-compose run server python manage.py makemigrations (making migrations) and getting this error:

django.template.library.InvalidTemplateLibrary: Invalid template library specified. 
ImportError raised when trying to load 'rest_framework.templatetags.rest_framework': No mo
dule named 'pytz'

My 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"]

I tried installing pytz through pip install pytz, but I still get the same error. Now I'm confused, please explain what the problem could be.

CodePudding user response:

You need to install all dependencies inside Dockerfile. Your dockerfile should contains something like

COPY requirements.txt /app/requirements.txt  
RUN pip install -r /app/requirements.txt

Where your requirements.txt contains all libraries you need to run the server.

or you can just install libs you need inside dockerfile

RUN pip install pytz django etc...
  • Related