0

I'm trying to use django-widget-tweaks in my web application (using Django and Docker), but it is not being recognized as an installed package.

My DockerFile:

# Pull base image
FROM python:3.10.2-slim-bullseye

# Set environment variables
ENV PIP_DISABLE_PIP_VERSION_CHECK 1
ENV PYTHONDONTWRITEBYTECODE 1
ENV PYTHONUNBUFFERED 1

# Set work directory
WORKDIR /code

# Install dependencies
COPY ./requirements.txt .
RUN pip install -r requirements.txt
RUN pip3 install django-widget-tweaks

# Copy project
COPY . .

My settings.py:

INSTALLED_APPS = [
    'users.apps.UsersConfig',
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'openai',   
]

INSTALLED_APPS += [
    'widget_tweaks',
]

The error:

Exception in thread django-main-thread:
project-web-1  | Traceback (most recent call last):
...
project-web-1  | ModuleNotFoundError: No module named 'widget_tweaks'
Dhruv Erry
  • 161
  • 3
  • 8
  • 1
    An reason you are using pip first and then pip3? They probably point to the same executable, but just to be sure. – Rob Jun 19 '23 at 09:19
  • I tried it with pip first, but it didn't work. Then some folks online said pip3 worked for them for this particular module, so I edited the run command in my Dockerfile, but no luck. – Dhruv Erry Jun 19 '23 at 09:23
  • @Rob To be clear, this module isn't in my requirements.txt – Dhruv Erry Jun 19 '23 at 09:24
  • I would use the same command (pip/pip3) for all dependencies to make sure they are installed to the same environment. Did you try adding `django-widget-tweaks` to requirements.txt? – Rob Jun 19 '23 at 09:29
  • @Rob yep, I tried that first. Didn't work (same error) – Dhruv Erry Jun 19 '23 at 10:08
  • Using the same command (pip/pip3) for both RUN instructions would still be my best guess, for example `RUN pip install -r requirements.txt` and `RUN pip install django-widget-tweaks` or `RUN pip3 install -r requirements.txt` and `RUN pip3 install django-widget-tweaks` – Rob Jun 19 '23 at 10:50

0 Answers0