简体   繁体   中英

Q: Python/Docker - No matching distribution found for Django==4.0.2 when running docker container

I have a project that I am trying to run named Veganettest inside of my visual studio code editor, however, when I run docker-compose up I receive an error that says ERROR: No matching distribution found for Django==4.0.2 even though such a distribution does indeed exist. I have tried various other solutions on here like installing the library using pip install Django pip could not find a version that satisfies the requirement django==2.2.1 , Tried to downgrade and upgrade the version of Django to different values ex. Django==3.1.3, Django==3.0, and Django==4.0 ERROR: Could not find a version that satisfies the requirement tensorflow (from versions: none) ERROR: No matching distribution found for tensorflow) but when I try those solutions they don't work. The error is coming from my requirements.txt file specifically from the first line that declares Django==4.0.2 as a requirement.

Here is the full error that I am getting along with a few warnings initially:

WARNING: Retrying (Retry(total=4, connect=None, read=None, redirect=None, status=None)) after connection broken by 'NewConnectionError('<pip._vendor.urllib3.connection.HTTPSConnection object at 0x000001B4E55BC430>: Failed to establish a new connection: [Errno 11002] getaddrinfo failed')': /simple/django/
WARNING: Retrying (Retry(total=3, connect=None, read=None, redirect=None, status=None)) after connection broken by 'NewConnectionError('<pip._vendor.urllib3.connection.HTTPSConnection object at 0x000001B4E55DE070>: Failed to establish a new connection: [Errno 11002] getaddrinfo failed')': /simple/django/
WARNING: Retrying (Retry(total=2, connect=None, read=None, redirect=None, status=None)) after connection broken by 'NewConnectionError('<pip._vendor.urllib3.connection.HTTPSConnection object at 0x000001B4E55DE220>: Failed to establish a new connection: [Errno 11002] getaddrinfo failed')': /simple/django/
WARNING: Retrying (Retry(total=1, connect=None, read=None, redirect=None, status=None)) after connection broken by 'NewConnectionError('<pip._vendor.urllib3.connection.HTTPSConnection object at 0x000001B4E55DE3D0>: Failed to establish a new connection: [Errno 11002] getaddrinfo failed')': /simple/django/
WARNING: Retrying (Retry(total=0, connect=None, read=None, redirect=None, status=None)) after connection broken by 'NewConnectionError('<pip._vendor.urllib3.connection.HTTPSConnection object at 0x000001B4E55DE580>: Failed to establish a new connection: [Errno 11002] getaddrinfo failed')': /simple/django/
ERROR: Could not find a version that satisfies the requirement Django==4.0.2 (from versions: none)
ERROR: No matching distribution found for Django==4.0.2

Here is my requirements.txt, Dockerfile, docker-compose.yml, and manage.py file respectively:

requirements.txt:

Django==4.0.2
djangorestframework==3.12.2
mysqlclient==2.0.1
django-mysql==3.9
django-cors-headers==3.5.0
pika==1.1.0
pillow==9.0.0
matplotlib==3.5.0

Dockerfile:

FROM python:3.9
ENV PYTHONUNBUFFERED 1
WORKDIR /app
COPY requirements.txt /app/requirements.txt
RUN pip install -r requirements.txt
COPY . /app

docker-compose.yml:

version: '3.9'
services:
  backend:
    build: 
      context: .
      dockerfile: Dockerfile
    command: 'python manage.py runserver 0.0.0.0:8000'
    ports:
      - 8000:8000
    volumes: 
      - .:/app
    depends_on:
      - db

  db:
    image: mysql:5.7.22
    restart: always
    environment:
      MYSQL_DATABASE: veganettest
      MYSQL_USER: foodiehutts
      MYSQL_PASSWORD: bobaboyheheh21342345><L
      MYSQL_ROOT_PASSWORD: root
    volumes:
      - .dbdata:/var/lib/mysql
    ports:
      - 33065:3306

manage.py:

import os
import sys


def main():
    """Run administrative tasks."""
    os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'veganettest.settings')
    try:
        from django.core.management import execute_from_command_line
    except ImportError as exc:
        raise ImportError(
            "Couldn't import Django. Are you sure it's installed and "
            "available on your PYTHONPATH environment variable? Did you "
            "forget to activate a virtual environment?"
        ) from exc
    execute_from_command_line(sys.argv)


if __name__ == '__main__':
    main()  

Why is this error happening? what can I do to fix it? thank you.

I had a similar issue and upgrading pip worked for me ( RUN pip install --upgrade pip && pip install -r requirements.txt ). I didn't have the "NewConnectionError", though.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM