如何在AWS Elastic Beanstalk或Google App Engine上使用没有pip安装的Python库?

时间:2017-12-25 22:48:23

标签: python amazon-web-services google-app-engine pip elastic-beanstalk

我有一个使用Python库PyDDE的Flask Web服务,它是在PyPI上发布的,但不知何故不能安装pip。我可以使用pip install git+https://github.com/hensing/PyDDE.git在我的本地环境中安装此库,或者克隆并安装setup.py

但是当我尝试在AWS Elastic Beanstalk或Google App Engine灵活环境上上传和构建项目时,这就成了他们无法找到此库的匹配分布的问题。

是否有解决此问题的解决方法?

以下是来自GAE Flexible的错误消息:

Step #1:   Could not find a version that satisfies the requirement PyDDE (from -r requirements.txt (li
ne 7)) (from versions: )
Step #1: No matching distribution found for PyDDE (from -r requirements.txt (line 7))
Step #1: The command '/bin/sh -c pip install -r requirements.txt' returned a non-zero code: 1
Finished Step #1
ERROR
ERROR: build step "gcr.io/cloud-builders/docker@sha256:331786b295647a4560ed004a46761ee91409e754df7ffa7
54a67000bd020729a" failed: exit status 1
Step #1:
------------------------------------------------------------------------------------------------------

ERROR: (gcloud.app.deploy) Cloud build failed. Check logs at https://console.cloud.google.com/gcr/buil
ds/6ace1019-8bf5-434b-b916-5c6cae84de9f?project=project-190120 Failure status: UNKNOWN: Err
or Response: [2] Build failed; check build logs for details

这是我的requirements.txt

Flask==0.12.2
Werkzeug==0.12.2
gunicorn==19.7.1
pandas>0.20.0
numpy>1.13.0
scipy>0.19.0
PyDDE
google-api-python-client

更新

我在requirements.txt中添加了这一行:

-e git+git://github.com/hensing/PyDDE.git#egg=PyDDE

它适用于GAE。

谢谢@hansaplast !!

但是,AWS Elastic Beanstalk不接受此requirements.txt。它抛出了这个错误:

INFO: Created CloudWatch alarm named: awseb-e-3tu2ajdxug-stack-AWSEBCloudwatchAlarmLow-8NOPISSRAAEH
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-activity.log using console or EB CLI.
INFO: Command execution completed on all instances. Summary: [Successful: 0, Failed: 1].
ERROR: Create environment operation is complete, but with errors. For more information, see troubleshooting documentation.

3 个答案:

答案 0 :(得分:1)

  • 在项目文件夹中创建一个文件夹,例如lib
  • 使用pip install -t <dir>
  • 将您想要的库安装到该文件夹​​中
  • 在与appengine_config.py文件相同的文件夹中创建名为app.yaml的文件,并按如下方式进行编辑:

    from google.appengine.ext import vendor 
    vendor.add('lib') # Folder name
    
  • 部署

答案 1 :(得分:1)

而不是PyDDE,请将其添加到requirements.txt

-e git://https://github.com/hensing/PyDDE.git#egg=PyDDE
  

AWS Elastic Beanstalk不接受此要求.txt

您似乎已将git+git://github.com/hensing/PyDDE.git#egg=PyDDE放入您的requirements.txt中。从文件中删除git+#egg=PyDDE(如上所示)然后它应该可以正常工作。

答案 2 :(得分:1)

我能够通过以下方式解决类似的问题:

创建一个配置文件来安装git,因为它没有预先安装在EB上:

  • 路径:root / .ebextensions
  • 文件:conf.config(名称无关紧要,扩展名需要配置)

将以下内容添加到conf.config文件中:

packages:
  yum:
    git: []

将以下内容添加到您的requirements.txt:

-e git://github.com/hensing/PyDDE.git#egg=PyDDE

重新运行eb deploy

链接: - https://docs.aws.amazon.com/elasticbeanstalk/latest/dg/environment-configuration-methods-during.html#configuration-options-during-ebcli-ebextensions