首页 > 解决方案 > 未安装依赖项 Elastic Beansalk + Django

问题描述

我目前正在 64 位 Amazon Linux 2 上运行 Django 3.1.2 和 Python 3.7

从弹性豆茎日志中它告诉我没有django模块。

2021-04-08 05:09:30,592 P3788 [INFO] ============================================================
2021-04-08 05:09:30,593 P3788 [INFO] Test for Command 01_migrate
2021-04-08 05:09:30,596 P3788 [INFO] Completed successfully.
2021-04-08 05:09:30,596 P3788 [INFO] ============================================================
2021-04-08 05:09:30,596 P3788 [INFO] Command 01_migrate
2021-04-08 05:09:30,622 P3788 [INFO] -----------------------Command Output-----------------------
2021-04-08 05:09:30,623 P3788 [INFO]    Traceback (most recent call last):
2021-04-08 05:09:30,623 P3788 [INFO]      File "manage.py", line 11, in main
2021-04-08 05:09:30,623 P3788 [INFO]        from django.core.management import execute_from_command_line
2021-04-08 05:09:30,623 P3788 [INFO]    ModuleNotFoundError: No module named 'django'
2021-04-08 05:09:30,623 P3788 [INFO]    
2021-04-08 05:09:30,623 P3788 [INFO]    The above exception was the direct cause of the following exception:
2021-04-08 05:09:30,623 P3788 [INFO]    
2021-04-08 05:09:30,623 P3788 [INFO]    Traceback (most recent call last):
2021-04-08 05:09:30,623 P3788 [INFO]      File "manage.py", line 22, in <module>
2021-04-08 05:09:30,623 P3788 [INFO]        main()
2021-04-08 05:09:30,623 P3788 [INFO]      File "manage.py", line 17, in main
2021-04-08 05:09:30,623 P3788 [INFO]        ) from exc
2021-04-08 05:09:30,623 P3788 [INFO]    ImportError: Couldn't import Django. Are you sure it's installed and available on your PYTHONPATH environment variable? Did you forget to activate a virtual environment?
2021-04-08 05:09:30,623 P3788 [INFO] ------------------------------------------------------------

我的文件.ebextensions夹中有 2 个文件:

01-python.config

option_settings:
    "aws:elasticbeanstalk:application:environment":
        DJANGO_SETTINGS_MODULE: "Project.settings"
        "PYTHONPATH": "/var/app/current:$PYTHONPATH"
    "aws:elasticbeanstalk:container:python":
        WSGIPath: Project.wsgi:application
        NumProcesses: 3
        NumThreads: 20
    "aws:elasticbeanstalk:environment:proxy:staticfiles":
        /static: static

02-django.config

container_commands:
    01_migrate:
        command: "source /var/app/venv/*/bin/activate && python3 manage.py migrate"
        leader_only: true
    02_collectstatic:
        command: "source /var/app/venv/*/bin/activate && python3 manage.py collectstatic --noinput"
    03_createsu:
        command: "source /var/app/venv/*/bin/activate && python3 manage.py createsu"
        leader_only: true
    04_importdata:
        command: "source /var/app/venv/*/bin/activate && python3 manage.py importdata"
        leader_only: true

.ebextensions这是我位于根级别的 requirements.txt 文件(与文件夹相同的级别.elasticbeanstalk

asgiref==3.2.10
awsebcli==3.19.1
botocore==1.17.63
Django==3.1.2
djangorestframework==3.12.1
gunicorn==20.0.4

标签: pythondjangoamazon-web-servicespipamazon-elastic-beanstalk

解决方案


推荐阅读