What to do if you get the error Target WSGI script'/var/www/xxx/xxx.wsgi' cannot be loaded as python module

When creating and publishing a simple application using Python, the web server is Apache, and the web application framework is [flask](https://flask.palletsprojects. I think the combination of com / en / 1.1.x /) is common. And WSGI (Web Server Gateway Interface) that connects Apache and flask will use mod_wsgi.

Create an instance of EC2 on AWS, install Apache, and run the app written in flask! I also installed mod_wsgi so it should work fine! I was thinking, but sometimes I get the following error:

mod_wsgi (pid=8711): Target WSGI script '/var/www/xxx/xxx.wsgi' cannot be loaded as Python module.
mod_wsgi (pid=8711): Exception occurred processing WSGI script '/var/www/xxx/xxx.wsgi'.

Why did you install mod_wsgi? However, the conclusion is that mod_wsgi installed by yum install mod_wsgi is old and only compatible with Python 2 series (in the case of Cent OS series OS).

So if you installed mod_wsgi with yum install mod_wsgi, you need to uninstall it with yum remove mod_wsgi. After that, if you install via pip like pip install mod_wsgi, you can install mod_wsgi corresponding to Python3 series.

For example, if you are using venv to create a Python 3.7 virtual environment, running the above pip command will

$VENVHOME/lib/python3.7/site-packages/mod_wsgi/server/mod_wsgi-py37.cpython-37m-x86_64-linux-gnu.so

A shared library file for mod_wsgi will be created in this location. Then, if you write the following in the Apache conf file, mod_wsgi corresponding to Python3 will be executed.

LoadModule wsgi_module $VENVHOME/lib/python3.7/site-packages/mod_wsgi/server/mod_wsgi-py37.cpython-37m-x86_64-linux-gnu.so

Congratulations, congratulations. Even so, there are many pitfalls with the Python version ...

Recommended Posts

What to do if you get the error Target WSGI script'/var/www/xxx/xxx.wsgi' cannot be loaded as python module
What to do if you get Swagger-codegen in python and Import Error: No module named
What to do if you get an error when installing python with pyenv
What to do if the package dependency cannot be repaired
What to do if you get an OpenSSL error when installing Python 2 with pyenv
What to do if you get an error when importing matplotlib in Python (Mac)
What to do if you get the error ʻERR_FEATURE_UNAVAILABLE_ON_PLATFORM` when using ts-node-dev on Linux
What to do if you get a minus zero in Python
What to do if you get the error RuntimeError: Python is not installed as a framework when trying to use matplitlib and pylab in Python 3.3
What to do if PyAudio cannot be installed on Python 3.7, 3.8, 3.9 on Windows
What to do if you get the error "Error: opencv3: Does not support building both Python 2 and 3 wrappers" when installing openCV 3
[Python] If you create a file with the same name as the module to be imported, an Attribute Error will occur.
What to do if you get an error saying c compiler cannot create executables in configure
What to do if you get an error when trying to load mnist
What to do if you get an error when installing Dlib (Ubuntu)
What to do if pip cannot be installed
What to do if you get "The session could not be opened" when installing CentOS on VirtualBox
What to do if you get an error like'Qstring' has already been set to version 1 using mne python
What to do if you get a "Wrong Python Platform" warning when using Python with the NetBeans IDE
What to do if you get angry with "Value Error: unknown local: UTF-8" in python manage.py syncdb
When I import TensorFlow to Python, I get "Import Error: DLL load failed: The specified module cannot be found."
What to do if you get a "No versions found" error in pipenv
What to do if you get "Python not configured." Using PyDev in Eclipse
What to do if you get the message "" ~ .pkg "is corrupted and cannot be opened" when installing wxPython on Mac OS X
No module named What to do if you get'libs.resources'
ModuleNotFoundError: No module What to do if you get'tensorflow.contrib'
What to do if you get an "unknown service" error from your gRPC server
What to do if the Microsoft Store opens even if you run python on Windows
What to do if the print command itself causes an error in Maya python
What to do if you get "(35,'SSL connect error')" in pycurl (one of them)
What to do if you can't hit the arrow keys in the Python interactive console
What to do if you run python in IntelliJ and end with an error
What to do if you get "coverage unknown" in Coveralls
What to do if you can't log in as root
[* CentOS 6.10] What to do if you cannot add the IUS Community Project repository on CentOS 6.5 (VirtualBox)
What to do if you get an error when running "certbot renew" in CakePHP environment
What to do if ʻObject arrays cannot be loaded when allow_pickle = False` occurs in numpy.load ()
What to do if you get an Undefined error when trying to use pip with pyenv
What to do if you can't install pyaudio with pip #Python
What to do if you can't use the trash in Lubuntu 18.04.
What to do when you get "I can't see the site !!!!"
What to do if you get angry with'vertices' must be a 2D list ... in matplotlib arrow
What to do if you get a must override `get_config` error when trying to model.save in Keras
What to do if you get `locale.Error: unsupported locale setting` when getting the day of the week from a date in Python
If you want a singleton in python, think of the module as a singleton
What to do if you couldn't send an email to Yahoo with Python.
What to do if you can't use scikit grid search in Python
What to do if you get lost in file reference with FileNotFoundError
What to do if you get angry in TensorFlow v2 without attribute'app'
What to do if you get stuck during Anaconda installation on Linux
What to do if the server doesn't start with python manage.py runserver
What to do if you get a TypeError with numpy min, max
What to do if you get Could not fetch URL 443 with pip
Switch the module to be loaded for each execution environment in Python
What happens if you do "import A, B as C" in Python?
What to do if you get a Permission denied (public key) error when trying to pull on Github
[Python] What to do if you get a ModuleNotFoundError when importing pandas using Jupyter Notebook in Anaconda
What to do if you get an error when trying to send a message in tasks.loop () immediately after startup
[Python] What to do if an error occurs in pip (pyinstaller, pyautogui, etc.)
What to do if you get angry with swapon failed: Operation not permitted
What to do if you get the error Input contains NaN, infinity or a value too large for dtype ('float64'). In machine learning