看到我运行 Flask 的尝试有什么问题吗? (mod_wsgi + virtualenv)
我有一个运行全新安装的 Ubuntu 10.04 LTS 的 VPS。我正在尝试使用 Flask 微框架设置一个实时应用程序,但这给我带来了麻烦。当我尝试让它运行时,我做了笔记,这是我的逐个操作,以准确找出我出错的地方。
安装
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
创建 WSGI 文件
$ 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/
配置 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
</Directory>
</VirtualHost>
启用我刚刚创建的虚拟主机文件
$ cd /etc/apache2/sites-enabled
$ ln -s ../sites-available/myapp.com
重新启动 Apache
$ /etc/init.d/apache2 restart
服务器,出现 500 服务器错误页面。这是最新的错误日志:
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
这些错误暗示这是非常明显的事情,但我很迷失。
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
</Directory>
</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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
显然,它找不到您的“
myapp
”包。您应该将其添加到myapp.wsgi
文件中的路径,如下所示:此外,如果
myapp
模块是一个包,您应该放置并清空__init__.py
文件放入其目录中。Obviously, it cannot find your "
myapp
" package. You should add it to the path in yourmyapp.wsgi
file like this:Also, if
myapp
module is a package, you should put and empty__init__.py
file into its directory.编辑
sys.path.append
行,它需要是一个字符串。注意单引号。
Edit line
sys.path.append
, it needs to be a string.Notice the single quotes.