Reputation: 311
I am having a problem deploying a flask application on apache2 using mod_wsgi. Error log and config files follow. I always get internal server error. This is very similar to How to solve import errors while trying to deploy Flask using WSGI on Apache2 but for some reason the solution proposed there did not work here.
apache error log
[Thu Aug 27 12:06:30.366817 2015] [:error] [pid 9330:tid 140623686452992] [remote 2.239.9.178:64904] mod_wsgi (pid=9330): Target WSGI script '/var/www/bitcones/bitcones.wsgi' cannot be loaded as Python module.
[Thu Aug 27 12:06:30.366867 2015] [:error] [pid 9330:tid 140623686452992] [remote 2.239.9.178:64904] mod_wsgi (pid=9330): Exception occurred processing WSGI script '/var/www/bitcones/bitcones.wsgi'.
[Thu Aug 27 12:06:30.366894 2015] [:error] [pid 9330:tid 140623686452992] [remote 2.239.9.178:64904] Traceback (most recent call last):
[Thu Aug 27 12:06:30.366913 2015] [:error] [pid 9330:tid 140623686452992] [remote 2.239.9.178:64904] File "/var/www/bitcones/bitcones.wsgi", line 4, in <module>
[Thu Aug 27 12:06:30.366969 2015] [:error] [pid 9330:tid 140623686452992] [remote 2.239.9.178:64904] from bitcones import bitcones as application
[Thu Aug 27 12:06:30.366981 2015] [:error] [pid 9330:tid 140623686452992] [remote 2.239.9.178:64904] File "/var/www/bitcones/bitcones/bitcones.py", line 6, in <module>
[Thu Aug 27 12:06:30.367045 2015] [:error] [pid 9330:tid 140623686452992] [remote 2.239.9.178:64904] from analysis import cone as _cone, flow
[Thu Aug 27 12:06:30.367056 2015] [:error] [pid 9330:tid 140623686452992] [remote 2.239.9.178:64904] File "/var/www/bitcones/bitcones/analysis/cone.py", line 5, in <module>
[Thu Aug 27 12:06:30.367121 2015] [:error] [pid 9330:tid 140623686452992] [remote 2.239.9.178:64904] from analysis.statistics import purity_statistics
[Thu Aug 27 12:06:30.367139 2015] [:error] [pid 9330:tid 140623686452992] [remote 2.239.9.178:64904] ImportError: No module named analysis.statistics
bitcones.wsgi
#!/usr/bin/python
import sys
sys.path.insert(0,"/var/www/bitcones")
from bitcones import bitcones as application
apache virtual host file
<VirtualHost *:80>
ServerName <my-server-name>
ServerAdmin <my-email>
WSGIDaemonProcess bitcones user=<my-username> group=<my-username> threads=5
WSGIScriptAlias / /var/www/bitcones/bitcones.wsgi
<Directory /var/www/bitcones>
WSGIProcessGroup bitcones
WSGIApplicationGroup %{GLOBAL}
Order deny,allow
Allow from all
</Directory>
part of my app tree (everything is under /var/www/bitcones/)
├── bitcones
│ ├── analysis
│ │ ├── <some_files>
│ │ └── statistics
│ │ │ ├── <some_files>
│ ├── bitcones.py
│ ├── static
│ │ ├── <some static content>
│ └── templates
│ └── <my_templates>.html
└── bitcones.wsgi
This should be sufficient to figure out why I'm having this import error. If any other file/configuration is needed please ask. I'm loosing my mind.
Thanks!
EDIT: I just want to add that I was following this guide: http://flask.pocoo.org/docs/0.10/deploying/mod_wsgi/
Upvotes: 2
Views: 997
Reputation: 2594
You set the Python version that mod_wsgi uses when you install libapache2-mod-wsgi (python 2) or libapache2-mod-wsgi-py3 (python 3). I would guess you're on Python 2 from what you describe, since using python 3 is a more deliberate choice than 2. I don't think that's your problem, though. I think it's an import problem, like Graham said.
I recommend using from bitcones.analysis.statistics import purity_statistics
for your import statement.
Upvotes: 1