簡體   English   中英

Windows上的mod_wsgi WSGIPythonPath多個路徑

[英]mod_wsgi WSGIPythonPath multiple paths on Windows

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僅接受一個參數。

謝謝。

作為使用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>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM