title: RuntimeError: populate() isn't reentrant
body: <p>I got a legacy project based on Django as backend and Angularjs on the front. It's deployed and working, but I got no docs at all so I had to guess everything out of how to deploy it in local, how the system works and that.</p>
  
  <p>Now, I've been asked to set it up in a pre-production environment, and so I tried to do, I copied all the configs from the production server and changed as necessary to fit the new environment</p>
  
  <pre><code>[Thu Mar 15 07:08:53.612256 2018] [wsgi:error] [pid 13884:tid 140222719059712] [remote 212.170.177.164:49429] mod_wsgi (pid=13884): Target WSGI script '/opt/mysite/mysite/wsgi.py' cannot be loaded as Python module.
  [Thu Mar 15 07:08:53.612336 2018] [wsgi:error] [pid 13884:tid 140222719059712] [remote 212.170.177.164:49429] mod_wsgi (pid=13884): Exception occurred processing WSGI script '/opt/mysite/mysite/wsgi.py'.
  [Thu Mar 15 07:08:53.612539 2018] [wsgi:error] [pid 13884:tid 140222719059712] [remote 212.170.177.164:49429] Traceback (most recent call last):
  [Thu Mar 15 07:08:53.612602 2018] [wsgi:error] [pid 13884:tid 140222719059712] [remote 212.170.177.164:49429]   File "/opt/mysite/mysite/wsgi.py", line 19, in &lt;module&gt;
  [Thu Mar 15 07:08:53.612611 2018] [wsgi:error] [pid 13884:tid 140222719059712] [remote 212.170.177.164:49429]     application = get_wsgi_application()
  [Thu Mar 15 07:08:53.612624 2018] [wsgi:error] [pid 13884:tid 140222719059712] [remote 212.170.177.164:49429]   File "/usr/local/lib/python3.6/dist-packages/django/core/wsgi.py", line 12, in get_wsgi_application
  [Thu Mar 15 07:08:53.612632 2018] [wsgi:error] [pid 13884:tid 140222719059712] [remote 212.170.177.164:49429]     django.setup(set_prefix=False)
  [Thu Mar 15 07:08:53.612643 2018] [wsgi:error] [pid 13884:tid 140222719059712] [remote 212.170.177.164:49429]   File "/usr/local/lib/python3.6/dist-packages/django/__init__.py", line 24, in setup
  [Thu Mar 15 07:08:53.612649 2018] [wsgi:error] [pid 13884:tid 140222719059712] [remote 212.170.177.164:49429]     apps.populate(settings.INSTALLED_APPS)
  [Thu Mar 15 07:08:53.612659 2018] [wsgi:error] [pid 13884:tid 140222719059712] [remote 212.170.177.164:49429]   File "/usr/local/lib/python3.6/dist-packages/django/apps/registry.py", line 81, in populate
  [Thu Mar 15 07:08:53.612666 2018] [wsgi:error] [pid 13884:tid 140222719059712] [remote 212.170.177.164:49429]     raise RuntimeError("populate() isn't reentrant")
  [Thu Mar 15 07:08:53.612693 2018] [wsgi:error] [pid 13884:tid 140222719059712] [remote 212.170.177.164:49429] RuntimeError: populate() isn't reentrant
  </code></pre>
  
  <p>I tried to access that file (registry.py) and edit it so I could see what's going on inside, but it doesn't print anything on the Django console, neither in a file.</p>
  
  <p>Here are my config files:</p>
  
  <p>/etc/apache2/sites-enabled/dev.my_domain.com.conf</p>
  
  <pre><code>WSGIPythonPath /opt/mysite:/home/my_user/.local/lib/python3.6/site-packages
  &lt;VirtualHost *:80&gt;
          WSGIScriptAlias /backend /opt/mysite/mysite/wsgi.py
  
          &lt;Directory /opt/mysite/mysite/&gt;
          Require all granted
          &lt;/Directory&gt;
  
          WSGIDaemonProcess mysite python-path=/opt/mysite:/home/my_user/.local/lib/python3.6/site-packages
          WSGIProcessGroup mysite
  
          Alias /media/ /opt/mysite/media/
          Alias /static/ /opt/mysite/static/
  
          &lt;Directory /opt/mysite/media&gt;
          Require all granted
          &lt;/Directory&gt;
  
          &lt;Directory /opt/mysite/static&gt;
          Require all granted
          &lt;/Directory&gt;
  
  
      ServerName dev.my_domain.com
      ServerAdmin admin@my_domain.com
      DocumentRoot /var/www/html/dev.my_domain.com
      ErrorLog /var/log/apache2/virtual.host.error.log
      CustomLog /var/log/apache2/virtual.host.access.log combined
      LogLevel warn
  &lt;/VirtualHost&gt;
  </code></pre>
  
  <p>/var/www/html/dev.mydomain.com/.htaccess</p>
  
  <pre><code>RewriteEngine on
  RewriteCond %{HTTP_HOST} ^www\.(.*)
  RewriteRule ^.*$ https://%1/$1 [R=301,L]
  
  RewriteEngine On
  
  RewriteBase /
  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteCond %{REQUEST_FILENAME} !-d
  RewriteCond %{REQUEST_URI} !index
  RewriteCond %{REQUEST_URI} !.*\.(css¦js|html|png)
  
  RewriteRule ^(.*) /index.html
  </code></pre>
  
  <p>The Django server can be run properly from the console without any error but the requests never reach it. </p>
  
  <p>I'm running Python3.6 and Django 1.9.5 (same as the prod server) over Ubuntu 17.04. The .htaccess has been copied from the prod server as it is. The firewall is not blocking the port 8000 for Django. Not running over virtualenvs</p>
  
  <p>Any suggestions of how to face this?</p>