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:
pip install -r requirements.txtpip 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?
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.configfile shown in the question intocommand: /var/app/venv/.../bin/python -m pip install aiopg==1.2.1 --no-depswhere...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 forpipcommand in youreb-engine.logif you set up exporting logs intoCloudWatch(you'll see the full path to yourpip's env there).