3

如何让 aWS EB 实例使用实例上已安装的 python 3 版本?我无法使用运行 Django 2.1+ 的 Python 3.6 运行新环境。

本地(不在虚拟环境中):

which python -> /usr/local/bin/python
python -V -> Python 2.7.15
which python3 -> /usr/local/bin/python3
python3 -V -> Python 3.6.5
which pip -> /usr/local/bin/pip
pip -V -> pip 18.0 from /usr/local/lib/python3.6/site-packages/pip (python 3.6)`
which pip3 -> /usr/local/bin/pip3
pip3 -V -> pip 18.0 from /usr/local/lib/python3.6/site-packages/pip (python 3.6)

virtualenv 中的本地mstFirst

which python -> /Users/me/.virtualenvs/mstFirst/bin/python
which python3 -> /Users/me/.virtualenvs/mstFirst/bin/python
python -V -> Python 3.6.5
python3 -V -> Python 3.6.5
which pip -> /Users/me/.virtualenvs/mstFirst/bin/pip
which pip3 -> /Users/me/.virtualenvs/mstFirst/bin/pip3
pip -V -> pip 18.0 from /Users/me/.virtualenvs/mstFirst/lib/python3.6/site-packages/pip (python 3.6)
pip3 -V -> pip 18.0 from /Users/me/.virtualenvs/mstFirst/lib/python3.6/site-packages/pip (python 3.6)
aws --version -> aws-cli/1.16.9 Python/3.6.5 Darwin/17.7.0 botocore/1.11.9
eb --version -> EB CLI 3.14.4 (Python 3.6.5)
eb -list -> * mst-p3
eb -config ->
  ApplicationName: mst
  DateUpdated: 2018-09-07 02:15:51+00:00
  EnvironmentName: mst-p3
  PlatformArn: arn:aws:elasticbeanstalk:us-east-1::platform/Python 3.6 running on 64bit Amazon Linux/2.7.3
  settings: …

文件

“.elasticbeanstalk/config.yml”

branch-defaults:
  master:
    environment: mst-p3
environment-defaults:
  mst-p3: …
global:
  application_name: mst
  default_platform: 64bit Amazon Linux 2018.03 v2.7.3 running Python 3.6
  default_region: us-east-1
  workspace_type: Application
…

“.ebextensions/01_packages.config”

packages:
  yum:
    git: []
    python36: []
    python36-devel: []
    postgresql93: []
    postgresql93-devel: []
    mod24_ssl : []

commands:
  pip_upgrade:
    command: /opt/python/run/venv/bin/pip install --upgrade pip
    ignoreErrors: false

尝试时出错eb deploy,它在尝试运行时指向错误的 python 版本(2.7)pip install -r requirements.py

Command "python setup.py egg_info" failed with error code 1 in /tmp/pip-install-jt3_s4in/slugger/
2018-09-07 03:28:35,315 ERROR    Error installing dependencies: Command '/opt/python/run/venv/bin/pip install -r /opt/python/ondeck/app/requirements.txt' returned non-zero exit status 1
Traceback (most recent call last):
  File "/opt/elasticbeanstalk/hooks/appdeploy/pre/03deploy.py", line 22, in main
    install_dependencies()
  File "/opt/elasticbeanstalk/hooks/appdeploy/pre/03deploy.py", line 18, in install_dependencies
    check_call('%s install -r %s' % (os.path.join(APP_VIRTUAL_ENV, 'bin', 'pip'), requirements_file), shell=True)
  File "/usr/lib64/python2.7/subprocess.py", line 186, in check_call
    raise CalledProcessError(retcode, cmd)
CalledProcessError: Command '/opt/python/run/venv/bin/pip install -r /opt/python/ondeck/app/requirements.txt' returned non-zero exit status 1 (Executor::NonZeroExitStatus)

远程实例 ssh ( eb ssh)

pyhthon -V -> Python 2.7.14
pyhthon3 -V -> Python 3.6.5

我尝试过的事情:

4

3 回答 3

1

您的问题是由 Python 2.7 安装中的 pip (Python 3.x pip) 版本错误引起的。

AWS 工具是为 Python 2.7 编写的

我也不确定 aws cli 或 eb 是否已经用 pip 18 进行了完全测试。

从 Python 2 目录中卸载 pip。卸载 eb

重新安装。

我建议您先安装 AWS CLI,即使您不使用它。这将确保您的 Python 环境针对 AWS 工具设置正确。

您没有指定操作系统,因此我无法为您提供操作系统特定的卸载/安装说明。

于 2018-09-14T23:00:54.323 回答
0

尝试:

  • 备份和删除 .elasticbeanstalk/config.yml
  • 运行:eb init 然后您可以在 eb init 中选择 python 版本 3.6
于 2022-02-25T23:01:17.250 回答
0

使用eb init绝对有效:

eb init -p "64bit Amazon Linux 2017.09 v2.7.3 running Python 3.6" ...

.ebextension然后从你的文件中删除所有 python 的东西。

对于yum section,我使用的是:

packages:
  yum:
    postgresql94-devel: []

应该不需要升级 pip。

于 2018-09-08T22:34:04.517 回答