1

我收到这个错误。任何想法?谢谢!

PS。我还尝试以多种方式降级/升级 Flask-SQLAlchemy 和 SQLAlchemy,但没有成功。并尝试在 python shell(激活的 virtualenv)中导入 SQLAlchemy 行,它可以正确运行而没有错误。

这是我的点冻结:

Flask==0.10.1
Flask-SQLAlchemy==1.0
Jinja2==2.7.1
MarkupSafe==0.18
MySQL-python==1.2.4
SQLAlchemy==0.9.0dev
Werkzeug==0.9.4
itsdangerous==0.23
wsgiref==0.1.2

阿帕奇错误日志:

[Tue Oct 22 12:08:18 2013] [error] [client 10.1.100.54] Traceback (most recent call last):
[Tue Oct 22 12:08:18 2013] [error] [client 10.1.100.54]   File "/var/www/html/hello/hello.wsgi", line 11, in <module>
[Tue Oct 22 12:08:18 2013] [error] [client 10.1.100.54]     from hello import app as application
[Tue Oct 22 12:08:18 2013] [error] [client 10.1.100.54]   File "/var/www/html/hello/hello.py", line 8, in <module>
[Tue Oct 22 12:08:18 2013] [error] [client 10.1.100.54]     from flask.ext.sqlalchemy import SQLAlchemy
[Tue Oct 22 12:08:18 2013] [error] [client 10.1.100.54]   File "/var/www/html/hello/venv/lib/python2.7/site-packages/flask/exthook.py", line 81, in load_module
[Tue Oct 22 12:08:18 2013] [error] [client 10.1.100.54]     reraise(exc_type, exc_value, tb.tb_next)
[Tue Oct 22 12:08:18 2013] [error] [client 10.1.100.54]   File "/var/www/html/hello/venv/lib/python2.7/site-packages/flask_sqlalchemy/__init__.py", line 24, in <module>
[Tue Oct 22 12:08:18 2013] [error] [client 10.1.100.54]     from sqlalchemy import orm, event
[Tue Oct 22 12:08:18 2013] [error] [client 10.1.100.54] ImportError: cannot import name event

你好.wsgi:

activate_this = '/var/www/html/hello/venv/bin/activate_this.py'
execfile(activate_this, dict(__file__=activate_this))
import sys, site
site.addsitedir('/var/www/html/hello/venv/lib/python2.7/site-packages')
sys.path.insert(0, '/var/www/html/hello')
from hello import app as application

你好.py:

from flask import Flask
import time, os
from flask.ext.sqlalchemy import SQLAlchemy

app = Flask(__name__)
app.config['SQLALCHEMY_DATABASE_URI'] = 'mysql://test:11111@10.1.17.197'
db = SQLAlchemy(app)
...

以及 apache 虚拟主机文件的配置:

WSGISocketPrefix run/wsgi
WSGIPythonPath /var/www/html/hello:/var/www/html/hello/venv/lib/python2.7/site-packages

<VirtualHost *>
   ServerName example.com

   WSGIDaemonProcess yourapplication user=apache group=root threads=5
   WSGIScriptAlias /hello /var/www/html/hello/hello.wsgi

   <Directory /var/www/html/hello>
       WSGIProcessGroup yourapplication
       WSGIApplicationGroup %{GLOBAL}
       Order deny,allow
       Allow from all
   </Directory>
</VirtualHost>
4

1 回答 1

0

我遇到了同样的问题,使用以下代码段解决了它:

ALLDIRS = ['/var/www/MarkerDB/']

import sys 
import site 

# Remember original sys.path.
prev_sys_path = list(sys.path) 

# Add each new site-packages directory.
for directory in ALLDIRS:
  site.addsitedir(directory)

# Reorder sys.path so new directories at the front.
new_sys_path = [] 
for item in list(sys.path): 
    if item not in prev_sys_path: 
        new_sys_path.append(item) 
        sys.path.remove(item) 
sys.path[:0] = new_sys_pat

来源:http ://code.google.com/p/modwsgi/wiki/VirtualEnvironments#Application_Environments

于 2013-11-14T03:13:54.137 回答