3

I'm trying to deploy Flask app via Apache2 but I'm getting No module named app error. I'm also using virtualenv

planer(Flask app)

(venv)jdoe@jdoe-virtual-machine:/var/www/planer$ la
app.py   forms.py   .git        helpers.py   __init__.py  main.pyc   models.pyc   README.md         setup.cfg  templates  views.py
app.pyc  forms.pyc  .gitignore  helpers.pyc  main.py      models.py  planer.wsgi  requirements.txt  static     venv       views.pyc

planer.conf

<VirtualHost *:80>
        ServerName planer.dev
        ServerAdmin [email protected]
        WSGIScriptAlias / /var/www/planer/planer.wsgi
        <Directory /var/www/planer/planer/>
            Order allow,deny
            Allow from all
        </Directory>
        Alias /static /var/www/planer/static
        <Directory /var/www/planer/static/>
            Order allow,deny
            Allow from all
        </Directory>
        ErrorLog ${APACHE_LOG_DIR}/error.log
        LogLevel warn
        CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>

planer.wsgi

import sys, os
sys.path.insert (0,'/var/www/planer')

    sys.path = [
        '/var/www/planer/venv/lib/python2.7/lib-dynload',
        '/usr/lib/python2.7',
    ]

    activate_this = '/var/www/planer/venv/bin/activate_this.py'
    execfile(activate_this, dict(__file__=activate_this))

    import app as application

error

[Wed Jan 06 09:45:29.781102 2016] [:error] [pid 20727] [client 127.0.0.1:42448] mod_wsgi (pid=20727): Target WSGI script '/var/www/planer/planer.wsgi' cannot be loaded as Python module.
[Wed Jan 06 09:45:29.781137 2016] [:error] [pid 20727] [client 127.0.0.1:42448] mod_wsgi (pid=20727): Exception occurred processing WSGI script '/var/www/planer/planer.wsgi'.
[Wed Jan 06 09:45:29.781208 2016] [:error] [pid 20727] [client 127.0.0.1:42448] Traceback (most recent call last):
[Wed Jan 06 09:45:29.781235 2016] [:error] [pid 20727] [client 127.0.0.1:42448]   File "/var/www/planer/planer.wsgi", line 12, in <module>
[Wed Jan 06 09:45:29.781302 2016] [:error] [pid 20727] [client 127.0.0.1:42448]     import app as application
[Wed Jan 06 09:45:29.781327 2016] [:error] [pid 20727] [client 127.0.0.1:42448] ImportError: No module named app
2
  • in planer.wsgi, use from app import app as application works? Commented Jan 6, 2016 at 13:33
  • Delete all the *.pyc and try from planer.app import app as application works? If still not work, you may show us the content of app.py and __init__.py. Commented Jan 7, 2016 at 1:46

1 Answer 1

2

Make sure the .wsgi file is executable:

sudo chmod a+x planer.wsgi

And try to load it with this:

python /absolute/path/to/planer.wsgi
Sign up to request clarification or add additional context in comments.

2 Comments

What happens when you do python /absolute/path/to/planer.wsgi?
@intelis what was the problem?

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.