Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/318.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/apache/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/xpath/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python mod_wsgi、apache和sqlalchemy的语法类模板(元类=_TemplateMetaclass)无效_Python_Apache_Sqlalchemy_Mod Wsgi_Bottle - Fatal编程技术网

Python mod_wsgi、apache和sqlalchemy的语法类模板(元类=_TemplateMetaclass)无效

Python mod_wsgi、apache和sqlalchemy的语法类模板(元类=_TemplateMetaclass)无效,python,apache,sqlalchemy,mod-wsgi,bottle,Python,Apache,Sqlalchemy,Mod Wsgi,Bottle,我有一个脚本,可以在其中导入: from bottle import route, request from sqlalchemy import create_engine, MetaData from sqlalchemy.ext.declarative import declarative_base from sqlalchemy.orm import sessionmaker from sqlalchemy import Table, Column, Integer import xml.

我有一个脚本,可以在其中导入:

from bottle import route, request
from sqlalchemy import create_engine, MetaData
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy.orm import sessionmaker
from sqlalchemy import Table, Column, Integer
import xml.etree.cElementTree as ET 

@route('/getmember')
def get_member():
    pass
run(host='localhost', port=8080, reloader=True)
我可以使用瓶子内置web服务器成功运行此脚本:
$python3.2 getmember.py

完成后,我想使用Apache和
mod_wsgi
运行应用程序,并创建一个名为
adapter.wsgi
的脚本:

import sys, os, bottle
sys.path = ['/var/www/getmember/'] + sys.path
os.chdir(os.path.dirname(__file__))
import getmember
application = bottle.default_app()
在Apache中,我有:

WSGIDaemonProcess getmember user=www-data group=www-data processes=1 threads=5 python-path=/usr/lib/python3.2/site-packages
WSGIScriptAlias /getmember /var/www/idcheck/adapter.wsgi
<Directory /var/www/getmember>
    WSGIProcessGroup getmember
    WSGIApplicationGroup %{GLOBAL}
    Order deny,allow
    Allow from all
</Directory>
那么,为什么它在正常的python调用下工作(意味着所有库和包都正常),而在wsgi和Apache下却抛出了这个错误呢?我感觉它找不到该包的所需路径,但不确定如何添加它

编辑

我运行了
import sys
print sys.path
,以获取运行python3.2环境时加载的所有路径。我在Apache中添加了多个路径到Python路径:

WSGIDaemonProcess idcheck user=www-data group=www-data processes=1 threads=5 python-path=/usr/local/lib/python3.2/dist-packages/distribute-0.6.34-py3.2.egg:/usr/local/lib/python3.2/dist-packages/logilab_common-0.58.3-py3.2.egg:/usr/local/lib/python3.2/dist-packages/logilab_astng-0.24.1-py3.2.egg:/usr/local/lib/python3.2/dist-packages/SQLAlchemy-0.8.0b2-py3.2.egg:/usr/local/lib/python3.2/dist-packages/psycopg2-2.4.6-py3.2-linux-x86_64.egg:/usr/local/lib/python3.2/dist-packages/pip-1.2.1-py3.2.egg:/usr/local/lib/python3.2/dist-packages/sqlautocode-0.6b1-py3.2.egg:/usr/lib/python3.2:/usr/lib/python3.2/plat-linux2:/usr/lib/python3.2/lib-dynload:/usr/local/lib/python3.2/dist-packages:/usr/lib/python3/dist-packages
这样,前面的错误消失了,我得到了一个新的无效语法。SQLAlchemy和mod_wsgi+Apache有什么问题吗

mod_wsgi (pid=21339): Target WSGI script '/var/www/getmember/adapter.wsgi' cannot be loaded as Python module.
mod_wsgi (pid=21339): Exception occurred processing WSGI script '/var/www/getmember/adapter.wsgi'.
Traceback (most recent call last):
  File "/var/www/getmember/adapter.wsgi", line 6, in <module>
    import getmember # This loads your application
  File "/var/www/getmember/getmember.py", line 10, in <module>
    from sqlalchemy import create_engine, MetaData
  File "/usr/local/lib/python3.2/dist-packages/SQLAlchemy-0.8.0b2-py3.2.egg/sqlalchemy/__init__.py", line 7, in <module>
    import inspect as _inspect
  File "/usr/lib/python3.2/inspect.py", line 36, in <module>
    import string
  File "/usr/lib/python3.2/string.py", line 89
    class Template(metaclass=_TemplateMetaclass):
                            ^
SyntaxError: invalid syntax
mod_wsgi(pid=21339):目标wsgi脚本'/var/www/getmember/adapter.wsgi'不能作为Python模块加载。
mod_wsgi(pid=21339):处理wsgi脚本“/var/www/getmember/adapter.wsgi”时发生异常。
回溯(最近一次呼叫最后一次):
文件“/var/www/getmember/adapter.wsgi”,第6行,在
导入getmember#这将加载您的应用程序
文件“/var/www/getmember/getmember.py”,第10行,在
从sqlalchemy导入创建引擎,元数据
文件“/usr/local/lib/python3.2/dist-packages/SQLAlchemy-0.8.0b2-py3.2.egg/SQLAlchemy/_-init__;.py”,第7行
进口检验作为检验
文件“/usr/lib/python3.2/inspect.py”,第36行,在
导入字符串
文件“/usr/lib/python3.2/string.py”,第89行
类模板(元类=\u TemplateMetaclass):
^
SyntaxError:无效语法

也许Apache使用的是2版Python可执行文件?您可以检查apache用户的搜索路径,或者查看WSGI指令WSGIPythonHome/WSGIPythonExecutable

尝试:

-剪断-

@route('/test', method='GET')
def test():
    return sys.version
或:


我认为它使用的是Python3.2,因为我在apache2.conf中有这样一个条目:
WSGIDaemonProcess idcheck user=www数据组=www数据进程=1线程=5 python路径=/usr/lib/Python3.2/site packages
?另外,在我插入该行之前,它找不到
瓶子
包装。现在确实如此,但现在在SQLAlchemy部分失败了
import sys
@route('/test', method='GET')
def test():
    return sys.version
#grep Python /var/log/httpd/error_log