I have a VPS running a fresh install of Ubuntu 10.04 LTS. I'm trying to set up a live application using the Flask microframework, but it's giving me trouble. I took notes while I tried to get it running and here's my play-by-play in an effort to pinpoint exactly where I went wrong.
INSTALLATION
http://flask.pocoo.org/docs/installation/#installation
$ adduser myapp
$ sudo apt-get install python-setuptools
$ sudo easy_install pip
$ sudo pip install virtualenv
/home/myapp/
-- www/
$ sudo pip install virtualenv
/home/myapp/
-- www/
-- env/
$ . env/bin/activate
$ easy_install Flask
MOD_WSGI
http://flask.pocoo.org/docs/deploying/mod_wsgi/
$ sudo apt-get install apache2
$ sudo apt-get install libapache2-mod-wsgi
Creating WSGI file
$ nano /home/myapp/www/myapp.wsgi
--myapp.wsgi contents:--------------------------
activate_this = '/home/myapp/env/bin/activate_this.py'
execfile(activate_this, dict(__file__=activate_this))
from myapp import app as application
/home/myapp/
-- www/
-- myapp.wsgi
-- env/
Configuring Apache
$ nano /etc/apache2/sites-available/myapp.com
-----myapp.com file contents ---------------------
<VirtualHost *:80>
ServerName myapp.com
WSGIDaemonProcess myapp user=myapp group=myapp threads=5 python-path=/home/myapp/env/lib/python2.6/site-packages
WSGIScriptAlias / /home/myapp/www/myapp.wsgi
<Directory /home/myapp/www>
WSGIProcessGroup myapp
WSGIApplicationGroup %{GLOBAL}
Order deny,allow
Allow from all
</Direc开发者_C百科tory>
</VirtualHost>
Enable the virtual host file I just created
$ cd /etc/apache2/sites-enabled
$ ln -s ../sites-available/myapp.com
Restart Apache
$ /etc/init.d/apache2 restart
Servers me a 500 server error page. Here's the latest error log:
mod_wsgi (pid=3514): Target WSGI script '/home/myapp/www/myapp.wsgi' cannot be loaded as Python module.
mod_wsgi (pid=3514): Exception occurred processing WSGI script '/home/myapp/www/myapp.wsgi'.
Traceback (most recent call last):
File "/home/myapp/www/myapp.wsgi", line 4, in <module>
from myapp import app as application
ImportError: No module named myapp
The errors allude that it's something strikingly obvious, but I'm quite lost.
Obviously, it cannot find your "myapp" package. You should add it to the path in your myapp.wsgi file like this:
import sys
sys.path.append(DIRECTORY_WHERE_YOUR_PACKAGE_IS_LOCATED)
from myapp import app
Also, if myapp module is a package, you should put and empty __init__.py file into its directory.
Edit line sys.path.append, it needs to be a string.
import sys
sys.path.append('directory/where/package/is/located')
Notice the single quotes.
加载中,请稍侯......
精彩评论