There's this Python package called aiopg for working with the PostgreSQL database asynchronously. It has two dependencies - async-timeout and psycopg2-binary. I don't want it to install psycopg2-binary when using pip because I use the regular psycopg2 package. This is because the authors of psycopg2-binary do not recommend using it in production.

This all does not create any problems working locally because I can add the desired dependency of aiopg to requirements.txt leaving out the undesired one, and then run two separate commands:

  1. pip install -r requirements.txt
  2. pip install aiopg --no-deps

But when I push my project to Elastic Beanstalk it uses requirements.txt to install Python packages and I don't know how to run the additional pip command.

I tried adding pip3 install aiopg --no-deps and also different variations of this command to eb.config (both to commands and container_commands sections) but to no avail.

Right now my eb.config looks like so:

packages:
    yum:
        amazon-linux-extras: []

commands:
    01_postgres_activate:
        command: sudo amazon-linux-extras enable postgresql11
    02_postgres_install:
        command: sudo yum install -y postgresql-devel

container_commands:
    01_aiopg_install:
        command: python3 -m pip install aiopg==1.2.1 --no-deps

But this is not woking. The Beanstalk environment is in Severe state and my web.stdout.log still contains this error: web: ModuleNotFoundError: No module named 'aiopg'.

So how do I implement this additional pip command with --no-deps flag which is not supported inside requirements.txt files yet?

1

There are 1 best solutions below

0
On BEST ANSWER

I had spent a whole day trying to solve this problem before posting this question. But some time after posting this I googled for some more time, tried a couple other approaches and found a working solution.

I changed the last line in my eb.config file shown in the question into command: /var/app/venv/.../bin/python -m pip install aiopg==1.2.1 --no-deps where ... should be replaced by the name of the directory sitting inside /var/app/venv/ in your Beanstalk's EC2 instance. ssh into one of your instances to find this directory or search for pip command in your eb-engine.log if you set up exporting logs into CloudWatch (you'll see the full path to your pip's env there).