如何在Amazon Linux 2 AMI上安装pythonocc-core?

发布时间:2020-07-06 09:37

我有一个Django应用程序,已将其部署到Elastic Beanstalk,Amazon Linux 2 AMI,并且我对AWS还是很陌生。我必须在应用程序中使用pythonocc-core软件包,但无法通过pip安装它。如果我通过SSH进入实例并手动安装,则由于EB环境的自动扩展,这不是一个好方法。我在下面添加了用于安装anaconda的.config文件,并且我的部署成功。

commands:
  00_download_conda:
    command: 'wget https://repo.anaconda.com/archive/Anaconda3-2020.02-Linux-x86_64.sh'
    test: test ! -d /anaconda
  01_install_conda:
    command: 'bash Anaconda3-2020.02-Linux-x86_64.sh -b -f -p /anaconda'
    test: test ! -d /anaconda
  02_create_home:
    command: 'mkdir -p /home/wsgi'

当我在此.config文件的延续中添加以下命令行时,部署失败。

commands:
  03_conda_create: 
    command: conda create --name=whatever-name python=3.7
  04_conda_activate: 
    command: source activate whatever-name
  05_conda_install: 
    command: conda install -c dlr-sc pythonocc-core=7.4.0

但是我遇到了如下错误。

Traceback (most recent call last):
  File "/opt/aws/bin/cfn-init", line 171, in <module>
    worklog.build(metadata, configSets)
  File "/usr/lib/python2.7/site-packages/cfnbootstrap/construction.py", line 129, in build
    Contractor(metadata).build(configSets, self)
  File "/usr/lib/python2.7/site-packages/cfnbootstrap/construction.py", line 530, in build
    self.run_config(config, worklog)
  File "/usr/lib/python2.7/site-packages/cfnbootstrap/construction.py", line 542, in run_config
    CloudFormationCarpenter(config, self._auth_config).build(worklog)
  File "/usr/lib/python2.7/site-packages/cfnbootstrap/construction.py", line 260, in build
    changes['commands'] = CommandTool().apply(self._config.commands)
  File "/usr/lib/python2.7/site-packages/cfnbootstrap/command_tool.py", line 117, in apply
    raise ToolError(u"Command %s failed" % name)
ToolError: Command 03_conda_create failed

如何解决此问题?

回答1

一个好的方法是在Commands文件夹中使用.ebextensions

例如,您可能有一个文件.ebextensions/10_install_pythonocc.config

commands:
  10_conda_create: 
    command: conda create --name=whatever-name python=3.7
  20_conda_activate: 
    command: source activate whatever-name
  30_conda_install: 
    command: conda install -c dlr-sc pythonocc-core=7.4.0

关于anaconda本身,here是可以尝试的说明。