Can I update or remove the pip and setuptools provided with AWS Elastic Beanstalk?
The versions of pip and setuptools provided with my AWS Elastic Beanstalk Python environments (in the 2.7 virtual environment running my application, ami-d14608e1
; in /opt/python/run/venv/lib/python2.7/site-packages
) are very old: as reported by
pip list --outdated
they are
setuptools (Current: 2.2 Latest: 12.0.5)
pip (Current: 1.5.4 Latest: 6.0.7)
Can I update these (e.g. by listing them in my requirements.txt
) or are these specific versions expected by or needed for EB's Python and deployment processes to work?
Updating Pip When an update for pip is available, and you run a pip command, you will see a message that says, “You are using pip version xy. a, however version xy. b is available.” You can run “pip install --upgrade pip” to install and use the new version of pip.
New software releases can bring bug fixes, new features, and faster performance. For example, NumPy 1.20 added type annotations, and improved performance by using SIMD when possible. If you're installing NumPy, you might want to install the newest version.
Taking pip
as an example, the default AWS environment provides usually an old version. Currently it is a 6.1.1
on a machine I use, while pip
repeats at each call that 9.0.1
is available.
Dependencies sometimes require recent versions of pip
. One way to have it available is to rely on pip
itself, as the yum
sources provided by AWS are slower to upgrade (due to the sheer impact that would cause...).
Different AWS services have different solutions. The question is about Beanstalk. Assuming deployment based on eb
provided by AWS, it is possible to execute commands in the target container:
.ebextensions/upgrade_pip.config
file.To upgrade pip
, a command like this does the job:
commands:
pip_upgrade:
command: /opt/python/run/venv/bin/pip install --upgrade pip
ignoreErrors: false
Note that the file name for .ebextensions/upgrade_pip.config
defines the order of execution. If it needs to run earlier than any other script in .ebextensions
, a prefix like 01_upgrade...
is necessary.
Try adding an ebextension file that will upgrade pip before running
pip install -r requirements.txt
for example:
004_prehook.config
files:
"/opt/elasticbeanstalk/hooks/appdeploy/pre/02a_upgrade_pip.sh":
mode: "000755"
owner: root
group: root
content: |
#!/usr/bin/env bash
source /opt/python/run/venv/bin/activate
python3 -m pip install --upgrade pip
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With