Can I update Amazon's old versions of pip and setuptools?

不羁的心 提交于 2020-07-17 05:39:15

问题


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?


回答1:


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:

  • Create a .ebextensions/upgrade_pip.config file.
  • Insert the command to execute.

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.




回答2:


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


来源:https://stackoverflow.com/questions/28369235/can-i-update-amazons-old-versions-of-pip-and-setuptools

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!