No module named 'django' when deploying django with apache2 wsgi

So I want to deploy my django application on an Ubuntu 16.04 server using Apache2.

I followed the steps in this digital ocean tutorial, though it is for Ubuntu 14.04 I guess it would work as well. I use Python 3.5 and instead of creating the project on the server I just cloned my git repository. The server works just fine when I activate my virtual environment and use the runserver command. Now, i wanted to use Apache2 for the real deployment. I have Apache/2.4.18 (Ubuntu) installed. I also used pip3 for everything (the virtual env and installment of the requirements.txt). When I started the apache2 server, I get HTTP Status 500 and the error.log file shows the following:

[wsgi:info] mod_wsgi (pid=8996): Attach interpreter ''. [wsgi:info] mod_wsgi (pid=8996): Adding '(null)' to path. [wsgi:error] mod_wsgi (pid=8996): Call to 'site.addsitedir()' failed for '(null)', stopping. [wsgi:info] mod_wsgi (pid=8996): Adding '/home/user/ProjectDir/env/lib/python3.5/site-packages' to path. [wsgi:error] mod_wsgi (pid=8996): Call to 'site.addsitedir()' failed for '/home/user/ProjectDir/env/lib/python3.5/site-packages'. [wsgi:info] mod_wsgi (pid=8996): Create interpreter 'www.projectName.com|'. [wsgi:info] mod_wsgi (pid=8996): Adding '(null)' to path. [wsgi:error] mod_wsgi (pid=8996): Call to 'site.addsitedir()' failed for '(null)', stopping. [wsgi:info] mod_wsgi (pid=8996): Adding '/home/user/ProjectDir/env/lib/python3.5/site-packages' to path. [wsgi:error] mod_wsgi (pid=8996): Call to 'site.addsitedir()' failed for '/home/user/ProjectDir/env/lib/python3.5/site-packages'.  [wsgi:error] mod_wsgi (pid=8996): Target WSGI script '/home/user/ProjectDir/projectName/wsgi.py' cannot be loaded as Python module. [wsgi:error] mod_wsgi (pid=8996): Exception occurred processing WSGI script '/home/user/ProjectDir/projectName/wsgi.py'.   Traceback (most recent call last):   File "/home/user/ProjectDir/projectName/wsgi.py", line 14, in <module>   from django.core.wsgi import get_wsgi_application   ImportError: No module named 'django' 

This is the log output for one server request. The last part appears two times for one request.

My /etc/apache2/sites-available/000-default.conf:

<VirtualHost *:80>     ServerName www.projectName.com      WSGIScriptAlias / /home/user/ProjectDir/projectName/wsgi.py     WSGIDaemonProcess projectName.com user=user group=www-data        python-path=/home/user/ProjectDir:/home/user/ProjectDir/env/lib/python3.5/site-packages     WSGIProcessGroup projectName.com      Alias /static/ /home/user/ProjectDir/static/     <Directory /home/user/ProjectDir/static>             Require all granted     </Directory>     <Directory /home/user/ProjectDir/projectName>             <Files wsgi.py>                     Require all granted             </Files>     </Directory> </VirtualHost> 

Note that I get the same exception when I try to run the server via python3 manage.py runserver without activating my virtualenv, so I conclude he can't find or access the virtualenv folder for some reason. The "side.addsitedir()" also fails for that exact path. But the path exists 100%. I also checked for permission problems, but everything on the way down to the virtualenv folder has permissions for users and groups to rwx - I also added www-data to my "user" group.

I don't want to use my django application without a virtualenv, because I plan to deploy another django application on that server. Also I tried the "dirty fix" by adding the path to the site-packages folder inside the wsgi.py by using

sys.path.append("/home/user/ProjectDir/env/lib/python3.5/site-packages") 

This did not help. I hope someone can help me, I can provide additional information if needed.

Replay

Category: django Time: 2016-07-29 Views: 1

Related post

iOS development

Android development

Python development

JAVA development

Development language

PHP development

Ruby development

search

Front-end development

Database

development tools

Open Platform

Javascript development

.NET development

cloud computing

server

Copyright (C) avrocks.com, All Rights Reserved.

processed in 0.206 (s). 12 q(s)