如何在 mod_python 中添加 python 路径

how to add python path in mod_python

您好,我正在使用 mod_python,我在目录 X 中有一个 python 模块 AA,在目录 X 中,我有子目录,其中包含其他模块,这些模块在 AA 中导入。我在 BB 中导入 AA。当我 运行 BB 它无法加载在 AA 中导入的模块。

这是一个 python 路径问题,但问题是如何动态设置用户工作区的路径。

每个用户的工作区不同。

请帮我解决这个问题。

更新我正在使用

sys. path.append(classpath)

在我的 BB 脚本中,但仍然失败。

我的虚拟主机文件在目录标签中添加了以下内容:

AddHandler cgi-script .py
PythonHandler mod_python
PythonDebug On

Python 路径可以使用 PythonPath 指令添加。它应该在服务器、虚拟主机、目录和 .htaccess 上下文中工作。

PythonPath "['/path/to/site1', '/path/to/site2']"

http://modpython.org/live/current/doc-html/directives.html#pythonpath