将Django部署到AWS时出现问题

问题描述:

我正在尝试使用弹性beantalk将我的个人网站部署到aws.我的网站在django/python中. 我一直遇到同样的问题.每次上传文件时,我都会在AWS控制台中收到以下错误:

I'm trying to deploy my personal website to aws using elastic beanstalk. My website is in django/python. I keep encountering the same issue. Each time I upload the files I get the following error in AWS console:

Your requirements.txt is invalid. Snapshot your logs for details.

好,所以我检查了日志,并从各个位中注意到了以下内容:

Ok, so I check the logs and from the bits I notice the following:

Error installing dependencies: Command '/opt/python/run/venv/bin/pip install -r /opt/python/ondeck/app/requirements.txt' returned non-zero exit status 2Traceback (most recent call last):
File "/opt/elasticbeanstalk/hooks/appdeploy/pre/03deploy.py", line 22, in main
  install_dependencies()

pip version 7.1.2, however version 9.0.1 is available.You should consider upgrading via the 'pip install --upgrade pip' command.

我在Google上搜索了很多东西,发现了这个问题.他们建议手动更新点并安装依赖项.因此,我登录到服务器并通过更新pip开始.繁荣,另一个问题.更新到pip 9.0.1后,当我输入pip --version时,我得到以下信息:

I googled and found many having this issue. They suggested updating pip and installing dependencies manually. So I logged into the server and started by updating pip. Boom, another issue. After updating to pip 9.0.1 when I type pip --version I get the following:

-bash: /usr/bin/pip: no such file or directory

我似乎无法继续.我以为弹性豆茎本来应该很容易,但是我一直在做越来越多的事情. 经过今天的所有测试,我无所适从.我可以要求任何帮助吗?接下来我该怎么办? 我想AWS不会为这样的事情提供支持,是吗? 谢谢.

I can't seem to move on with this. I thought elastic beanstalk is supposed to be easy but I keep getting more and more stuff to do. I'm at my wits end after all the testing today. Could I ask for any help with this? What should I do next? I suppose AWS don't provide support for stuff like that, do they? Thanks.

编辑.我正在使用python 3.6和Django 1.11.4.

Edit. I am using python 3.6 and django 1.11.4.

添加了requirements.txt和01_packages.config和django.config

Edit 2: Added requirements.txt and 01_packages.config and django.config

这是requirements.txt:

Here's the requirements.txt:

altgraph==0.14
argon2-cffi==16.3.0
awsebcli==3.12.0
botocore==1.7.36
cement==2.8.2
cffi==1.10.0
colorama==0.3.7
cx-Freeze==5.0.2
Django==1.11.4
django-bootstrap3==9.0.0
django-braces==1.11.0
dnspython==1.15.0
docker-py==1.7.2
dockerpty==0.4.1
docopt==0.6.2
docutils==0.14
et-xmlfile==1.0.1
future==0.16.0
idna==2.6
jdcal==1.3
jmespath==0.9.3
macholib==1.8
olefile==0.44
pathspec==0.5.0
pefile==2017.9.3
Pillow==4.2.1
python-dateutil==2.6.1
pytz==2017.2
PyYAML==3.12
requests==2.9.1
semantic-version==2.5.0
six==1.10.0
tabulate==0.7.5
termcolor==1.1.0
untangle==1.1.1
virtualenv==15.1.0
websocket-client==0.44.0

这是01_packages.config文件:

Here's 01_packages.config file:

packages:
  yum:
    altgraph: []
    argon2-cffi: []
    awsebcli: []
    botocore: []
    cement: []
    cffi: []
    colorama: []
    Django: []
    django-bootstrap3: []
    django-braces: []
    dnspython: []
    dockerpty: []
    docopt: []
    future: []
    idna: []
    macholib: []
    pathspec: []
    Pillow: []
    python-dateutil: []
    PyYAML: []
    untangle: []

这是django.config:

And here's django.config:

option_settings:
 "aws:elasticbeanstalk:container:python":
   WSGIPath: "davidbiendotcom/wsgi.py"

要检查的两件事.

首先,在运行pip之前,您需要输入以下内容进入正确的虚拟环境:

Firstly, before running pip you need to get in the right virtual environment by typing:

source /opt/python/run/venv/bin/activate
source /opt/python/current/env

其次,请检查您是否正在运行ebextensions文件右侧部分中的命令.如果您在此处看到说明,我以前遇到的问题中的不同命令部分.如果您需要升级点子,则需要在container_commands部分中完成.

Secondly, please check that you are running the commands in the right section of your ebextensions file. If you look here you can see an explanation of the different command sections in a problem I previously had. If you need to upgrade pip it needs to be done in the container_commands section.

在上方查看您的附件,我认为您正尝试使用yum进行过多的安装.

Reviewing your attachments above I think you are trying to install too much using yum.

我建议像这样的django配置:

I would suggest a django config like this:

option_settings:
packages:
 yum:
  mysql-devel: []
  gcc: []
  make: []
  gcc-c++: []
  libjpeg-turbo-devel: []
  python26-devel: []
  postgresql94-devel: []
  libcurl-devel: []

container_commands:
  01_collectstatic:
      command: "django-admin.py generate_favicon static/img/email_logo.png"
      command: "find /opt/python/current/app/static -mmin -1440 | xargs touch"
      command: "django-admin.py collectstatic --noinput --clear"

  03_migrate:
    command: "django-admin.py migrate --noinput"
    leader_only: true

  04_wsgipass:
    command: 'echo "WSGIPassAuthorization On" >> ../wsgi.conf'

其他软件包应使用pip自动安装.

And the other packages should install automatically using pip.

如果pip版本仍然存在问题,则可能需要使用requirements.txt安装其他软件包,然后升级pip并使用其他容器命令安装最终软件包.

If you still have a problem with the pip version then you might need to install your other packages using requirements.txt then upgrade pip and install your final package using an additional container command.

如果您仍在挣扎,请发布您的ebextensions文件和您的requirements.txt

If you're still struggling please post your ebextensions file and your requirements.txt