ImportError: No module named django.core.wsgi Apache + VirtualEnv + AWS + WSGI

后端 未结 10 824
予麋鹿
予麋鹿 2020-11-29 03:34

I am trying to publish my site on an Amazon\'s EC2 Instance, and I keep getting a 500 error. I really dunno why.

//Log Files

    [Sun Feb 17 23:12:48         


        
相关标签:
10条回答
  • 2020-11-29 03:40

    I had the same issue. My libapache2-mod-wsgi was python 2.x and not python 3.x

    found the solution here: https://stackoverflow.com/a/28118284/2489042

    credits to @nima

    $ sudo apt-get remove libapache2-mod-python libapache2-mod-wsgi
    $ sudo apt-get install libapache2-mod-wsgi-py3
    

    Warning from @alxs before you copy/paste these commands: If there are python 2 projects running on the server that use wsgi and apache, the above commands will effectively shut them down.

    0 讨论(0)
  • 2020-11-29 03:46

    In case someone came here using AWS Lightsail bitnami..

    The problem is that 'python install packages in a directory that apache do not see'.

    so: packages get installed in '/home/bitnami/.local/lib/python3.8/site-packages/' and Apache looks in '/opt/bitnami/python/lib/python3.8/site-packages/'.

    The temporary solution I followed is copying packages to Apache eyes folder with this command 'cp -r /home/bitnami/.local/lib/python3.8/site-packages/* /opt/bitnami/python/lib/python3.8/site-packages/'

    0 讨论(0)
  • 2020-11-29 03:48

    I had a similar error just now. It turns out that our Django code was developed on python 3.5, but for some reasons the people who deployed our server setup virtualEnv with python 2.7. We redeployed with python 3.5 and everything worked for us

    Below was the error message I received:

    $ python serviceStartup.py 
    Traceback (most recent call last):
      File "serviceStartup.py", line 10, in <module>
        from django.core.wsgi import get_wsgi_application
    ImportError: No module named django.core.wsgi
    

    Hope this will help with anyone seeing a similar error message!

    0 讨论(0)
  • 2020-11-29 03:48

    At first glance, I am sorry for my English. I also faced this issue, and I have solved it by changing 'wsgi.py' file to:

    import os
    import django
    from django.core.handlers.wsgi import WSGIHandler
    
    
    os.environ.setdefault("DJANGO_SETTINGS_MODULE", "eisentask.settings.production")
    django.setup(set_prefix=False)
    
    application = WSGIHandler()
    
    0 讨论(0)
  • 2020-11-29 03:53

    Add this to the Apache configuration file:

    WSGIPythonHome /home/ec2-user/.virtualenvs/mysite-main
    
    0 讨论(0)
  • 2020-11-29 03:59

    I am using Centos and the nginx and gunicorn for my project... I had this problem... wsgi file is not reachable maybe it's bcz of the your current directory I changed my current directory and It worked... my project name is coda so I typed

    cd coda
    

    and then

    gunicorn --bind  0.0.0.0:8001 coda.wsgi
    
    0 讨论(0)
提交回复
热议问题