I moved my Django project from Python 2.7 to Python 3.6.
Since then, I can't get my project up & running, as Apache complains as follows (full output after a restart):
[mpm_prefork:notice] [pid 2340] AH00173: SIGHUP received. Attempting to restart
[:notice] [pid 25019] FastCGI: process manager initialized (pid 25019)
[:warn] [pid 2340] mod_wsgi: Compiled for Python/3.4.0.
[:warn] [pid 2340] mod_wsgi: Runtime using Python/3.4.3.
[mpm_prefork:notice] [pid 2340] AH00163: Apache/2.4.7 (Ubuntu) mod_fastcgi/mod_fastcgi-SNAP-0910052141 PHP/5.5.9-1ubuntu4.21 OpenSSL/1.0.1f mod_wsgi/3.4 Python/3.4.3 configured -- resuming normal operations
[core:notice] [pid 2340] AH00094: Command line: '/usr/sbin/apache2'
[:error] [pid 25025] [client 10.0.10.117:49933] mod_wsgi (pid=25025): Target WSGI script '/home/myuser/projects/myproject/myproject_project/wsgi.py' cannot be loaded as Python module.
[:error] [pid 25025] [client 10.0.10.117:49933] mod_wsgi (pid=25025): Exception occurred processing WSGI script '/home/myuser/projects/myproject/myproject_project/wsgi.py'.
[:error] [pid 25025] [client 10.0.10.117:49933] Traceback (most recent call last):
[:error] [pid 25025] [client 10.0.10.117:49933] File "/home/myuser/projects/myproject/myproject_project/wsgi.py", line 29, in <module>
[:error] [pid 25025] [client 10.0.10.117:49933] application = get_wsgi_application()
[:error] [pid 25025] [client 10.0.10.117:49933] File "/home/myuser/.virtualenvs/myproject-3.6/lib/python3.6/site-packages/django/core/wsgi.py", line 13, in get_wsgi_application
[:error] [pid 25025] [client 10.0.10.117:49933] django.setup(set_prefix=False)
[:error] [pid 25025] [client 10.0.10.117:49933] File "/home/myuser/.virtualenvs/myproject-3.6/lib/python3.6/site-packages/django/__init__.py", line 27, in setup
[:error] [pid 25025] [client 10.0.10.117:49933] apps.populate(settings.INSTALLED_APPS)
[:error] [pid 25025] [client 10.0.10.117:49933] File "/home/myuser/.virtualenvs/myproject-3.6/lib/python3.6/site-packages/django/apps/registry.py", line 85, in populate
[:error] [pid 25025] [client 10.0.10.117:49933] app_config = AppConfig.create(entry)
[:error] [pid 25025] [client 10.0.10.117:49933] File "/home/myuser/.virtualenvs/myproject-3.6/lib/python3.6/site-packages/django/apps/config.py", line 116, in create
[:error] [pid 25025] [client 10.0.10.117:49933] mod = import_module(mod_path)
[:error] [pid 25025] [client 10.0.10.117:49933] File "/usr/lib/python3.4/importlib/__init__.py", line 109, in import_module
[:error] [pid 25025] [client 10.0.10.117:49933] return _bootstrap._gcd_import(name[level:], package, level)
[:error] [pid 25025] [client 10.0.10.117:49933] File "<frozen importlib._bootstrap>", line 2254, in _gcd_import
[:error] [pid 25025] [client 10.0.10.117:49933] File "<frozen importlib._bootstrap>", line 2237, in _find_and_load
[:error] [pid 25025] [client 10.0.10.117:49933] File "<frozen importlib._bootstrap>", line 2226, in _find_and_load_unlocked
[:error] [pid 25025] [client 10.0.10.117:49933] File "<frozen importlib._bootstrap>", line 1200, in _load_unlocked
[:error] [pid 25025] [client 10.0.10.117:49933] File "<frozen importlib._bootstrap>", line 1129, in _exec
[:error] [pid 25025] [client 10.0.10.117:49933] File "<frozen importlib._bootstrap>", line 1471, in exec_module
[:error] [pid 25025] [client 10.0.10.117:49933] File "<frozen importlib._bootstrap>", line 321, in _call_with_frames_removed
[:error] [pid 25025] [client 10.0.10.117:49933] File "/home/myuser/.virtualenvs/myproject-3.6/lib/python3.6/site-packages/django/contrib/postgres/apps.py", line 7, in <module>
[:error] [pid 25025] [client 10.0.10.117:49933] from .signals import register_hstore_handler
[:error] [pid 25025] [client 10.0.10.117:49933] File "/home/myuser/.virtualenvs/myproject-3.6/lib/python3.6/site-packages/django/contrib/postgres/signals.py", line 1, in <module>
[:error] [pid 25025] [client 10.0.10.117:49933] from psycopg2 import ProgrammingError
[:error] [pid 25025] [client 10.0.10.117:49933] File "/home/myuser/.virtualenvs/myproject-3.6/lib/python3.6/site-packages/psycopg2/__init__.py", line 50, in <module>
[:error] [pid 25025] [client 10.0.10.117:49933] from psycopg2._psycopg import ( # noqa
[:error] [pid 25025] [client 10.0.10.117:49933] ImportError: No module named 'psycopg2._psycopg'
However when I try to load the problem module (psycopg2) in the virtualenv manually, it is perfectly possible to do so:
(myproject-3.6)myuser@Server:$ python
Python 3.6.0 (default, Jan 13 2017, 00:00:00)
[GCC 4.8.4] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import psycopg2
>>>
I'm using WSGI. Its file content is as follows:
import os
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "my_project.settings")
from django.core.wsgi import get_wsgi_application
application = get_wsgi_application()
My main Apache2 site config is as follows (there is a section for the admin/ as well):
WSGIApplicationGroup %{GLOBAL}
WSGIScriptAlias / /home/myuser/projects/myproject/myproject_project/wsgi.py
#WSGIPythonPath /home/myuser/projects/myproject:/home/myuser/.virtualenvs/myproject/local/lib/python2.7/site-packages
WSGIPythonPath /home/myuser/projects/myproject:/home/myuser/.virtualenvs/myproject-3.6/lib/python3.6/site-packages
<Directory /home/myuser/projects/myproject/myproject_project>
SSLRequireSSL
<Files wsgi.py>
Order deny,allow
Require all granted
</Files>
</Directory>
I've installed the python3-psycopg2
package through apt-get
. And of course my virtualenv has psycopg2 installed as well:
(myproject-3.6)myuser@Server:~/projects/$ pip freeze | grep psy
psycopg2==2.7
What is going wrong?
I'm using Ubuntu 14.04 LTS.