I've added deploy commands to my Elastic Beanstalk deployment which download the Anaconda installer, and install it into /anaconda
. Everything goes well, but I cannot seem to correctly modify the PATH of my instance to include /anaconda/bin
as suggested by the Anaconda installation page. If I SSH into an instance and manually add it, everything works fine. But this is obviously not the correct approach, as machines will be added automatically by EB.
So my question is: how can I use Anaconda in my script?
A couple more details:
/anaconda/bin
to the system PATH all ways I can think of. Pre/post deploy scripts, custom environment variables, etc. It seems that no matter what I do, the modifications don't persist to when the application is run. sys.path.append('/anaconda/bin')
sys.path.append('/anaconda/lib/python2.7/site-packages')
allows me to import some packages but fails on import pandas
. Strangely enough, if I SSH into the instance and run the application with their python (/opt/python/run/venv/bin/python2.7
) it runs fine. Am I going crazy? Why does it fail on a specific import statement when run via EB?Found the answer: import pandas
was failing because matplotlib
was failing to initialize, because it was trying to get the current user's home directory. Since the application is run via WSGI, the HOME variable is set to /home/wsgi
but this directory doesn't exist. So, creating this directory via deployment command fixed this issue.
.ebextensions/options.config
contains:
commands:
00_download_conda:
command: 'wget http://repo.continuum.io/archive/Anaconda-2.0.1-Linux-x86_64.sh'
test: test ! -d /anaconda
01_install_conda:
command: 'bash Anaconda-2.0.1-Linux-x86_64.sh -b -f -p /anaconda'
test: test ! -d /anaconda
02_create_home:
command: 'mkdir -p /home/wsgi'
00_download_conda
simply downloads Anaconda. See here for latest Anaconda version download link. The test
commands are EB's way of letting you only execute the command if the test fails...Just prevents double downloading when in development.01_install_conda
installs Anaconda with options -b -f -p /anaconda
which allows it to be installed in the specified directory, without user input, and skips installation if it has already been installed.02_create_home
creates the missing directory.
And finally - to use Anaconda inside your python application: sys.path.append('/anaconda/lib/python2.7/site-packages')
Cheers!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With