1

I am trying to run my Flask application with mod_wsgi, but mod_wsgi gives the error Target WSGI script '/var/www/FDApp/fdapp.wsgi' cannot be loaded as Python module.

mod_wsgi: Compiled for Python/3.5.1+.
mod_wsgi: Runtime using Python/3.5.2.
mod_wsgi (pid=4142): Target WSGI script '/var/www/FDApp/fdapp.wsgi' cannot be loaded as Python module.
mod_wsgi (pid=4142): Exception occurred processing WSGI script '/var/www/FDApp/fdapp.wsgi'.
Traceback (most recent call last):
  File "/var/www/FDApp/fdapp.wsgi", line 6, in <module>
    from main import app as application
  File "/var/www/FDApp/main.py", line 15, in <module>
    import label_faces
  File "/var/www/FDApp/label_faces.py", line 2, in <module>
    import mxnet as mx
ImportError: No module named 'mxnet'

The mxnet package is installed in python3.5. All the packages are installed in this folder.

        <VirtualHost *:80>
                        ServerName 127.0.0.1
                        WSGIDaemonProcess fdapp user=www-data group=www-data threads=5  python-path=/home/teja/.local/lib/python3.5/site-packages
                        WSGIScriptAlias /fdapp /var/www/FDApp/fdapp.wsgi process-group=fdapp application-group=%{GLOBAL}
                        <Directory /var/www/FDApp/>
                                WSGIProcessGroup fdapp
                                WSGIApplicationGroup %{GLOBAL}
                                WSGIScriptReloading On
                                Order allow,deny
                                Allow from all
                        </Directory>

                        Alias /static1 /var/www/FDApp/static
                        <Directory /var/www/FDApp/static/>
                                Order allow,deny
                                Allow from all
                        </Directory>
                        ErrorLog ${APACHE_LOG_DIR}/error.log
                        LogLevel warn
                        CustomLog ${APACHE_LOG_DIR}/access.log combined
        </VirtualHost>

1 Answer 1

2

Change:

WSGIScriptAlias /fdapp /var/www/FDApp/fdapp.wsgi

to:

WSGIScriptAlias /fdapp /var/www/FDApp/fdapp.wsgi \
    process-group=fdapp application-group=%{GLOBAL}

You aren't telling mod_wsgi to run your application in the daemon process group.

Also, using:

python-home=/home/teja/.local/lib/python3.5/site-packages

is wrong.

For per user site-packages use:

python-path=/home/teja/.local/lib/python3.5/site-packages
Sign up to request clarification or add additional context in comments.

2 Comments

I have change python-home to python-path.....and changed that WSGIScriptAlias tooo...But same error.Do i need to change any other?
The other problem is that the directory /home/teja is likely not accessible to the user that Apache runs as. You are better of creating a Python virtual environment under /var/www/FDap and install packages into that. Then use python-home to refer to the root of the Python virtual environment. See modwsgi.readthedocs.io/en/develop/user-guides/…

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.