简体   繁体   中英

AWS Elastic Beanstalk Python (3.8) platform: run additional pip command for a Python package with `--no-deps` flag aside from using `requirements.txt`

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?

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).

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