Skip to main content
 首页 » 编程设计

python之AWS Elastic Beanstalk 无法使用 requirements.txt Git Pip 安装 Python 包

2025年01月19日30del

我尝试使用 eb deploy 在 AWS Elastic Beanstalk 上部署 Flask 应用程序但失败了。

我在app目录下有requirements.txt:

Flask==0.12.2 
numpy==1.13.3 
pandas==0.21.1 
requests==2.18.4 
scipy==1.0.0 
Werkzeug==0.12.2 
-e git+http://github.com/hensing/PyDDE#egg=PyDDE 

和.ebextensions目录下的python.config文件:

packages: 
  yum: 
    git: [] 
    gcc-c++: [] 
    make: [] 

错误信息是:

INFO: Environment update is starting.

INFO: Deploying new version to instance(s).

ERROR: Your requirements.txt is invalid. Snapshot your logs for details.

ERROR: [Instance: i-03e92fa3c58b6e010] Command failed on instance. Return code: 1 Output: (TRUNCATED)... )

File "/usr/lib64/python2.7/subprocess.py", line 541, in check_call

raise CalledProcessError(retcode, cmd)

CalledProcessError: Command '/opt/python/run/venv/bin/pip install -r /opt/python/ondeck/app/requirements .txt' returned non-zero exit status 2.

Hook /opt/elasticbeanstalk/hooks/appdeploy/pre/03deploy.py failed. For more detail, check /var/log/eb-ac tivity.log using console or EB CLI.

INFO: Command execution completed on all instances. Summary: [Successful: 0, Failed: 1].

ERROR: Unsuccessful command execution on instance id(s) 'i-03e92fa3c58b6e010'. Aborting the operation.

ERROR: Failed to deploy application.

/var/log/eb-activity.log 显示:

2018-01-19 04:26:53,878 ERROR Error installing dependencies: Command '/opt/python/run/venv/bin/pip install -r /opt/python/ondeck/app/requirements.txt' returned non-zero exit status 2

Traceback (most recent call last):

File "/opt/elasticbeanstalk/hooks/appdeploy/pre/03deploy.py", line 22, in main

install_dependencies()

File "/opt/elasticbeanstalk/hooks/appdeploy/pre/03deploy.py", line 18, in install_dependencies

check_call('%s install -r %s' % (os.path.join(APP_VIRTUAL_ENV, 'bin', 'pip'), requirements_file), shell=True)

File "/usr/lib64/python2.7/subprocess.py", line 541, in check_call

raise CalledProcessError(retcode, cmd)

CalledProcessError: Command '/opt/python/run/venv/bin/pip install -r /opt/python/ondeck/app/requiremen ts.txt' returned non-zero exit status 2 (Executor::NonZeroExitStatus)

看来这个问题是因为 AWS Elastic Beanstalk 不支持 -e git+ 安装?

请您参考如下方法:

问题已经解决。

这不是因为安装了 PyDDE。

实际原因是安装 Scipy 需要 > 40MB 的内存,而默认的 EC2 实例 t1.micro 没有足够的内存来安装它。它可以通过使用更大的 EC2 实例来解决。我最终选择了 t2.medium。

此外,要安装 Pandas,它需要 gcc。我修改了 .ebextensions\[env_name].config 文件:(我使用的是 python 2.7,来自:elasticbeanstalk gcc and python-devel installation)

packages: 
  yum: 
    git: [] 
    gcc-c++: [] 
    python27-devel: []