Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Could not find a version that satisfies the requirement psycopg2

Tags:

gitlab-ci

I'm working on CI for my Python + Django project. I have to use the python:3.9-alpine image. A weird error is popping in my CI pipelines:

WARNING: Discarding https://files.pythonhosted.org/packages/aa/8a/7c80e7e44fb1b4277e89bd9ca509aefdd4dd1b2c547c6f293afe9f7ffd04/psycopg2-2.9.1.tar.gz#sha256=de5303a6f1d0a7a34b9d40e4d3bef684ccc44a49bbe3eb85e3c0bffb4a131b7c (from https://pypi.org/simple/psycopg2/) (requires-python:>=3.6). Command errored out with exit status 1: python setup.py egg_info Check the logs for full command output.
ERROR: Could not find a version that satisfies the requirement psycopg2==2.9.1 (from versions: 2.0.10, 2.0.11, 2.0.12, 2.0.13, 2.0.14, 2.2.0, 2.2.1, 2.2.2, 2.3.0, 2.3.1, 2.3.2, 2.4, 2.4.1, 2.4.2, 2.4.3, 2.4.4, 2.4.5, 2.4.6, 2.5, 2.5.1, 2.5.2, 2.5.3, 2.5.4, 2.5.5, 2.6, 2.6.1, 2.6.2, 2.7, 2.7.1, 2.7.2, 2.7.3, 2.7.3.1, 2.7.3.2, 2.7.4, 2.7.5, 2.7.6, 2.7.6.1, 2.7.7, 2.8, 2.8.1, 2.8.2, 2.8.3, 2.8.4, 2.8.5, 2.8.6, 2.9, 2.9.1, 2.9.2)
  Preparing metadata (setup.py): finished with status 'error'
ERROR: No matching distribution found for psycopg2==2.9.1

I see 2.9.1 in list of avaliable versions

My .gitlab-ci.yml

stages:
  - linter
  - build_pip
  - build
  - meta
  - code_quality
  - deploy

.except-tags:
  except:
    - tags

build_pip:build_dist:
  stage: build_pip
  # image: $CI_DEPENDENCY_PROXY_GROUP_IMAGE_PREFIX/python:3.9-alpine
  image: python:3.9-alpine
  variables:
    OPENCV_VERSION: "4.5.3.56"
  before_script:
    - pip install --upgrade pip setuptools wheel
    - apk update apk add -q --update --no-cache
      - postgresql-dev musl-dev
      ...
    - pip install -r requirements/production.txt --no-cache
  script:
    - python setup.py bdist_wheel
    - echo PIP_CI_JOB_ID=$CI_JOB_ID > PIP_CI_JOB_ID.env
  dependencies: []
  artifacts:
    expire_in: 1 hour
    paths:
      - dist/
      - version
    reports:
      dotenv: PIP_CI_JOB_ID.env
  extends:
    - .except-tags
    ...

requirements/production.txt

djangorestframework==3.12.4
drf-extra-fields==3.1.1
djangorestframework-camel-case==1.2.0  # https://pypi.org/project/djangorestframework-camel-case/
Pillow==8.3.2
python-dateutil==2.8.2  # datetime formatting
psycopg2==2.9.1
opencv-python==4.5.3.56
drf-yasg==1.20.0
sentry-sdk==1.4.3
gunicorn==20.1.0
requests==2.26.0
yarl==1.7.0
googlemaps==4.5.3
django_redis==5.0.0
celery==5.2.0
channels==3.0.4
channels_redis==3.3.1

Full gitlab ci log: https://pastebin.com/QhMhErF7

What is the reason for this error?

I tried to replace psycopg2 with psycopg2-binary but the same error occours.

like image 962
Alex Avatar asked Sep 02 '25 06:09

Alex


1 Answers

What is the reason of my error?

Did you read my previous answer to a similar question of yours? The last part warns about certain combinations of Alpine + Python and this seems to be happening right now.

I tried to replace psycopg2 with psycopg2-binary but have the same error

The problem here might be a python library that has dependencies on gcc, which is not shipped on alpine by default.

Try replacing this:

  before_script:
    - pip install --upgrade pip setuptools wheel
    - apk update
    - apk add -q --update --no-cache postgresql-dev musl-dev

with:

  before_script:
    - pip install --upgrade pip setuptools wheel
    - apk update
    - apk add -q --no-cache postgresql-dev gcc python3-dev musl-dev

Notice that adding gcc will increase the image size, since this might be a dependency for either psycopg2 or psycopg2-binary. If the image size grows a lot I see no point in sticking with alpine, you could just avoid more Python headaches by switching to a debian-based image.

like image 123
Aristu Avatar answered Sep 05 '25 00:09

Aristu