mod_python在虚拟环境下无法找到web.py模块

发布于 2024-10-06 10:16:21 字数 2312 浏览 3 评论 0原文

我有一个小型 web.py Python 应用程序,我想使用 mod_python 在 Apache 下提供服务。 web.py 框架以及相关应用程序所依赖的其他第三方 Python 模块安装在虚拟环境中。虚拟环境在内部创建: /home/ayaz/Sandbox/Scrapper/

我用来设置此应用程序的 Apache 虚拟主机配置的相关片段如下:

<Location "/api">
    PythonPath "['/home/ayaz/Sandbox/Scrapper/lib/python2.5/site-packages/', '/home/ayaz/project/'] + sys.path"
    #PythonHandler wsgiref.modpython_gateway::handler
    PythonHandler modpython_gateway::handler
    SetHandler python-program 
    PythonOption wsgi.application device_api::main
    PythonOption device_api /api/
</Location>

在浏览器上然而,当我尝试访问 /api URL 时,我从服务器收到 500 ,日志中显示错误,指出 web 模块无法找到从 device_api.py 文件(这是我的应用程序)导入的;换句话说,我看到一个 ImportError。我不知道为什么它找不到 web 模块。

从 Python 解释器能够找到 device_api.py 的事实来看,我知道 PythonPath 指令正在工作,至少部分来自该指令中定义的路径的文件。但是,它无法找到在同一指令中也定义了路径的其余模块。

对此的任何帮助将不胜感激。

谢谢!

更新 #1

Ned 的回复让我着迷 通过 site-packages 目录 对于我拥有的虚拟环境。 虽然权限看起来不错 在我的目录里面,我意识到 mod_python/Apache 无法 读取鸡蛋。自从我安装了 虚拟内的所有包 使用 easy_install 的环境,它们都是形式 鸡蛋。所以,举例来说,如果我搬家了 目录 /home/ayaz/Sandbox/Scrapper/lib/python2.5/site-packages/web.py-0.34-py2.5.egg/web/ 进入 /home/ayaz/Sandbox/Scrapper/lib/python2.5/site-packages/ (基本上是从鸡蛋中取出 文件/目录),mod_python 已停止 抱怨缺少 web 模块(当然,它然后启动 抱怨其余的失踪 第三方模块)。

我已将 Apache 配置为作为我的运行 用户和组,即 ayaz,而我 检查了权限 /home/ayaz/.python-eggs 目录 都很好。

然后我使用了这个 使用鸡蛋 mod_python 被欺骗的解释 Django 部署文档 页。但这没有帮助。 最终,我硬着头皮,为了 每个第三方模块 mod_python 抱怨它不能 发现,我移动了实际目录 从该模块的鸡蛋内部 从鸡蛋外面到里面 site-packages 目录 虚拟环境。这使得 mod_python 找到模块。

现在,我真的不知道为什么会这样 正在发生,为什么 mod_python 没有发生 能够读懂鸡蛋。

I have a small web.py Python application that I would like to serve under Apache using mod_python. The web.py framework, as well as other third-party Python modules the application in question relies upon, are installed in a virtual environment. The virtual environment is created inside: /home/ayaz/Sandbox/Scrapper/

The relevant snippet from the virtual host configuration for Apache that I am using in order to set up this application is this:

<Location "/api">
    PythonPath "['/home/ayaz/Sandbox/Scrapper/lib/python2.5/site-packages/', '/home/ayaz/project/'] + sys.path"
    #PythonHandler wsgiref.modpython_gateway::handler
    PythonHandler modpython_gateway::handler
    SetHandler python-program 
    PythonOption wsgi.application device_api::main
    PythonOption device_api /api/
</Location>

On the browser when I try to access the /api URL however, I get a 500 from the server with the error in the logs saying that the web module imported from within the device_api.py file (which is my application) could not be found; in other words, I see an ImportError. I am not sure why it is unable to find the web module.

I know that the PythonPath directive is working, at least partially, judging from the fact that the Python interpreter is able to find the device_api.py file from the path defined in that directive. But, it is unable to find the rest of the modules for which the path is also defined in the same directive.

Any help with this will be deeply appreciated.

Thanks!

UPDATE #1

Ned's reply had me looking
through the site-packages directory
for the virtual environment I have.
While the permissions looked fine
inside the directory to me, I realized
that mod_python/Apache was not able
to read the eggs. Since I installed
all the packages inside the virtual
environment using easy_install, they are all in the forms
of eggs. So, for example, if I moved
the directory
/home/ayaz/Sandbox/Scrapper/lib/python2.5/site-packages/web.py-0.34-py2.5.egg/web/
into
/home/ayaz/Sandbox/Scrapper/lib/python2.5/site-packages/
(essentially taking it out of the egg
file/directory), mod_python stopped
complaining about the missing web
module (of course, it then started
complaining about the missing rest of
the third-party modules).

I have Apache configured to run as my
user and group, that is ayaz, and I
checked that the permissions on the
/home/ayaz/.python-eggs directory
were fine.

I then used this Using eggs with
mod_python
tricked explained on
the Django deployment documentation
page. But it didn't help.
Eventually, I bit the bullet, and for
each third-party module that
mod_python complained it couldn't
find, I moved the actual directory
from inside the egg for that module
outside of the egg and into the
site-packages directory for the
virtual environment. This made
mod_python find the modules.

Now, I am really not sure why this
is happening, and why mod_python isn't
able to read through the eggs.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

彡翼 2024-10-13 10:16:21

会不会是文件或目录权限问题?验证是否可以通过 Apachemod_python< 的用户名访问 virtualenv site-packages 中的所有文件和目录/code> 下运行。

Could it be a file or directory permission problem? Verify that the all of the files and directories in your virtualenv site-packages are accessible from the user name that Apache and mod_python are running under.

明媚如初 2024-10-13 10:16:21

为了回答这个问题,我将复制问题中的更新段落并将它们作为答案发布(因为它们似乎在某种程度上解释了我如何设法摆脱问题)。

内德的回复让我浏览了
site-packages 目录
我有虚拟环境。虽然
权限在里面看起来很好
目录给我,我意识到
mod_python/Apache 无法读取
鸡蛋。由于我安装了所有
虚拟内的包
使用easy_install的环境,他们
都是鸡蛋的形式。所以,对于
例如,如果我移动目录
/home/ayaz/Sandbox/Scrapper/lib/python2.5/site-packages/web.py-0.34-py2.5.egg/web/
进入
/home/ayaz/Sandbox/Scrapper/lib/python2.5/site-packages/
(基本上是从鸡蛋中取出
文件/目录),mod_python 停止
抱怨网络缺失
模块(当然,它然后启动
抱怨其余的失踪
第三方模块)。

我已将 Apache 配置为作为我的运行
用户和组,即 ayaz,而我
检查了权限
/home/ayaz/.python-eggs 目录为
很好。

然后我使用了这个 使用鸡蛋
mod_python
被欺骗的解释
Django 部署文档页面。
但这没有帮助。最终我还是咬了一口
项目符号,以及对于每个第三方
mod_python 抱怨的模块
找不到,我搬了实际的
鸡蛋内部的目录
模块在鸡蛋外面并进入
site-packages 目录
虚拟环境。这使得
mod_python 找到模块。

现在我真的不知道这是为什么
发生了,为什么 mod_python 没有发生
能够读懂鸡蛋。

So as to answer this question, I am going to copy the update paragraphs from my question and post them as the answer (as they seem to explain to some extent how I manage to get rid of the problem).

Ned's reply had me looking through the
site-packages directory for the
virtual environment I have. While the
permissions looked fine inside the
directory to me, I realized that
mod_python/Apache was not able to read
the eggs. Since I installed all the
packages inside the virtual
environment using easy_install, they
are all in the forms of eggs. So, for
example, if I moved the directory
/home/ayaz/Sandbox/Scrapper/lib/python2.5/site-packages/web.py-0.34-py2.5.egg/web/
into
/home/ayaz/Sandbox/Scrapper/lib/python2.5/site-packages/
(essentially taking it out of the egg
file/directory), mod_python stopped
complaining about the missing web
module (of course, it then started
complaining about the missing rest of
the third-party modules).

I have Apache configured to run as my
user and group, that is ayaz, and I
checked that the permissions on the
/home/ayaz/.python-eggs directory were
fine.

I then used this Using eggs with
mod_python
tricked explained on the
Django deployment documentation page.
But it didn't help. Eventually, I bit
the bullet, and for each third-party
module that mod_python complained it
couldn't find, I moved the actual
directory from inside the egg for that
module outside of the egg and into the
site-packages directory for the
virtual environment. This made
mod_python find the modules.

Now, I am really not sure why this is
happening, and why mod_python isn't
able to read through the eggs.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文