Elastic Beanstalk 导入错误

问题描述 投票:0回答:1

django 找不到模块错误 导入错误

错误日志

2023-12-24 12:02:34,096 P2120 [INFO] Command 01_collectstatic
2023-12-24 12:02:34,133 P2120 [INFO] -----------------------Command Output-----------------------
2023-12-24 12:02:34,133 P2120 [INFO]    Traceback (most recent call last):
2023-12-24 12:02:34,133 P2120 [INFO]      File "/var/app/staging/manage.py", line 11, in main
2023-12-24 12:02:34,133 P2120 [INFO]        from django.core.management import execute_from_command_line
2023-12-24 12:02:34,133 P2120 [INFO]    ModuleNotFoundError: No module named 'django'
2023-12-24 12:02:34,133 P2120 [INFO]    
2023-12-24 12:02:34,133 P2120 [INFO]    The above exception was the direct cause of the following exception:
2023-12-24 12:02:34,133 P2120 [INFO]    
2023-12-24 12:02:34,133 P2120 [INFO]    Traceback (most recent call last):
2023-12-24 12:02:34,133 P2120 [INFO]      File "/var/app/staging/manage.py", line 22, in <module>
2023-12-24 12:02:34,133 P2120 [INFO]        main()
2023-12-24 12:02:34,133 P2120 [INFO]      File "/var/app/staging/manage.py", line 13, in main
2023-12-24 12:02:34,134 P2120 [INFO]        raise ImportError(
2023-12-24 12:02:34,134 P2120 [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?
2023-12-24 12:02:34,134 P2120 [INFO] ------------------------------------------------------------
2023-12-24 12:02:34,134 P2120 [ERROR] Exited with error code 1

但是,安装成功 记录 eb 引擎

Successfully built django-allauth
Installing collected packages: webencodings, urllib3, sqlparse, soupsieve, six, python-ipware, pyjwt, pycparser, psycopg2-binary, Pillow, oauthlib, idna, django-widget-tweaks, django-environ, defusedxml, charset-normalizer, certifi, asgiref, requests, python3-openid, django-ipware, Django, cffi, bleach, beautifulsoup4, requests-oauthlib, django-ckeditor-5, cryptography, django-allauth

Successfully installed Django-4.2.4 Pillow-10.1.0 asgiref-3.7.2 beautifulsoup4-4.12.2 bleach-5.0.1 certifi-2023.11.17 cffi-1.16.0 charset-normalizer-3.3.2 cryptography-41.0.7 defusedxml-0.7.1 django-allauth-0.55.2 django-ckeditor-5-0.2.10 django-environ-0.11.2 django-ipware-6.0.0 django-widget-tweaks-1.5.0 idna-3.6 oauthlib-3.2.2 psycopg2-binary-2.9.9 pycparser-2.21 pyjwt-2.8.0 python-ipware-2.0.1 python3-openid-3.2.0 requests-2.31.0 requests-oauthlib-1.3.1 six-1.16.0 soupsieve-2.5 sqlparse-0.4.4 urllib3-2.1.0 webencodings-0.5.1

为什么?

我通过教程找到了

    PYTHONPATH: "/var/app/current:$PYTHONPATH"

但是,错误。

eb ssh

echo $PYTHONPATH
no output

目录结构

root => var
var]$ cd app
[ec2-user@ip-app]$ cd venv/
[ec2-user@ip- venv]$ cd staging-LQM1lest/
[ec2-user@ip- staging-LQM1lest]$ ls
bin  include  lib  lib64  pyvenv.cfg
[ec2-user@ip- staging-LQM1lest]$ cd lib
[ec2-user@ip- lib]$ ls
python3.11
[ec2-user@ip- lib]$ cd python3.11/
[ec2-user@ip- python3.11]$ ls
site-packages
[ec2-user@ip- python3.11]$ cd site-packages/

其他

    PYTHONPATH: "/var/app/venv/staging-LQM1lest/"

错误

echo $PYTHONPATH
no output

我该怎么办?

附注 我的配置文件:

option_settings:
  aws:elasticbeanstalk:container:python:
    WSGIPath: my-project.wsgi:application
  aws:elasticbeanstalk:application:environment:
    PYTHONPATH: "xxx"

  aws:elb:listener:443:
    SSLCertificateId: arn:aws:acm:xxxxxxx
    ListenerProtocol: HTTPS
    InstancePort: 80

container_commands:
  01_collectstatic:
    command: 'python3 manage.py collectstatic --noinput'

看起来你的帖子主要是代码;请添加更多详细信息。 看起来你的帖子主要是代码;请添加更多详细信息。 看起来你的帖子主要是代码;请添加更多详细信息。

python amazon-elastic-beanstalk
1个回答
0
投票
container_commands:
  01_collectstatic:
    command: "source /var/app/venv/*/bin/activate && python3 manage.py collectstatic --noinput"

成功了!

具体情况我不清楚。但我知道该命令是在虚拟环境激活之前执行的。

© www.soinside.com 2019 - 2024. All rights reserved.