[PYTHON] About mod_wsgi's "Compiled for ~" warning

Installing mod_wsgi with libapache2-mod-wsgi has one pitfall. Check the Log file with the following command.

vim /var/log/apache2/error.log

I'm sure that such a warning (I think it will be slightly different depending on the environment) is described.

[Mon Feb 13 14:10:22.233656 2017] [wsgi:warn] [pid 10526:tid 139972854908800] mod_wsgi: Compiled for Python/2.7.8.
[Mon Feb 13 14:10:22.233725 2017] [wsgi:warn] [pid 10526:tid 139972854908800] mod_wsgi: Runtime using Python/2.7.9.

This literally says that the version of python that compiles wsgi is different from the version of python that is currently in use.

So, to solve this, reinstall mod_wsgi using pip. However, please Install pyenv before that.

pip install mod_wsgi

Then a file like this will be created

/home/USERNAME/.pyenv/versions/3.5.2/lib/python3.5/site-packages/mod_wsgi/server/mod_wsgi-py35.cpython-35m-x86_64-linux-gnu.so

Modify the config file so that apache2 will read this file.

sudo vim /etc/apache2/mods-available/wsgi.load

Describe the path of the module. Specify the pyenv module you just installed. (Don't forget to change USERNAME)

LoadModule wsgi_module /home/USERNAME/.pyenv/versions/3.5.2/lib/python3.5/site-packages/mod_wsgi/server/mod_wsgi-py35.cpython-35m-x86_64-linux-gnu.so

After doing the above, restart apache2.

sudo service apache2 restart

Now when you access (domain name or IP address) / test_wsgi again, Hello World will be drawn and Warning should not occur.

In addition, when proceeding with ubuntu, a bug in ubuntu (command-not-found fails when user-installed python3 is in PATH) Causes ```Import Error: No module named'_sysconfigdata_m'` ``, so Debian is recommended.

Recommended Posts

About mod_wsgi's "Compiled for ~" warning
About Python for loops
About Python, for ~ (range)
About pgbench for MySQL
About polymorphism for nesting
About Fabric's support for Python 3
About "for _ in range ():" in python
Web scraping for weather warning notifications.