mod_wsgi for correct version of python3
Solution 1
I found out how to build mod_wsgi, to be used with Python 3.3.5, on Ubuntu 12.04 LTS.
The trick is to be able to install the python3.3-dev package, which isn't supported on Ubuntu 12.04 LTS ("precise"). There is a 3rd party repository maintained by Felix Krull that makes old and new Python builds available (Kudos to Felix!):
https://launchpad.net/~fkrull/+archive/deadsnakes
To install Felix's repository:
sudo add-apt-repository ppa:fkrull/deadsnakes sudo apt-get update
Before starting to build mod_wsgi we need the apache2-dev package ...
sudo apt-get install apache2-dev
... and get the python3.3-dev package (this actually installs python3.3 as well!)
sudo apt-get install python3.3-dev
Download the mod_wsgi code and build it by providing the path to the freshly installed Python libs and headers (/usr/bin/python3.3). The download link with the latest mod_wsgi release can be found at:
https://github.com/GrahamDumpleton/mod_wsgi/releases
cd /usr/local/src sudo wget https://storage.googleapis.com/google-code-archive-downloads/v2/code.google.com/modwsgi/mod_wsgi-3.4.tar.gz sudo tar -zxvf mod_wsgi-3.4.tar.gz cd mod_wsgi-3.4/ sudo ./configure --with-python=/usr/bin/python3.3 sudo make sudo make install
mod_wsgi.so is placed in /usr/lib/apache2/modules/
Optional step: Since they were missing, I manually (re)created the wsgi.conf and wsgi.load files in /etc/apache2/mods-available (although I didn't have to set any specific option).
wsgi.conf:
<IfModule mod_wsgi.c> # See http://code.google.com/p/modwsgi/wiki/ConfigurationDirectives #WSGISocketPrefix: Configure directory to use for daemon sockets. #WSGISocketPrefix /var/run/apache2/wsgi #WSGIPythonOptimize: Enables basic Python optimisation features. #WSGIPythonOptimize 0 #WSGIPythonPath: Additional directories to search for Python modules, # overriding the PYTHONPATH environment variable. #WSGIPythonPath directory|directory-1:directory-2:... #WSGIPythonEggs: Directory to use for Python eggs cache. #WSGIPythonEggs directory #WSGIRestrictEmbedded: Enable restrictions on use of embedded mode. #WSGIRestrictEmbedded On|Off #WSGIRestrictStdin: Enable restrictions on use of STDIN. #WSGIRestrictStdout: Enable restrictions on use of STDOUT. #WSGIRestrictSignal: Enable restrictions on use of signal(). #WSGIRestrictStdin On #WSGIRestrictStdout On #WSGIRestrictSignal On #WSGIAcceptMutex: Specify type of accept mutex used by daemon processes. #WSGIAcceptMutex default #WSGIImportScript: Specify a script file to be loaded on process start. #WSGIImportScript process-group=name application-group=name #WSGILazyInitialization: Enable/disable lazy initialisation of Python. #WSGILazyInitialization On|Off </IfModule>
wsgi.load:
LoadModule wsgi_module /usr/lib/apache2/modules/mod_wsgi.so
Finally, mod_wsgi can be enabled by creating symbolic links like this:
cd /etc/apache2/mods-enabled sudo ln -s ../mods-available/wsgi.conf wsgi.conf sudo ln -s ../mods-available/wsgi.load wsgi.load
Let me know if this also worked out for you!
Solution 2
I did it in Centos 6.7, just create the file wsgi.conf in : /etc/httpd/conf.d , specify the file path mod_wsgi.so: LoadModule wsgi_module /etc/httpd/modules/mod_wsgi.so After downloading and unzipping the file mod_wsgi_x.x.tar, you need to do something extra after specifying the version of python:
./configure --with-python=/usr/local/bin/python3.4
LD_RUN_PATH=/usr/local/lib make
make install
This will embed the non standard directory location into the mod_wsgi.so, as explained Graham Dumpleton in the following link : GoogleGroups answers
Related videos on Youtube
Comments
-
Hat almost 2 years
I am setting up a Django server on Ubuntu 12.04 LTS, and I am having trouble installing mod-wsgi with the correct version of python. I have built my site locally with python 3.3, and Ubuntu 12.04 comes bundled with python 3.2. I suppose I could, but would rather not just use 3.2 instead of 3.3, so I installed python 3.3 alongside 3.2. I have everything installed for python 3.3 except for mod-wsgi.
On my local machine that is running python3.3 installing libapache2-mod-wsgi-py3 with
sudo apt-get install libapache2-mod-wsgi-py3
installs it for python3.3. However on the Ubuntu server, running that same code installs it for python3.2 such that the web server runs 3.2 and can't find django.Is there a way to disable python3.2, or point the script to install it for python 3.3?
EDIT: after looking into it more, python3.2 was not bundled with ubuntu, instead it was installed with libapache2-mod-wsgi-py3
-
Visionscaper almost 10 yearsCould you share how you solved this, if at all? Thank you!
-
Hat almost 10 years@Visionscaper I ended up just changing the project to use a lower version of Python. The vast majority of the code is the same for both Python versions so it was mostly a matter of re-installing dependencies for the proper Python version
-
Visionscaper almost 10 yearsI found the solution, so I wrote my answer below!
-
-
Dan P. over 9 yearsIf you're installing on CentOS, you may need to update your Makefile. See code.google.com/p/modwsgi/issues/detail?id=299
-
nicorellius almost 9 years@ Visionscaper - this was a life saver - thanks a lot for a great post!
-
Visionscaper almost 9 years@nicorellius you are welcome! This was a pain to figure out so I'm happy I could save you from this agony. :)
-
GMeister about 7 yearsLatest versions of mod_wsgi are now here: github.com/GrahamDumpleton/mod_wsgi/releases I managed to build against Python3.5 using this method. Thanks
-
orangecaterpillar almost 4 yearsThank you for describing how to create wsgi.load and wsgi.conf! I got stuck on that part going through the quick install guide. modwsgi.readthedocs.io/en/develop/user-guides/…
-
dougB almost 4 yearsThanks to @GMeister and @Visionscaper for this insight. This helped with an error I had trying to install
mod-wsgi
using pip3 on a python 3.8 installation. All I had to do was to addapt-get -y install python3.8-dev
and thenpip3 install mod-wsgi
. I didn't need to add the PPA, however.