SineCo
SineCo

Reputation: 33

How to fix different python versions errors?

I have 3 different versions:

2.7, 3.5, 3.6

To install Flask and run Hello World, I followed this tutorial step by step Flask But I changed this command ln -sf /usr/bin/python3 /usr/bin/python To:

ln -sf /usr/bin/python3.6 /usr/bin/python

and now it is giving me this error in the log:

[Fri Apr 20 09:21:19.808894 2018] [mpm_event:notice] [pid 25752:tid 139701099587456] AH00489: Apache/2.4.18 (Ubuntu) configured -- resuming normal operations
[Fri Apr 20 09:21:19.808980 2018] [core:notice] [pid 25752:tid 139701099587456] AH00094: Command line: '/usr/sbin/apache2'
[Fri Apr 20 09:21:32.207980 2018] [mpm_event:notice] [pid 25752:tid 139701099587456] AH00491: caught SIGTERM, shutting down
[Fri Apr 20 09:21:33.319127 2018] [wsgi:warn] [pid 26013:tid 140126648674176] mod_wsgi: Compiled for Python/3.5.1+.
[Fri Apr 20 09:21:33.319205 2018] [wsgi:warn] [pid 26013:tid 140126648674176] mod_wsgi: Runtime using Python/3.5.2.
[Fri Apr 20 09:21:33.320002 2018] [mpm_event:notice] [pid 26013:tid 140126648674176] AH00489: Apache/2.4.18 (Ubuntu) mod_wsgi/4.3.0 Python/3.5.2 configured -- resuming normal operations
[Fri Apr 20 09:21:33.320024 2018] [core:notice] [pid 26013:tid 140126648674176] AH00094: Command line: '/usr/sbin/apache2'
[Fri Apr 20 09:28:37.277698 2018] [mpm_event:notice] [pid 26013:tid 140126648674176] AH00491: caught SIGTERM, shutting down
[Fri Apr 20 09:28:38.336490 2018] [wsgi:warn] [pid 10166:tid 140069159778176] mod_wsgi: Compiled for Python/3.5.1+.
[Fri Apr 20 09:28:38.336542 2018] [wsgi:warn] [pid 10166:tid 140069159778176] mod_wsgi: Runtime using Python/3.5.2.
[Fri Apr 20 09:28:38.337272 2018] [mpm_event:notice] [pid 10166:tid 140069159778176] AH00489: Apache/2.4.18 (Ubuntu) mod_wsgi/4.3.0 Python/3.5.2 configured -- resuming normal operations
[Fri Apr 20 09:28:38.337294 2018] [core:notice] [pid 10166:tid 140069159778176] AH00094: Command line: '/usr/sbin/apache2'
[Fri Apr 20 09:29:08.182299 2018] [mpm_event:notice] [pid 10166:tid 140069159778176] AH00491: caught SIGTERM, shutting down
[Fri Apr 20 09:29:09.224956 2018] [wsgi:warn] [pid 10290:tid 140446016731008] mod_wsgi: Compiled for Python/3.5.1+.
[Fri Apr 20 09:29:09.225001 2018] [wsgi:warn] [pid 10290:tid 140446016731008] mod_wsgi: Runtime using Python/3.5.2.
[Fri Apr 20 09:29:09.225714 2018] [mpm_event:notice] [pid 10290:tid 140446016731008] AH00489: Apache/2.4.18 (Ubuntu) mod_wsgi/4.3.0 Python/3.5.2 configured -- resuming normal operations
[Fri Apr 20 09:29:09.225740 2018] [core:notice] [pid 10290:tid 140446016731008] AH00094: Command line: '/usr/sbin/apache2'
[Fri Apr 20 09:29:42.886467 2018] [wsgi:error] [pid 10294:tid 140445919373056] [client 134.193.130.121:56046] mod_wsgi (pid=10294): Target WSGI script '/var/www/FlaskApp/flaskapp.wsgi' cannot be loaded as Python modul$
[Fri Apr 20 09:29:42.886529 2018] [wsgi:error] [pid 10294:tid 140445919373056] [client 134.193.130.121:56046] mod_wsgi (pid=10294): Exception occurred processing WSGI script '/var/www/FlaskApp/flaskapp.wsgi'.

What I understood is that Flask module was not found. I changed the version again, and now I am so lost. What to do to get "Hello World" Work?

Upvotes: 0

Views: 3762

Answers (1)

Graham Dumpleton
Graham Dumpleton

Reputation: 58523

Those logs do not show the actual error and why your app doesn't load. You need to see the messages after what you included.

The warning about Python patch level can be ignored, as is documented at:

If you want to use Python 3.6, you must use a mod_wsgi installation which has been compiled for 3.6. There is no way to force mod_wsgi compiled for 3.5 to use 3.6.

You should uninstall the system package for mod_wsgi. Then compile mod_wsgi from source code yourself against the Python 3.6 and use it. Easiest to use pip install method:

Then run mod_wsgi-express module-config to get config to include in Apache configuration. Or use mod_wsgi-express start-server if just doing local development. See the documentation at that link.

You can not use pyenv with mod_wsgi unless you take the extra steps to ensure pyenv generates shared libraries for Python, which it doesn't do by default.

Upvotes: 1

Related Questions