Installing Anaconda on Amazon Elastic Beanstalk to use in Django application

Viewed 533

I have a Django application which it's deployed to Amazon Elastic Beanstalk. I have to install anaconda for installing pythonocc-core package. I have created a .config file in .ebextensions folder and add the anaconda path in my wsgi.py file such as below and I have deployed it successfully.

.config file:

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'
  03_conda_activate_installation:
    command: 'source ~/.bashrc'

wsgi.py:

sys.path.append('/anaconda/lib/python3.7/site-packages')

However when I add the 04_conda_install_pythonocc command below to the continuation of this .config file, I got command failed error.

04_conda_install_pythonocc: 
command: 'conda install -c dlr-sc pythonocc-core=7.4.0'

I ssh into the instance for checking. I saw the /anaconda folder has occured. When I checked with the conda --version command, I got the -bash: conda: command not found error.

Afterwards, I thought there might be a problem with the PATH and I edited the .config file as follows and I have deployed this .config file successfully.

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'
  03_add_path:
    command: 'export PATH=$PATH:$HOME/anaconda/bin'
  04_conda_activate_installation:
    command: 'source ~/.bashrc'

But when I add the conda_install_pythonocc command again to the continuation of this edited version of .config file, it failed again and I got command failed.

In manually, all the commands work but they don't work in my .config file.

How can I fix this issue and install package with conda?

1 Answers

I tried to replicated the issue on my sandbox account, and I successful installed conda using the following (simplified) config file on 64bit Amazon Linux 2 v3.0.3 running Python 3.7:

.ebextensions/60_anaconda.config

commands:
  00_download_conda:
    command: 'wget https://repo.anaconda.com/archive/Anaconda3-2020.02-Linux-x86_64.sh'
  01_install_conda:
    command: 'bash Anaconda3-2020.02-Linux-x86_64.sh -b -f -p /anaconda'
  05_conda_install: 
    command: '/anaconda/bin/conda install -y -c dlr-sc pythonocc-core=7.4.0'   

Note the use off absolute path /anaconda/bin/conda and -y to not ask for manual confirmations. I only verified installation procedure, not how to use it afterwards (e.g. not how to use it in python application). Thus you will probably need to adjust it to your needs.

The EB log file showing successful installation is also provided for your reference (shortened for simplicity):

Related