ModuleNotFoundError: No module named 'django' while deploying to ElasticBeanstalk - python

Tried multiple solutions online but couldnt get it working !
Basically my application is deployed but http response is "Internal Server Error".
On investigating EB logs i found the following traceback.
[Sat Jun 08 10:28:56.880823 2019] [:error] [pid 4776] [remote 172.31.4.251:180] Traceback (most recent call last):
[Sat Jun 08 10:28:56.880846 2019] [:error] [pid 4776] [remote 172.31.4.251:180] File "/opt/python/current/app/modelforms/modelforms/wsgi.py", line 12, in <module>
[Sat Jun 08 10:28:56.880863 2019] [:error] [pid 4776] [remote 172.31.4.251:180] from django.core.wsgi import get_wsgi_application
[Sat Jun 08 10:28:56.880878 2019] [:error] [pid 4776] [remote 172.31.4.251:180] ModuleNotFoundError: No module named 'django'
[Sat Jun 08 10:29:10.828039 2019] [:error] [pid 4776] [remote 172.31.42.54:180] mod_wsgi (pid=4776): Target WSGI script '/opt/python/current/app/modelforms/modelforms/wsgi.py' cannot be loaded as Python module.
[Sat Jun 08 10:29:10.828089 2019] [:error] [pid 4776] [remote 172.31.42.54:180] mod_wsgi (pid=4776): Exception occurred processing WSGI script '/opt/python/current/app/modelforms/modelforms/wsgi.py'.
My requirements.txt is placed in all directories and yet django module is not recognised. It seems it hasn't been installed at first place.
The file's contents are:
Django==2.2.1
Pillow==6.0.0
pytz==2019.1
sorl-thumbnail==12.5.0
sqlparse==0.3.0
Any help is appreciated.
EDIT1:
I dont have ebextentions setup, however the same config's are present when i run " eb config"
aws:elasticbeanstalk:container:python:
NumProcesses: '1'
NumThreads: '15'
StaticFiles: /static/=static/
WSGIPath: modelforms/modelforms/wsgi.py
aws:elasticbeanstalk:container:python:staticfiles:
/static/: static/
aws:elasticbeanstalk:environment:
EnvironmentType: LoadBalanced
ExternalExtensionsS3Bucket: null
ExternalExtensionsS3Key: null
LoadBalancerType: application
ServiceRole: aws-elasticbeanstalk-service-role

Try adding your DJANGO_SETTINGS_MODULE and PYTHONPATH to the config
"aws:elasticbeanstalk:application:environment":
DJANGO_SETTINGS_MODULE: "modelforms.settings"
"PYTHONPATH": "/opt/python/current/app/modelforms:$PYTHONPATH"
Also, check the Health dashboard and make sure it shows as deployed before testing

Related

Django Apache - internal Server Error mod_wsgi [duplicate]

I've been developing a Django web application deployed on an Apache server with WSGI, and everything has been going smoothly. Today, I made some minor changes to my app's admin.py in an attempt to customize the build-in Django Admin interface, and initially made a syntax error (an unclosed parenthesis). This meant that when I touched wsgi.py and loaded the code (I have WSGI running in daemon mode on my virtual host), my website was replaced with an Internal Server Error because WSGI stopped when it hit the syntax error.
So I fixed the syntax error, checked that I didn't have any more with manage.py check, and touched wsgi.py to redeploy. But my website still displays an Internal Server Error! Checking the Apache logs, this is what I see:
[Sun Nov 23 13:52:46 2014] [info] mod_wsgi (pid=19093): Create interpreter 'quotes.cs.cornell.edu|'.
[Sun Nov 23 13:52:46 2014] [info] mod_wsgi (pid=19093): Adding '/extra/www/html/quotes/quotes_django' to path.
[Sun Nov 23 13:52:46 2014] [info] mod_wsgi (pid=19093): Adding '/opt/rh/python27/root/usr/lib64/python2.7/site-
packages/' to path.
[Sun Nov 23 13:52:46 2014] [info] [client 128.84.33.19] mod_wsgi (pid=19093, process='quotes.cs.cornell.edu',
application='quotes.cs.cornell.edu|'): Loading WSGI script '/extra/www/html/quotes/quotes_django/quotes_django/
wsgi.py'.
[Sun Nov 23 13:52:46 2014] [error] [client 128.84.33.19] mod_wsgi (pid=19093): Target WSGI script '/extra/www/html/
quotes/quotes_django/quotes_django/wsgi.py' cannot be loaded as Python module.
[Sun Nov 23 13:52:46 2014] [error] [client 128.84.33.19] mod_wsgi (pid=19093): Exception occurred processing WSGI
script '/extra/www/html/quotes/quotes_django/quotes_django/wsgi.py'.
[Sun Nov 23 13:52:46 2014] [error] [client 128.84.33.19] Traceback (most recent call last):
[Sun Nov 23 13:52:46 2014] [error] [client 128.84.33.19] File "/extra/www/html/quotes/quotes_django/
quotes_django/wsgi.py", line 14, in <module>
[Sun Nov 23 13:52:46 2014] [error] [client 128.84.33.19] application = get_wsgi_application()
[Sun Nov 23 13:52:46 2014] [error] [client 128.84.33.19] File "/opt/rh/python27/root/usr/lib64/python2.7/site-
packages/django/core/wsgi.py", line 14, in get_wsgi_application
[Sun Nov 23 13:52:46 2014] [error] [client 128.84.33.19] django.setup()
[Sun Nov 23 13:52:46 2014] [error] [client 128.84.33.19] File "/opt/rh/python27/root/usr/lib64/python2.7/site-
packages/django/__init__.py", line 21, in setup
[Sun Nov 23 13:52:46 2014] [error] [client 128.84.33.19] apps.populate(settings.INSTALLED_APPS)
[Sun Nov 23 13:52:46 2014] [error] [client 128.84.33.19] File "/opt/rh/python27/root/usr/lib64/python2.7/site-
packages/django/apps/registry.py", line 115, in populate
[Sun Nov 23 13:52:46 2014] [error] [client 128.84.33.19] app_config.ready()
[Sun Nov 23 13:52:46 2014] [error] [client 128.84.33.19] File "/opt/rh/python27/root/usr/lib64/python2.7/site-
packages/django/contrib/admin/apps.py", line 22, in ready
[Sun Nov 23 13:52:46 2014] [error] [client 128.84.33.19] self.module.autodiscover()
[Sun Nov 23 13:52:46 2014] [error] [client 128.84.33.19] File "/opt/rh/python27/root/usr/lib64/python2.7/site-
packages/django/contrib/admin/__init__.py", line 23, in autodiscover
[Sun Nov 23 13:52:46 2014] [error] [client 128.84.33.19] autodiscover_modules('admin', register_to=site)
[Sun Nov 23 13:52:46 2014] [error] [client 128.84.33.19] File "/opt/rh/python27/root/usr/lib64/python2.7/site-
packages/django/utils/module_loading.py", line 74, in autodiscover_modules
[Sun Nov 23 13:52:46 2014] [error] [client 128.84.33.19] import_module('%s.%s' % (app_config.name,
module_to_search))
[Sun Nov 23 13:52:46 2014] [error] [client 128.84.33.19] File "/usr/lib64/python2.7/importlib/__init__.py", line
37, in import_module
[Sun Nov 23 13:52:46 2014] [error] [client 128.84.33.19] __import__(name)
[Sun Nov 23 13:52:46 2014] [error] [client 128.84.33.19] File "/extra/www/html/quotes/quotes_django/quotespage/
admin.py", line 25
[Sun Nov 23 13:52:46 2014] [error] [client 128.84.33.19] approve_quotes.short_description = "Approve selected
quotes"
[Sun Nov 23 13:52:46 2014] [error] [client 128.84.33.19] ^
[Sun Nov 23 13:52:46 2014] [error] [client 128.84.33.19] SyntaxError: invalid syntax
[Sun Nov 23 13:53:36 2014] [info] [client 128.84.33.19] mod_wsgi (pid=19093, process='quotes.cs.cornell.edu',
application='quotes.cs.cornell.edu|'): Loading WSGI script '/extra/www/html/quotes/quotes_django/quotes_django/
wsgi.py'.
[Sun Nov 23 13:53:36 2014] [error] [client 128.84.33.19] mod_wsgi (pid=19093): Target WSGI script '/extra/www/html/
quotes/quotes_django/quotes_django/wsgi.py' cannot be loaded as Python module.
[Sun Nov 23 13:53:36 2014] [error] [client 128.84.33.19] mod_wsgi (pid=19093): Exception occurred processing WSGI
script '/extra/www/html/quotes/quotes_django/quotes_django/wsgi.py'.
[Sun Nov 23 13:53:36 2014] [error] [client 128.84.33.19] Traceback (most recent call last):
[Sun Nov 23 13:53:36 2014] [error] [client 128.84.33.19] File "/extra/www/html/quotes/quotes_django/
quotes_django/wsgi.py", line 14, in <module>
[Sun Nov 23 13:53:36 2014] [error] [client 128.84.33.19] application = get_wsgi_application()
[Sun Nov 23 13:53:36 2014] [error] [client 128.84.33.19] File "/opt/rh/python27/root/usr/lib64/python2.7/site-
packages/django/core/wsgi.py", line 14, in get_wsgi_application
[Sun Nov 23 13:53:36 2014] [error] [client 128.84.33.19] django.setup()
[Sun Nov 23 13:53:36 2014] [error] [client 128.84.33.19] File "/opt/rh/python27/root/usr/lib64/python2.7/site-
packages/django/__init__.py", line 21, in setup
[Sun Nov 23 13:53:36 2014] [error] [client 128.84.33.19] apps.populate(settings.INSTALLED_APPS)
[Sun Nov 23 13:53:36 2014] [error] [client 128.84.33.19] File "/opt/rh/python27/root/usr/lib64/python2.7/site-
packages/django/apps/registry.py", line 78, in populate
[Sun Nov 23 13:53:36 2014] [error] [client 128.84.33.19] raise RuntimeError("populate() isn't reentrant")
[Sun Nov 23 13:53:36 2014] [error] [client 128.84.33.19] RuntimeError: populate() isn't reentrant
The first series of errors shows WSGI failing due to the syntax error in my admin.py. However, the second series of errors seems to show an error internal to Django:
RuntimeError: populate() isn't reentrant
thrown from the populate method of registry.py.
Googling this error message returns surprisingly little information, none of it from Django documentation. Apparently, it can sometimes happen if you name an app twice in your settings.py, but I'm not doing that. More importantly, I haven't changed settings.py since the point where the website was working fine -- the only thing I changed was admin.py.
I tried reverting all the changes I made, so all my Python code is back in the state it was when the website was working -- and I still get the populate() isn't reentrant error when I try to make WSGI reload the code!
I've also tried commenting-out different apps in the INSTALLED_APPS section of settings.py, and even with only 'django.contrib.staticfiles' enabled the error still happens. Weirdly, I still get the error even if I comment out all the apps -- Django throws the error even when it isn't loading any apps!
Does anyone know what's going on here? Or any better way for me to debug this error, since the traceback in the Apache log is pretty unhelpful?
Notes: I'm using Django 1.7, Apache 2.2, and Python 2.7.
This is caused by a bug in your Django settings somewhere. Unfortunately, Django's hiding the bug behind this generic and un-useful error message.
To reveal the true problem, open django/apps/registry.py and around line 80, replace:
raise RuntimeError("populate() isn't reentrant")
with:
self.app_configs = {}
This will allow Django to continue loading, and reveal the actual error.
I've encountered this error for several different causes. Once was because I had a bad import in one of my app's admin.py.
Update from the Future
Since this question has continued to receive attention years after I originally asked it, I thought I should update my answer to better help future readers solve their problems.
It turns out there are (at least) two different reasons you could be getting the "populate() isn't reentrant" error, and thus two different approaches to solving the problem:
There is an error in your Python code or your Django settings that makes your app fail to initialize correctly. As #Cerin's answer points out, Django hides the real problem behind the unhelpful "populate isn't reentrant" message. To fix this and reveal the actual error, follow #Cerin's advice and edit django/apps/registry.py to make Django stop throwing the RuntimeError.
There was at one point an error in your Python code, but you have fixed it, and Django still keeps failing with this message because WSGI won't reload your fixed code. This is a WSGI problem, not a Django problem. One way to fix it is to temporarily edit wsgi.py so that its application function kills the WSGI process (forcing it to restart), as I described in my original answer; another is to set the startup-timeout option of mod_wsgi so that WSGI will restart itself, as #Graham Dumpleton described in the comments. Restarting the entire Apache server also fixes this problem, because it will incidentally restart WSGI, although that's a bit heavy-handed and not always possible if you're not an admin on the webserver.
Original answer below:
My server's administrator restarted Apache, and that magically fixed this problem. The exact same Python files loaded without causing populate() isn't reentrant. I even tried loading another file with a syntax error, then fixing it, and the server was able to load the new file and run correctly with no problems.
I still don't know what was going wrong, but I'm marking this as answered since the problem is gone. (Well, I'll mark it as answered as soon as StackOverflow allows me to accept my own answer.)
Update: After continuing to get this error when I accidentally upload Python with syntax errors, I figured out a workaround that's easier than restarting Apache. When WSGI starts throwing the populate() isn't reentrant error, I replace my Django project's wsgi.py with this simple function:
def application(environ, start_response):
if environ['mod_wsgi.process_group'] != '':
import signal
os.kill(os.getpid(), signal.SIGINT)
return ["killed"]
Then I reload my website, and the WSGI daemon process restarts (which I can tell by looking at the Apache log, even though the website still displays the same 500 error).
If I then change wsgi.py back to normal and reload again, WSGI successfully picks up my code without throwing populate() isn't reentrant (assuming I have no syntax errors this time). So the entirety of Apache doesn't need to restart, just the WSGI process, and I can do that without root privileges.
I know this is an old answer but I will contribute with my solution:
As a way to diagnose the source of the problem run manage.py checkand see if you find anything there
In my case an outdated requirement was the issue and django was failing to import a submodule
Make sure that your requirements are up to date
It's not a response but a reflexion.
When you upgrade to django 1.7 and you have a 500 error and reload your page, Apache says "populate() isn't reentrant".
I think it's when you load your page, Apache load all the modules you need for your app and when the error is handle it doesn't unload module. So, when you reload your page, apache load again theses modules but it's already loaded. So, apache says "populate() isn't reentrant".
I've two actions to correct this : Restart apache, or correct the error that handle the first 5OO error.
Try restarting apache with:
sudo service httpd restart
I hope it will help you.
If you're getting this error when using Google App Engine check your logs for other errors which might be causing this. I was getting:
ImproperlyConfigured: Error loading either pysqlite2 or sqlite3 modules (tried in that order): No module named _sqlite3
You can't use SQLite with Google App Engine so commenting out the DATABASES section of settings.py stopped that error and the RuntimeError("populate() isn't reentrant") error as well.
You may be able to fix it without restarting Apache by touching a file (other than wsgi.py) that is early on in the loading process. For example, your settings file:
$ touch settings.py
I haven't properly solved this either, but more info in my question here: Code change monitoring malfunctioning with Django 1.7 on mod-wsgi
Apache stores the wsgi file in its cache.
Disable Apache caching of python files
So first delete the wsgi file and restart your acpache and then add wsgi file again and restart the apache.
This error also generated if inconsistence use of space and tab in the code.
I just faced the same problem so I started looking around.
Now I've got it working, so I thought I should share it with you guys!
All I did was do chown user:group /to/path -R and chmod 770 /to/path -R all over again and it worked.
This looks like a nice collection of valid responses for the same Apache mod-wsgi error, each guy posting the one that works for him/her, so here is mine:
Do not forget to update your project requirements after deploying :)
I experienced this same problem, and the source of the error for me was just a syntax error in a file I was working with. After fixing the typo, the populate() is not reentrant error disappeared.
If you are running django from a wsgi script, you might be able to identify the typo by just running the wsgi script from the command line. For example:
cd /usr/local/www/wsgi-scripts/
python djangolauncher.wsgi
If you tested your syntax in your dev environment and everything is ok, then the problem is here
WSGIDaemonProcess celeryEnv python-path=/var/www/celeryEnv/lib/python3.6/site-packages user=apache group=apache python-home=/var/www/celeryEnv
apache only look at
python-path=/var/www/celeryEnv/lib/python3.6/site-packages
so any modules in lib64 will not be recognized in apache
I found a workaround by coping all modules in /var/www/celeryEnv/lib64
to /var/www/celeryEnv/lib
now apache will work here's the line from my own servers
WSGIDaemonProcess domain.com python-path=/home/user/app/env/lib/python3.6/site-packages:/home/user/app
Note: there's beneficial information already here, but I put this answer because My servers are mostly Centos-7 which are working as it should with my answer !!
Setup: Ubuntu 14.04, Django 1.10, Python 3.5 (in virtualenv).
I tried many of these solutions without luck, but then I noticed that the Apache error log contains two different errors in my case. One that happens when someone tries to visit a page, another that happens at start up. I missed the startup one because I usually tried to refresh the page a couple of times and thus only saw the on visit error repeated a few times.
I then searched for solutions to the startup error instead and the solution to this question worked for me. Briefly, it involves updating the mod_wsgi package in a roundabout way.
I had been receiving warnings for months about the mismatch in mod_wsgi versions, but suddenly it resulted in Apache error 500's. Doesn't make any sense to me.
My guess is that this RuntimeError: populate() isn't reentrant error is usually a sign that one should look for a startup error, which indicates the real problem.
on visit
[Sat Oct 15 03:38:08.900966 2016] [:error] [pid 28272] [remote 95.166.81.114:39651] mod_wsgi (pid=28272): Target WSGI script '/django/GP/GP/wsgi.py' cannot be loaded as Python module.
[Sat Oct 15 03:38:08.901409 2016] [:error] [pid 28272] [remote 95.166.81.114:39651] mod_wsgi (pid=28272): Exception occurred processing WSGI script '/django/GP/GP/wsgi.py'.
[Sat Oct 15 03:38:08.901662 2016] [:error] [pid 28272] [remote 95.166.81.114:39651] Traceback (most recent call last):
[Sat Oct 15 03:38:08.902184 2016] [:error] [pid 28272] [remote 95.166.81.114:39651] File "/django/GP/GP/wsgi.py", line 16, in <module>
[Sat Oct 15 03:38:08.902217 2016] [:error] [pid 28272] [remote 95.166.81.114:39651] application = get_wsgi_application()
[Sat Oct 15 03:38:08.902501 2016] [:error] [pid 28272] [remote 95.166.81.114:39651] File "/django/env/lib/python3.5/site-packages/django/core/wsgi.py", line 13, in get_wsgi_application
[Sat Oct 15 03:38:08.902529 2016] [:error] [pid 28272] [remote 95.166.81.114:39651] django.setup(set_prefix=False)
[Sat Oct 15 03:38:08.902726 2016] [:error] [pid 28272] [remote 95.166.81.114:39651] File "/django/env/lib/python3.5/site-packages/django/__init__.py", line 27, in setup
[Sat Oct 15 03:38:08.902755 2016] [:error] [pid 28272] [remote 95.166.81.114:39651] apps.populate(settings.INSTALLED_APPS)
[Sat Oct 15 03:38:08.902924 2016] [:error] [pid 28272] [remote 95.166.81.114:39651] File "/django/env/lib/python3.5/site-packages/django/apps/registry.py", line 78, in populate
[Sat Oct 15 03:38:08.902953 2016] [:error] [pid 28272] [remote 95.166.81.114:39651] raise RuntimeError("populate() isn't reentrant")
[Sat Oct 15 03:38:08.903111 2016] [:error] [pid 28272] [remote 95.166.81.114:39651] RuntimeError: populate() isn't reentrant
start up
[Sat Oct 15 03:38:08.900966 2016] [:error] [pid 28272] [remote 95.166.81.114:39651] mod_wsgi (pid=28272): Target WSGI script '/django/GP/GP/wsgi.py' cannot be loaded as Python module.
[Sat Oct 15 03:38:08.901409 2016] [:error] [pid 28272] [remote 95.166.81.114:39651] mod_wsgi (pid=28272): Exception occurred processing WSGI script '/django/GP/GP/wsgi.py'.
[Sat Oct 15 03:38:08.901662 2016] [:error] [pid 28272] [remote 95.166.81.114:39651] Traceback (most recent call last):
[Sat Oct 15 03:38:08.902184 2016] [:error] [pid 28272] [remote 95.166.81.114:39651] File "/django/GP/GP/wsgi.py", line 16, in <module>
[Sat Oct 15 03:38:08.902217 2016] [:error] [pid 28272] [remote 95.166.81.114:39651] application = get_wsgi_application()
[Sat Oct 15 03:38:08.902501 2016] [:error] [pid 28272] [remote 95.166.81.114:39651] File "/django/env/lib/python3.5/site-packages/django/core/wsgi.py", line 13, in get_wsgi_application
[Sat Oct 15 03:38:08.902529 2016] [:error] [pid 28272] [remote 95.166.81.114:39651] django.setup(set_prefix=False)
[Sat Oct 15 03:38:08.902726 2016] [:error] [pid 28272] [remote 95.166.81.114:39651] File "/django/env/lib/python3.5/site-packages/django/__init__.py", line 27, in setup
[Sat Oct 15 03:38:08.902755 2016] [:error] [pid 28272] [remote 95.166.81.114:39651] apps.populate(settings.INSTALLED_APPS)
[Sat Oct 15 03:38:08.902924 2016] [:error] [pid 28272] [remote 95.166.81.114:39651] File "/django/env/lib/python3.5/site-packages/django/apps/registry.py", line 78, in populate
[Sat Oct 15 03:38:08.902953 2016] [:error] [pid 28272] [remote 95.166.81.114:39651] raise RuntimeError("populate() isn't reentrant")
[Sat Oct 15 03:38:08.903111 2016] [:error] [pid 28272] [remote 95.166.81.114:39651] RuntimeError: populate() isn't reentrant
[Sat Oct 15 03:38:43.291502 2016] [:error] [pid 28272] Exception ignored in: <module 'threading' from '/usr/lib/python3.4/threading.py'>
[Sat Oct 15 03:38:43.291579 2016] [:error] [pid 28272] Traceback (most recent call last):
[Sat Oct 15 03:38:43.291604 2016] [:error] [pid 28272] File "/usr/lib/python3.4/threading.py", line 1288, in _shutdown
[Sat Oct 15 03:38:43.292356 2016] [:error] [pid 28272] assert tlock is not None
[Sat Oct 15 03:38:43.292377 2016] [:error] [pid 28272] AssertionError:
[Fri Oct 14 23:38:43.412942 2016] [:error] [pid 28299] Exception ignored in: <module 'threading' from '/usr/lib/python3.4/threading.py'>
[Fri Oct 14 23:38:43.413044 2016] [:error] [pid 28299] Traceback (most recent call last):
[Fri Oct 14 23:38:43.413076 2016] [:error] [pid 28299] File "/usr/lib/python3.4/threading.py", line 1288, in _shutdown
[Fri Oct 14 23:38:43.425037 2016] [:error] [pid 28275] Exception ignored in: <module 'threading' from '/usr/lib/python3.4/threading.py'>
[Fri Oct 14 23:38:43.425125 2016] [:error] [pid 28275] Traceback (most recent call last):
[Fri Oct 14 23:38:43.425157 2016] [:error] [pid 28275] File "/usr/lib/python3.4/threading.py", line 1288, in _shutdown
[Fri Oct 14 23:38:43.427625 2016] [:error] [pid 28274] Exception ignored in: <module 'threading' from '/usr/lib/python3.4/threading.py'>
[Fri Oct 14 23:38:43.427694 2016] [:error] [pid 28274] Traceback (most recent call last):
[Fri Oct 14 23:38:43.427722 2016] [:error] [pid 28274] File "/usr/lib/python3.4/threading.py", line 1288, in _shutdown
[Fri Oct 14 23:38:43.432020 2016] [:error] [pid 28273] Exception ignored in: <module 'threading' from '/usr/lib/python3.4/threading.py'>
[Fri Oct 14 23:38:43.432078 2016] [:error] [pid 28273] Traceback (most recent call last):
[Fri Oct 14 23:38:43.432105 2016] [:error] [pid 28273] File "/usr/lib/python3.4/threading.py", line 1288, in _shutdown
[Fri Oct 14 23:38:43.438577 2016] [:error] [pid 28299] assert tlock is not None
[Fri Oct 14 23:38:43.438654 2016] [:error] [pid 28299] AssertionError:
[Fri Oct 14 23:38:43.442174 2016] [:error] [pid 28274] assert tlock is not None
[Fri Oct 14 23:38:43.442226 2016] [:error] [pid 28274] AssertionError:
[Fri Oct 14 23:38:43.447227 2016] [:error] [pid 28276] Exception ignored in: <module 'threading' from '/usr/lib/python3.4/threading.py'>
[Fri Oct 14 23:38:43.447294 2016] [:error] [pid 28276] Traceback (most recent call last):
[Fri Oct 14 23:38:43.447326 2016] [:error] [pid 28276] File "/usr/lib/python3.4/threading.py", line 1288, in _shutdown
[Fri Oct 14 23:38:43.448813 2016] [:error] [pid 28277] Exception ignored in: <module 'threading' from '/usr/lib/python3.4/threading.py'>
[Fri Oct 14 23:38:43.448876 2016] [:error] [pid 28277] Traceback (most recent call last):
[Fri Oct 14 23:38:43.448903 2016] [:error] [pid 28277] File "/usr/lib/python3.4/threading.py", line 1288, in _shutdown
[Fri Oct 14 23:38:43.450188 2016] [:error] [pid 28273] assert tlock is not None
[Fri Oct 14 23:38:43.450231 2016] [:error] [pid 28273] AssertionError:
[Fri Oct 14 23:38:43.456680 2016] [:error] [pid 28275] assert tlock is not None
[Fri Oct 14 23:38:43.456737 2016] [:error] [pid 28275] AssertionError:
[Fri Oct 14 23:38:43.461761 2016] [:error] [pid 28277] assert tlock is not None
[Fri Oct 14 23:38:43.461826 2016] [:error] [pid 28277] AssertionError:
[Fri Oct 14 23:38:43.466165 2016] [:error] [pid 28276] assert tlock is not None
[Fri Oct 14 23:38:43.466219 2016] [:error] [pid 28276] AssertionError:
[Fri Oct 14 23:38:43.658971 2016] [mpm_prefork:notice] [pid 28268] AH00169: caught SIGTERM, shutting down
[Sat Oct 15 03:38:43.691909 2016] [:error] [pid 28272] Exception ignored in: <module 'threading' from '/usr/lib/python3.4/threading.py'>
[Sat Oct 15 03:38:43.691968 2016] [:error] [pid 28272] Traceback (most recent call last):
[Sat Oct 15 03:38:43.691996 2016] [:error] [pid 28272] File "/usr/lib/python3.4/threading.py", line 1288, in _shutdown
[Sat Oct 15 03:38:43.693126 2016] [:error] [pid 28272] assert tlock is not None
[Sat Oct 15 03:38:43.693159 2016] [:error] [pid 28272] AssertionError:
[Fri Oct 14 23:38:44.490316 2016] [:warn] [pid 28349] mod_wsgi: Compiled for Python/3.4.0.
[Fri Oct 14 23:38:44.490407 2016] [:warn] [pid 28349] mod_wsgi: Runtime using Python/3.4.3.
[Fri Oct 14 23:38:44.505672 2016] [mpm_prefork:notice] [pid 28349] AH00163: Apache/2.4.7 (Ubuntu) PHP/5.5.9-1ubuntu4.19 mod_wsgi/3.4 Python/3.4.3 configured -- resuming normal operations
[Fri Oct 14 23:38:44.505764 2016] [core:notice] [pid 28349] AH00094: Command line: '/usr/sbin/apache2'
I know it has been a while since this question was asked, but I just ran into this issue due to a problem I haven't seen discussed here. I was getting the RuntimeError: populate() isn't reentrant error due to SELinux on CentOS 7. I had Django served out of a home directory, and I simply had to enable the SELinux boolean that allowed reading home directories, as the populate() error was due to a permissions issue. The solution for me was setsebool -P httpd_read_user_content 1. I hope this helps someone having this issue.
In my case the error occured because a required pip-package was missing.
So I did a pip install -r requirements.txt, restarted apache and things worked again.
In my case, I had a circular import, which cause an error that break the populate method.
The multitude of answers makes it clear; this is a generic error that can have multiple root causes, typically related to loading Apache/WSGI.
All of these answers on this page should function as a kind of checklist, and in that vein I want to add the root cause of my instance of this error: failure to add an 'import os' to your settings.py file.
Specifically, we had a developer on our team who intended to remove an unneeded package, and instead removed 'import os' from the top of the production settings.py file. After an apache restart, our application wouldn't restart and we received the dreaded 'RuntimeError: populate() isn't reentrant' error.
A quick 'python manage.py check' did not reveal the issue, but a 'python settings.py' did; the os package was not loaded.
If you have this error, focus your search on checking your settings.py file(s) and also your WSGI file.
RuntimeError: populate() isn't reentrant
Can be anything, that is why there are so many different answers for this question.
The trick is to look at the error message just before the RuntimeError. In your case there seems to be a syntax error in the file /extra/www/htmlquotes/quotes_django/quotespage/admin.py on line 15, see:
Sun Nov 23 13:52:46 2014] [error] [client 128.84.33.19] File "/extra/www/htmlquotes/quotes_django/quotespage/admin.py", line 25
[Sun Nov 23 13:52:46 2014] [error] [client 128.84.33.19] pprove_quotes.short_description = "Approve selected quotes"
[Sun Nov 23 13:52:46 2014] [error] [client 128.84.33.19] ^
[Sun Nov 23 13:52:46 2014] [error] [client 128.84.33.19] SyntaxError: invalid syntax
I had a recursive django.setup(), eg I tried to write a django.setup() inside a an app/models.py, in the stack trace django tried to point this out near:
... "site-packages/django/apps/config.py", line 211, in import_models
self.models_module = import_module(models_module_name)
...
... ./myproject/myapp/models.py ...
so yeah, be sure not to try to setup django while django is being setup...
Note on AWS Elastic Beanstalk: The default settings.py that is written by Django-admin includes a reference to a local sqlite database as the data source. This will likely work on your local OS, but not on AWS EB, and will give the populate() isn't reentrant runtime error. To test for this, simply comment out the DATABASES={<...>} statement in settings.py, deploy, and re-open the application.
For me the error was a missing mysqlclient package in the requirements.txt file.
First I installed the mysqlclient package with:
pip install mysqlclient
then I updated the requirements.txt file with:
pip freeze > requirements.txt
and this solved my problem.
I had this problem and couldn't find any answer why until I backtracked my commits. Apparently I had added an accidental import, because of auto-completion, that screwed up the setup.
# found in models.py
from msilib.schema import SelfReg
In apache error log:
RuntimeError("populate() isn't reentrant")
It worked fine in my windows dev environment but failed on the ubuntu/apache server.
I was going into this same error after having change the order of this setting :
MIDDLEWARE_CLASSES = (
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.auth.middleware.SessionAuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
'django.middleware.security.SecurityMiddleware',
)
putting it back on the order here before and restarting apache fixed the issue.
In my case, I had a custom renderer class for Django Rest Framework, for some purpose I had to override the renderer class's method "get_context" (full disclosure : to make django toolbar give correct SQL query count)
I removed that class and redeployed. It Worked.
Removing the virtualenv directory, recreating the virtualenv, then reinstalling all the requirements fixed it for me.
I hesitate to add this as an answer since it's really just a description of a related case. However, it didn't seem legible as a comment.
I ran into this error when creating a function that could access the Django database without the server running. Mostly, this was being used for inserting test data entries.
My project had the following in its project/apps/app_one/functions.py file:
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "Project.settings")
import django
django.setup()
This allows access to the Django database through Python scripts without a server running. See here for more info on this approach: https://stackoverflow.com/a/26875729/4573162
I was also keeping basic app functions in this file that didn't require database access and were to be used while a server was running. For example, in my app_one.models.py I might have the following usage of a functions.arg_format function, imported from the app_name/functions.py file:
def save(self, *args, **kwargs):
self.some_arg = functions.arg_format(self.some_arg)
super().save(*args, **kwargs)
What this amounts to is that my application, while running, was trying to again run the Django setup().
I dont' know how related this is but it threw the same RuntimeError: populate() isn't reentrant error until I created a separate file for all the database-accessing functions. After the additional setup() import was sidestepped, migrations were able to be completed as expected.
Adding my reason to the list.
For me it was because I had a django service named with the same directory as a process directory. Renaming the process/dir fixed the issue.
Restarting the Apache server for me solved the problem. You can do that by using the command
$ sudo service apache2 restart
I had this same issue, what worked for me was commenting out the default database settings in / settings.py . I also read that later versions of django are not compatible with ebs
In apps.py, i have set different name from my app name.

ImportError: No module named cx_Oracle in apache

I deploy flask with apache on CentOS7
And I want Oracle database to insert or select when user access.
So I install cx_Oracle
pip install cx_Oracle
And run flask on virtual env.
flask run
It work with no error.
But I access to localhost:80 using apache, It occur Internal Server Error 500.
In error_log
[Fri Oct 23 09:12:34.623473 2020] [mpm_prefork:notice] [pid 475] AH00170: caught SIGWINCH, shutting down gracefully
[Fri Oct 23 09:12:35.678302 2020] [lbmethod_heartbeat:notice] [pid 510] AH02282: No slotmem from mod_heartmonitor
[Fri Oct 23 09:12:35.681622 2020] [mpm_prefork:notice] [pid 510] AH00163: Apache/2.4.6 (CentOS) mod_wsgi/3.4 Python/2.7.5 configured -- resuming normal operations
[Fri Oct 23 09:12:35.681665 2020] [core:notice] [pid 510] AH00094: Command line: '/usr/sbin/httpd -D FOREGROUND'
[Fri Oct 23 09:12:38.074902 2020] [:error] [pid 513] [client 172.17.0.1:33640] mod_wsgi (pid=513): Target WSGI script '/var/www/hitme/wsgi.py' cannot be loaded as Python module.
[Fri Oct 23 09:12:38.074946 2020] [:error] [pid 513] [client 172.17.0.1:33640] mod_wsgi (pid=513): Exception occurred processing WSGI script '/var/www/hitme/wsgi.py'.
[Fri Oct 23 09:12:38.074973 2020] [:error] [pid 513] [client 172.17.0.1:33640] Traceback (most recent call last):
[Fri Oct 23 09:12:38.074994 2020] [:error] [pid 513] [client 172.17.0.1:33640] File "/var/www/hitme/wsgi.py", line 10, in <module>
[Fri Oct 23 09:12:38.075058 2020] [:error] [pid 513] [client 172.17.0.1:33640] from app import app as application
[Fri Oct 23 09:12:38.075070 2020] [:error] [pid 513] [client 172.17.0.1:33640] File "/var/www/hitme/app/__init__.py", line 4, in <module>
[Fri Oct 23 09:12:38.075138 2020] [:error] [pid 513] [client 172.17.0.1:33640] import cx_Oracle
[Fri Oct 23 09:12:38.075162 2020] [:error] [pid 513] [client 172.17.0.1:33640] ImportError: No module named cx_Oracle
I followed this article for deploy flask with apache.
https://dev.to/sm0ke/flask-deploy-with-apache-on-centos-minimal-setup-2kb7
and install cx_Oracle and I copied it where I thought I needed it.
Here my tree
/etc/httpd/modules/
|-cx_Oracle.cpython-36m-x86_64-linux-gnu.so
|-cx_Oracle-8.0.1.dist-info
/var/www/hitme/lib/python3.6/site-packages
|-cx_Oracle.cpython-36m-x86_64-linux-gnu.so
|-cx_Oracle-8.0.1.dist-info
/usr/local/lib/python3.6/site-packages
|-cx_Oracle.cpython-36m-x86_64-linux-gnu.so
|-cx_Oracle-8.0.1.dist-info
But it still gives the error.
Is there any other way?
Ensure that the required Oracle Instant Client is installed to the Apache user by downloading
https://download.oracle.com/otn_software/linux/instantclient/199000/instantclient-basic-linux.x64-19.9.0.0.0dbru.zip
and unzip ut to a folder Apache user owns or is accessible for read and execute - lets say
/apache/oracle
After that, ensure PATH, ORACLE_HOME and LD_LIBRARY_PATH ist set properly as Apache User - i.e.
export ORACLE_HOME=/apache/oracle
export PATH=$PATH:$ORACLE_HOME
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$ORACLE_HOME
If you start Apache as service then you may need to set the variables to root or user who starts apache.

Django AWS Elastic Beanstalk error ImproperlyConfigured: Error loading MySQLdb module: No module named MySQLdb

I know this error have come to many people and I have tried different solutions and none of them worked.
I am using aws eb cli.
I am using following command eb deploy to deploy my application to server.
Following are the configuration for my Django.
under .ebextensions directory, I have following 2 files:
1: 01_packages.config
packages:
yum:
git: []
python27-devel: []
mysql: []
mysql-devel: []
and another file is
2: 02_django.conf
option_settings:
"aws:elasticbeanstalk:application:environment":
DJANGO_SETTINGS_MODULE: "settings.development"
"PYTHONPATH": "/opt/python/current/app/src:$PYTHONPATH"
"aws:elasticbeanstalk:container:python":
WSGIPath: src/wsgi.py
NumProcesses: 3
NumThreads: 20
"aws:elasticbeanstalk:container:python:staticfiles":
"/static/": "static/"
Following is my requirements.txt file after pip freeze in my local virtual environment.
requirements.txt
asn1crypto==0.24.0
awsebcli==3.17.1
backports.ssl-match-hostname==3.5.0.1
botocore==1.14.17
cement==2.8.2
cent==2.1.0
centrifuge==0.8.4
certifi==2017.11.5
cffi==1.11.2
chardet==3.0.4
colorama==0.3.9
cryptography==2.1.4
Django==1.8.18
django-colorfield==0.1.14
django-countries==5.0
django-debug-toolbar==1.9.1
django-environ==0.4.4
django-multiselectfield==0.1.8
django-simple-history==1.9.1
django-sslserver==0.20
docutils==0.15.2
enum34==1.1.6
future==0.16.0
google-api-python-client==1.6.4
hiredis==0.2.0
html5lib==1.0b8
httplib2==0.10.3
icalendar==4.0.0
idna==2.6
ipaddress==1.0.18
jmespath==0.9.4
jsonschema==2.4.0
mysqlclient==1.4.6
oauth2client==2.0.0
oauthclient==1.0.3
olefile==0.44
pathspec==0.5.9
paypalrestsdk==1.13.1
pdfcrowd==4.0.1
phonenumbers==8.8.6
Pillow==4.3.0
pyasn1==0.3.7
pyasn1-modules==0.1.5
pycparser==2.18
PyJWT==1.5.3
pyOpenSSL==17.5.0
PyPDF2==1.26.0
pypiwin32==219
pytesseract==0.1.7
python-dateutil==2.6.1
pytz==2017.3
PyYAML==5.2
reportlab==3.4.0
requests==2.18.4
rsa==3.4.2
semantic-version==2.5.0
six==1.11.0
sockjs-tornado==1.0.1
sqlparse==0.2.4
termcolor==1.1.0
toredis-fork==0.1.4
tornado==4.2.1
toro==0.8
twilio==6.9.1
uritemplate==3.0.0
urllib3==1.22
wcwidth==0.1.8
webencodings==0.5.1
xhtml2pdf==0.2.2
I kept this in my root directory.
When I run eb deploy
it deploys successfully.
but when I run the browser to my url.
I get this Internal Server Error page.
So I tried to look in to the log files on the server under /var/log/httpd/error_log
i get the following error:
[Mon Feb 24 17:56:57.227427 2020] [:error] [pid 8054] [remote 101.50.93.65:188] mod_wsgi (pid=8054): Target WSGI script '/opt/python/current/app/src/wsgi.py' cannot be loaded as Python module.
[Mon Feb 24 17:56:57.227450 2020] [:error] [pid 8054] [remote 101.50.93.65:188] mod_wsgi (pid=8054): Exception occurred processing WSGI script '/opt/python/current/app/src/wsgi.py'.
[Mon Feb 24 17:56:57.227466 2020] [:error] [pid 8054] [remote 101.50.93.65:188] Traceback (most recent call last):
[Mon Feb 24 17:56:57.227483 2020] [:error] [pid 8054] [remote 101.50.93.65:188] File "/opt/python/current/app/src/wsgi.py", line 17, in <module>
[Mon Feb 24 17:56:57.227585 2020] [:error] [pid 8054] [remote 101.50.93.65:188] application = get_wsgi_application()
[Mon Feb 24 17:56:57.227599 2020] [:error] [pid 8054] [remote 101.50.93.65:188] File "/opt/python/run/venv/local/lib/python2.7/site-packages/django/core/wsgi.py", line 14, in get_wsgi_application
[Mon Feb 24 17:56:57.227627 2020] [:error] [pid 8054] [remote 101.50.93.65:188] django.setup()
[Mon Feb 24 17:56:57.227634 2020] [:error] [pid 8054] [remote 101.50.93.65:188] File "/opt/python/run/venv/local/lib/python2.7/site-packages/django/__init__.py", line 18, in setup
[Mon Feb 24 17:56:57.227645 2020] [:error] [pid 8054] [remote 101.50.93.65:188] apps.populate(settings.INSTALLED_APPS)
[Mon Feb 24 17:56:57.227651 2020] [:error] [pid 8054] [remote 101.50.93.65:188] File "/opt/python/run/venv/local/lib/python2.7/site-packages/django/apps/registry.py", line 78, in populate
[Mon Feb 24 17:56:57.227662 2020] [:error] [pid 8054] [remote 101.50.93.65:188] raise RuntimeError("populate() isn't reentrant")
[Mon Feb 24 17:56:57.227676 2020] [:error] [pid 8054] [remote 101.50.93.65:188] RuntimeError: populate() isn't reentrant
So I kept Googling, and found a post suggested to change wsgi file, and I did and then this error updated to the following lines of code.
[Mon Feb 24 18:23:12.169850 2020] [mpm_prefork:notice] [pid 9081] AH00169: caught SIGTERM, shutting down
[Mon Feb 24 18:23:13.289449 2020] [suexec:notice] [pid 10286] AH01232: suEXEC mechanism enabled (wrapper: /usr/sbin/suexec)
[Mon Feb 24 18:23:13.305290 2020] [so:warn] [pid 10286] AH01574: module wsgi_module is already loaded, skipping
[Mon Feb 24 18:23:13.307373 2020] [http2:warn] [pid 10286] AH10034: The mpm module (prefork.c) is not supported by mod_http2. The mpm determines how things are processed in your server. HTTP/2 has more demands in this regard and the currently selected mpm will just not do. This is an advisory warning. Your server will continue to work, but the HTTP/2 protocol will be inactive.
[Mon Feb 24 18:23:13.307384 2020] [http2:warn] [pid 10286] AH02951: mod_ssl does not seem to be enabled
[Mon Feb 24 18:23:13.307990 2020] [lbmethod_heartbeat:notice] [pid 10286] AH02282: No slotmem from mod_heartmonitor
[Mon Feb 24 18:23:13.308050 2020] [:warn] [pid 10286] mod_wsgi: Compiled for Python/2.7.13.
[Mon Feb 24 18:23:13.308057 2020] [:warn] [pid 10286] mod_wsgi: Runtime using Python/2.7.16.
[Mon Feb 24 18:23:13.311200 2020] [mpm_prefork:notice] [pid 10286] AH00163: Apache/2.4.41 (Amazon) mod_wsgi/3.5 Python/2.7.16 configured -- resuming normal operations
[Mon Feb 24 18:23:13.311217 2020] [core:notice] [pid 10286] AH00094: Command line: '/usr/sbin/httpd -D FOREGROUND'
[Mon Feb 24 18:23:16.367182 2020] [:error] [pid 10293] [remote 127.0.0.1:0] mod_wsgi (pid=10293): Exception occurred processing WSGI script '/opt/python/current/app/src/wsgi.py'.
[Mon Feb 24 18:23:16.367240 2020] [:error] [pid 10293] [remote 127.0.0.1:0] RuntimeError: response has not been started
[Mon Feb 24 18:23:17.744228 2020] [:error] [pid 10291] [remote 127.0.0.1:0] mod_wsgi (pid=10291): Exception occurred processing WSGI script '/opt/python/current/app/src/wsgi.py'.
[Mon Feb 24 18:23:17.744288 2020] [:error] [pid 10291] [remote 127.0.0.1:0] RuntimeError: response has not been started
[Mon Feb 24 18:23:19.116825 2020] [:error] [pid 10292] [remote 127.0.0.1:0] mod_wsgi (pid=10292): Exception occurred processing WSGI script '/opt/python/current/app/src/wsgi.py'.
[Mon Feb 24 18:23:19.116892 2020] [:error] [pid 10292] [remote 127.0.0.1:0] RuntimeError: response has not been started
[Mon Feb 24 18:23:20.493432 2020] [:error] [pid 10418] [remote 127.0.0.1:0] mod_wsgi (pid=10418): Exception occurred processing WSGI script '/opt/python/current/app/src/wsgi.py'.
[Mon Feb 24 18:23:20.493489 2020] [:error] [pid 10418] [remote 127.0.0.1:0] RuntimeError: response has not been started
[Mon Feb 24 18:36:44.987693 2020] [:error] [pid 10443] [remote 95.105.12.68:0] mod_wsgi (pid=10443): Exception occurred processing WSGI script '/opt/python/current/app/src/wsgi.py'.
[Mon Feb 24 18:36:44.987766 2020] [:error] [pid 10443] [remote 95.105.12.68:0] RuntimeError: response has not been started
[Mon Feb 24 18:55:28.298121 2020] [:error] [pid 10468] [remote 101.50.93.65:0] mod_wsgi (pid=10468): Exception occurred processing WSGI script '/opt/python/current/app/src/wsgi.py'.
[Mon Feb 24 18:55:28.298180 2020] [:error] [pid 10468] [remote 101.50.93.65:0] RuntimeError: response has not been started
[Mon Feb 24 18:55:30.126198 2020] [:error] [pid 10499] [remote 101.50.93.65:0] mod_wsgi (pid=10499): Exception occurred processing WSGI script '/opt/python/current/app/src/wsgi.py'.
[Mon Feb 24 18:55:30.126260 2020] [:error] [pid 10499] [remote 101.50.93.65:0] RuntimeError: response has not been started
[Mon Feb 24 18:55:31.671293 2020] [:error] [pid 10973] [remote 101.50.93.65:0] mod_wsgi (pid=10973): Exception occurred processing WSGI script '/opt/python/current/app/src/wsgi.py'.
[Mon Feb 24 18:55:31.671358 2020] [:error] [pid 10973] [remote 101.50.93.65:0] RuntimeError: response has not been started
[Mon Feb 24 18:55:32.858757 2020] [:error] [pid 11606] [remote 101.50.93.65:0] mod_wsgi (pid=11606): Exception occurred processing WSGI script '/opt/python/current/app/src/wsgi.py'.
[Mon Feb 24 18:55:32.858821 2020] [:error] [pid 11606] [remote 101.50.93.65:0] RuntimeError: response has not been started
and this is the new wsgi.py file.
import os
import logging
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "settings.development")
from django.core.wsgi import get_wsgi_application
# application = get_wsgi_application()
env_variables_to_pass = ['DJANGO_SETTINGS_MODULE', ]
def application(environ, start_response):
if environ['mod_wsgi.process_group'] != '':
import signal
os.kill(os.getpid(), signal.SIGINT)
return ["killed"]
and following was the old wsgi.py file
import os
import logging
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "settings.development")
from django.core.wsgi import get_wsgi_application
application = get_wsgi_application()
env_variables_to_pass = ['DJANGO_SETTINGS_MODULE', ]
So then I tried to run application on the server using python manage.py runserver as there was nothing else to do to fix this and I was not sure where the problem is.
So I did ssh and I did used the virtualenvironment of server that was already there created by EB.
after running python manage.py runserver.
I get this following error.
File "/opt/python/run/venv/local/lib/python2.7/site-packages/django/db/backends/mysql/base.py", line 27, in <module>
raise ImproperlyConfigured("Error loading MySQLdb module: %s" % e)
django.core.exceptions.ImproperlyConfigured: Error loading MySQLdb module: No module named MySQLdb
So I tried to follow any advice that I could see available on google.
I tried pip install mysqlclient
I get this error.
Collecting mysqlclient
Using cached https://files.pythonhosted.org/packages/d0/97/7326248ac8d5049968bf4ec708a5d3d4806e412a42e74160d7f266a3e03a/mysqlclient-1.4.6.tar.gz
Complete output from command python setup.py egg_info:
sh: mysql_config: command not found
sh: mariadb_config: command not found
sh: mysql_config: command not found
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "/tmp/pip-build-MxFUOd/mysqlclient/setup.py", line 16, in <module>
metadata, options = get_config()
File "setup_posix.py", line 61, in get_config
libs = mysql_config("libs")
File "setup_posix.py", line 29, in mysql_config
raise EnvironmentError("%s not found" % (_mysql_config_path,))
EnvironmentError: mysql_config not found
----------------------------------------
Command "python setup.py egg_info" failed with error code 1 in /tmp/pip-build-MxFUOd/mysqlclient/
I tried both
pip install mysqlclient --no-cache-dir
and
pip install mysqlclient
It's Centos server so I cannot do the sudo apt-get commands.
Only yum commands work.
I tried this following command with sudo
sudo pip install mysql-connector-python
But I think this will be installed globally rather than env.
So I tried without sudo, and it gave permission error.
I used other commands to install mysql both with sudo and not sudo.
pip install pymysql
sudo yum install python-mysqldb
No matter what I do I get this MySQL error.
I don't want to move to other database as I would have to move data as well.
UPDATE
from given suggession of #Arun K i ran this following command
which mysql_config
i got this following response.
/usr/bin/which: no mysql_config in (/opt/python/run/venv/bin:/usr/local/bin:/bin:/usr/bin:/usr/local/sbin:/usr/sbin:/sbin:/opt/aws/bin:/home/ec2-user/.local/bin:/home/ec2-user/bin)
in my case on on 64bit Amazon Linux 2/3.0.1
i had to install the following via *.config inside .ebextensions
packages:
yum:
python3-devel: []
mariadb-devel: []
gcc: []
Try running
sudo yum install mysql-devel gcc python-devel
Then
pip install mysqlclient
Why don't you use docker and run the Django app as a container? The elastic beanstalk also supports the docker type. There are so many articles on the internet detailing the steps. you do not have to worry about centos.
Reference:
Django on Docler

Apache WSGI no module named django whitout virtualenv

wsgi.py:
import os,sys
sys.path.append('/var/www/html/yuyyu/yuyyu')
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "yuyyu.settings")
from django.core.wsgi import get_wsgi_application
application = get_wsgi_application()
apache.conf:
...
WSGIDaemonProcess yuyyu python-path=/var/www/html/yuyyu
WSGIProcessGroup yuyyu
WSGIScriptAlias / /var/www/html/yuyyu/yuyyu/wsgi.py \
process-group=yuyyu application-group=%{GLOBAL}
...
here is my error in error.log:
[Fri Dec 02 19:07:55.862266 2016] [:error] [pid 1414] [remote 213.14.244.3:2784] mod_wsgi (pid=1414): Target WSGI script '/var/www/html/yuyyu/yuyyu/wsgi.py' cannot be loaded as Python module.
[Fri Dec 02 19:07:55.862323 2016] [:error] [pid 1414] [remote 213.14.244.3:2784] mod_wsgi (pid=1414): Exception occurred processing WSGI script '/var/www/html/yuyyu/yuyyu/wsgi.py'.
[Fri Dec 02 19:07:55.862353 2016] [:error] [pid 1414] [remote 213.14.244.3:2784] Traceback (most recent call last):
[Fri Dec 02 19:07:55.862393 2016] [:error] [pid 1414] [remote 213.14.244.3:2784] File "/var/www/html/yuyyu/yuyyu/wsgi.py", line 23, in <module>
[Fri Dec 02 19:07:55.862398 2016] [:error] [pid 1414] [remote 213.14.244.3:2784] from django.core.wsgi import get_wsgi_application
[Fri Dec 02 19:07:55.862418 2016] [:error] [pid 1414] [remote 213.14.244.3:2784] ImportError: No module named 'django'
my project path is /var/www/html/yuyyu/
my wsgi file path is /var/www/html/yuyyu/yuyyu/
im get also 500 Internel Server Error and
im not using virtualenv so what can i do for solve this problem?
WSGIDaemonProcess yuyyu python-path=/var/www/html/yuyyu
I think that your problem is here, the python-path shouldn't be the path to your django project but to your python libraries (for instance the path to your python's site-packages directory where django is installed).
For me, for instance, this path is /usr/lib/python3.5/site-packages.
In wsgi.py try to load the path where you have Django. In my configuration it is located inside of virtualenv and the path looks like that:
import site
site.addsitedir('~/virtualenvs/myenv/lib/python3.5/site-packages')
here is my solition my django is installed to
/usr/lib/python2.7/dist-packages
and i change my .conf file like this
WSGIDaemonProcess yuyyu python-path=/usr/local/lib/python2.7/dist-packages
WSGIProcessGroup yuyyu
WSGIScriptAlias / /var/www/html/yuyyu/yuyyu/wsgi.py

Django Internal Server 500 Error AWS Elastic-Beanstalk issue

How do I fix the Django Internal Server 500 error on an AWS eb deployed application?
Do I need to change my allowed hosts in my base.py file to have the ip address of the ec2 in elasticbeanstalk?
# SECURITY WARNING: keep the secret key used in production secret!
# Raises ImproperlyConfigured exception if SECRET_KEY not in os.environ
SECRET_KEY = env('SECRET_KEY')
ALLOWED_HOSTS = []
# Application definition
INSTALLED_APPS = (
'django.contrib.auth',
'django_admin_bootstrapped',
'django.contrib.admin',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
)
...
STATIC_URL = '/static/'
ALLOWED_HOSTS = []
...
I enabled DEBUG and ran eb config, and eb logs. The eb deploy values are displayed below, and the eb logs values below that. How do you fix the issue that the "No module named django?"
Creating application version archive "app-3e17-161020_112522".
Uploading pronet/app-3e17-161020_112522.zip to S3. This may take a while.
Upload Complete.
INFO: Environment update is starting.
INFO: Deploying new version to instance(s).
INFO: New application version was deployed to running EC2 instances.
INFO: Environment update completed successfully.
Provided below are the output from eb logs.
============= i-0b11de8b8521ea5c0 ==============
-------------------------------------
/var/log/httpd/error_log
-------------------------------------
[Thu Oct 20 17:46:59.414032 2016] [:error] [pid 11268]
[remote 172.31.5.67:41390] Traceback (most recent call last):
[Thu Oct 20 17:46:59.414077 2016] [:error] [pid 11268]
[remote 172.31.5.67:41390] File "/opt/python/current/app/pronet/src/pronet/wsgi.py", line 12, in <module>
[Thu Oct 20 17:46:59.414083 2016] [:error] [pid 11268]
[remote 172.31.5.67:41390] from django.core.wsgi import get_wsgi_application
[Thu Oct 20 17:46:59.414104 2016] [:error] [pid 11268]
[remote 172.31.5.67:41390] ImportError: No module named 'django'
[Thu Oct 20 17:47:00.046644 2016] [:error] [pid 11268]
[remote 172.31.5.67:43182] mod_wsgi (pid=11268): Target WSGI script '/opt/python/current/app/pronet/src/pronet/wsgi.py' cannot be loaded as Python module.
[Thu Oct 20 17:47:00.046704 2016] [:error] [pid 11268]
[remote 172.31.5.67:43182] mod_wsgi (pid=11268): Exception occurred processing WSGI script '/opt/python/current/app/pronet/src/pronet/wsgi.py'.
[Thu Oct 20 17:47:00.046738 2016] [:error] [pid 11268]
[remote 172.31.5.67:43182] Traceback (most recent call last):
[Thu Oct 20 17:47:00.046784 2016] [:error] [pid 11268]
[remote 172.31.5.67:43182] File "/opt/python/current/app/pronet/src/pronet/wsgi.py", line 12, in <module>
[Thu Oct 20 17:47:00.046789 2016] [:error] [pid 11268]
[remote 172.31.5.67:43182] from django.core.wsgi import get_wsgi_application
[Thu Oct 20 17:47:00.046810 2016] [:error] [pid 11268]
[remote 172.31.5.67:43182] ImportError: No module named 'django'
[Thu Oct 20 17:47:01.340552 2016] [:error] [pid 11268]
[remote 172.31.5.67:43182] mod_wsgi (pid=11268): Target WSGI script '/opt/python/current/app/pronet/src/pronet/wsgi.py' cannot be loaded as Python module.
[Thu Oct 20 17:47:01.340603 2016] [:error] [pid 11268]
[remote 172.31.5.67:43182] mod_wsgi (pid=11268): Exception occurred processing WSGI script '/opt/python/current/app/pronet/src/pronet/wsgi.py'.
[Thu Oct 20 17:47:01.340653 2016] [:error] [pid 11268] [remote 172.31.5.67:43182] Traceback (most recent call last):
[Thu Oct 20 17:47:01.340701 2016] [:error] [pid 11268]
[remote 172.31.5.67:43182] File "/opt/python/current/app/pronet/src/pronet/wsgi.py", line 12, in <module>
[Thu Oct 20 17:47:01.340706 2016] [:error] [pid 11268]
[remote 172.31.5.67:43182] from django.core.wsgi import get_wsgi_application
[Thu Oct 20 17:47:01.340728 2016] [:error] [pid 11268]
[remote 172.31.5.67:43182] ImportError: No module named 'django'
link to github project. You can view all the code here
https://github.com/IantheFlyingHawaiian/Pronet
Did you do this?
pip freeze > requirements.txt
If you didn't, AWS will not know that it should install Django and other dependencies on your EC2 instances for your deployment.
In my case error with sqllite
Remove Database settings from settings.py and try deploy
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
}
}
And then I configured with AWS RDS.

Categories