Reputation:
I have two versions of python installed on ubuntu -- 3.7 and 2.7. When I add in a "normal" sites-enabled/000-default.conf
config, it is trying to use python2.7, so it doesn't find the installed application:
WSGIScriptAlias / home/david/data-py/wsgi.py
<VirtualHost *:80>
<Directory /home/david/data-py>
Order allow,deny
Allow from all
Require all granted
</Directory>
</VirtualHost>
ImportError: No module named django.core.wsgi
However, if I specify the python path of my project (which was created using $ virtualenv .
, and I start the file with:
WSGIScriptAlias / home/david/data-py/wsgi.py
WSGIPythonHome /home/david/data-py
Then I get another error:
ImportError: No module named site
What does this mean and how can I get the project installed in apache/wsgi?
Upvotes: 8
Views: 5009
Reputation: 181
I also ran into the same issue about a month ago (caused by python2 vs python3). Here is what I recommend:
Upvotes: 1
Reputation: 1269
I just ran into the exact same issue and it turns out I had installed the wrong version of mod_wsgi on my server (I had the one for python 2 not python 3). You can see what version apache is attempting to use if you look at the tracebacks stored in the apache error.log file (in my case /var/log/apache2/error.log) I solved it as follows (on Ubuntu):
sudo apt-get remove libapache2-mod-python libapache2-mod-wsgi
sudo apt-get install libapache2-mod-wsgi-py3
sudo service apache2 restart
Also I made sure to install the mod_wsgi package into my virtual environment (I'm not sure whether this was necessary). To do this I did the following:
cd <path to my virtual env bin folder>
sudo ./pip3 install mod_wsgi-httpd
sudo ./pip3 install mod-wsgi
Upvotes: 6