Windows 8.1 x64 - Python 3.4.1(pyzo_distro-2014a.win64) - Apache httpd-2.4.10-win64 - mod_wsgi-3.5.ap24.win-amd64-py3.4
如何设置多条路径?
似乎只设置了最后一条路径。
WSGIPythonPath C:/test1;C:/test2;C:/test3
在Apache日志文件中(带有LogLevel信息):
mod_wsgi (pid=3568): Initializing Python.
mod_wsgi (pid=3568): Attach interpreter ''.
mod_wsgi (pid=3568): Adding '(null)' to path.
mod_wsgi (pid=3568): Adding '(null)' to path.
mod_wsgi (pid=3568): Adding 'C:/test3' to path.
AH00354: Child: Starting 64 worker threads.
同样的结果:
WSGIPythonPath "C:/test1;C:/test2;C:/test3"
这不起作用:
WSGIPythonPath "C:/test1";"C:/test2";"C:/test3"
因为WSGIPythonPath只接受一个参数。
感谢。
答案 0 :(得分:0)
作为使用WSGIPythonPath指令添加目录的替代方法,您可以在代码中添加目录到路径:
import sys, os
paths = ['C:\test1', 'C:\test2', 'C:\test3']
for path in paths:
if path not in sys.path:
sys.path.append(path)
或者,如果您需要添加当前目录(对于Flask / Webapp2来说并不罕见),您可以放置
您可以将以下内容放在main.py中的其他导入上方:
import sys, os
path = os.path.dirname(os.path.abspath(__file__))
if path not in sys.path:
sys.path.append(path)
如果您的Apache服务器配置类似于:
WSGIScriptAlias /scripts "C:/web/wsgi_scripts/main.py"
WSGICallableObject app
<Directory "C:/web/wsgi_scripts">
<Files main.py>
Require all granted
</Files>
</Directory>