【问题标题】:Trouble installing lxml to Elastic Beanstalk将 lxml 安装到 Elastic Beanstalk 时遇到问题
【发布时间】:2017-03-11 18:01:37
【问题描述】:

很难将 Python requirements.txt 安装到 Elastic Beanstalk 上的 PHP 应用程序。

最初我曾质疑Deploy multiple platforms to Elastic Beanstalk (PHP/Python) 的能力。虽然这不可能开箱即用,但可以运行 pre-install commands via .ebextentions

这导致创建 .ebextentions/install_python_requirements.config

container_commands:
  python_req:
    command: 'pip install -r /var/app/ondeck/requirements.txt'

问题在于,现在lxml 是需求中的一个依赖项,在部署过程中始终失败。奇怪的是,ssh 直接进入 EC2 实例,然后运行 ​​pip install -r requirements.txt 完成没有问题。

为什么依赖项安装通过直接ssh 访问成功,但在部署期间使用eb deployinstall_python_requirements.config 失败?

/var/log/eb-activity.log 中的失败

  creating build/temp.linux-x86_64-2.7/src/lxml
  gcc -pthread -fno-strict-aliasing -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector --param=ssp-buffer-size=4 -m64 -mtune=generic -D_GNU_SOURCE -fPIC -fwrapv -DNDEBUG -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector --param=ssp-buffer-size=4 -m64 -mtune=generic -D_GNU_SOURCE -fPIC -fwrapv -fPIC -I/usr/include/libxml2 -I/tmp/pip-build-A6NhcA/lxml/src/lxml/includes -I/usr/include/python2.7 -c src/lxml/lxml.etree.c -o build/temp.linux-x86_64-2.7/src/lxml/lxml.etree.o -w
  gcc: error trying to exec 'cc1': execvp: No such file or directory
  error: command 'gcc' failed with exit status 1

  ----------------------------------------
  Command "/usr/bin/python2.7 -c "import setuptools, tokenize;__file__='/tmp/pip-build-A6NhcA/lxml/setup.py';exec(compile(getattr(tokenize, 'open', open)(__file__).read().replace('\r\n', '\n'), __file__, 'exec'))" install --record /tmp/pip-gSsRbZ-record/install-record.txt --single-version-externally-managed --compile" failed with error code 1 in /tmp/pip-build-A6NhcA/lxml
   (ElasticBeanstalk::ExternalInvocationError)

【问题讨论】:

    标签: amazon-web-services amazon-ec2 amazon-elastic-beanstalk ebcli


    【解决方案1】:

    事实证明,问题最终出在系统 $PATH 上。在eb deploy 期间,系统路径似乎未设置。 pip install 能够开始,因为系统 PATH 可用于部署过程。但是,该系统 PATH 变量不会传递到 pip 进程中。因此,当尝试对 pip 进行后续调用时,它们会因为找不到应用程序路径而失败。正如通过向 install_python_requirements.config

    添加日志所证明的那样
    whome:      
      command: 'whoami'     
    env:        
      command: '/bin/sh -c env'
    

    然后检查 /var/log/eb-activity.log 以获取上述日志命令的输出,并注意到缺少 $PATH

    解决方案是通过另一个 .ebextentions/var.config 手动设置 PATH

     option_settings:
       - option_name: PATH
         value: '/usr/local/sbin:/sbin:/bin:/usr/sbin:/usr/bin:/opt/aws/bin:/root/bin'
    

    这允许 requirements.txteb deploy 过程中成功完成

    【讨论】:

    • 嘿维尼!你还有同样的问题吗?我现在面临一个问题,即 lxml 没有安装并且在 stock python pip install requirements 上出现 gcc 错误而失败
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-08-19
    • 2016-09-16
    • 2015-06-28
    • 1970-01-01
    • 2014-09-11
    • 2013-12-24
    相关资源
    最近更新 更多