在 Amazon Elastic Beanstalk 上安装 Anaconda [英] Installing Anaconda on Amazon Elastic Beanstalk

查看:20
本文介绍了在 Amazon Elastic Beanstalk 上安装 Anaconda的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已将部署命令添加到我的 Elastic Beanstalk 部署中,用于下载 Anaconda 安装程序,并将其安装到 /anaconda.一切顺利,但我似乎无法按照 Anaconda 安装页面的建议正确修改我的实例的 PATH 以包含 /anaconda/bin .如果我通过 SSH 连接到一个实例并手动添加它,则一切正常.但这显然不是正确的方法,因为 EB 会自动添加机器.

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.

所以我的问题是:如何在我的脚本中使用 Anaconda?

更多细节:

  • 我已经尝试以我能想到的所有方式将 /anaconda/bin 添加到系统路径中.部署前/后部署脚本、自定义环境变量等.似乎无论我做什么,修改都不会持续到应用程序运行时.
  • 我尝试通过将 Anaconda 添加到 sys.path 来包含它:sys.path.append('/anaconda/bin')
    无济于事.使用以下内容:sys.path.append('/anaconda/lib/python2.7/site-packages') 允许我导入一些包但在 import pandas 上失败.奇怪的是,如果我通过 SSH 连接到实例并使用他们的 python (/opt/python/run/venv/bin/python2.7) 运行应用程序,它运行良好.我要疯了吗?为什么在通过 EB 运行时在特定的导入语句上失败?
  • I've tried adding /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.
  • I've tried to include Anaconda via adding it to sys.path: sys.path.append('/anaconda/bin')
    to no avail. Using the following: 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?

推荐答案

找到答案:import pandas 失败,因为 matplotlib 未能初始化,因为它正在尝试获取当前用户的主目录.由于应用程序是通过 WSGI 运行的,所以 HOME 变量被设置为 /home/wsgi 但是这个目录不存在.因此,通过部署命令创建此目录解决了此问题.
<小时>我在 Elastic Beanstalk 上使用 Anaconda 的总体设置如下:
.ebextensions/options.config 包含:

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.


My overall setup to use Anaconda on Elastic Beanstalk is as follows:
.ebextensions/options.config contains:

命令:
  00_download_conda:
    命令:'wget http://repo.continuum.io/archive/Anaconda-2.0.1-Linux-x86_64.sh'
    测试:测试!-d/蟒蛇
  01_install_conda:
    命令:'bash Anaconda-2.0.1-Linux-x86_64.sh -b -f -p/anaconda'
    测试:测试!-d/蟒蛇
  02_create_home:
    命令:'mkdir -p/home/wsgi'

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 只是下载 Anaconda.请参阅此处以获取最新的 Anaconda 版本下载链接.test 命令是 EB 的一种方式,它让您仅在测试失败时才执行命令...只是在开发过程中防止重复下载.
01_install_conda 使用选项 -b -f -p/anaconda 安装 Anaconda,允许将其安装在指定目录中,无需用户输入,如果已经安装则跳过安装已安装.
02_create_home 创建丢失的目录.

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.

最后 - 在你的 python 应用程序中使用 Anaconda:sys.path.append('/anaconda/lib/python2.7/site-packages')
干杯!

And finally - to use Anaconda inside your python application: sys.path.append('/anaconda/lib/python2.7/site-packages')
Cheers!

这篇关于在 Amazon Elastic Beanstalk 上安装 Anaconda的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆