python 导入 (MySQLdb) 和 apache python_egg_cache 的问题

发布于 2024-11-01 18:17:44 字数 2029 浏览 1 评论 0 原文

我在 php 调用 python 脚本时遇到问题,或者它调用脚本时遇到问题,但在添加到我的用户 .bash_profile 后尝试导入 MySQLdb 时停止在途中的某个地方

,遵循本指南 如何修复开始的 Trac 安装给出与 PYTHON_EGG_CACHE?

export PYTHON_EGG_CACHE /var/www/html/path/cache

和 httpd.conf

   AddHandler mod_python
   SetEnv PYTHON_EGG_CACHE /var/www/html/path/cache

相关的错误我仍然收到此错误消息,网络服务器仍然尝试访问 /root/.python-eggs 我在新文件夹中找不到导出的 .python-eggs

Array
(
    [stdout] => 
    [stderr] => Traceback (most recent call last):
  File "/var/www/html/grndb/upscgenesearch/python/pythontest.py", line 4, in ?
    import MySQLdb
  File "build/bdist.linux-x86_64/egg/MySQLdb/__init__.py", line 19, in ?
  File "build/bdist.linux-x86_64/egg/_mysql.py", line 7, in ?
  File "build/bdist.linux-x86_64/egg/_mysql.py", line 4, in __bootstrap__
  File "/usr/lib/python2.4/site-packages/pkg_resources.py", line 799, in resource_filename
    return get_provider(package_or_requirement).get_resource_filename(
  File "/usr/lib/python2.4/site-packages/pkg_resources.py", line 1229, in get_resource_filename
    return self._extract_resource(manager, zip_path)
  File "/usr/lib/python2.4/site-packages/pkg_resources.py", line 1249, in _extract_resource
    real_path = manager.get_cache_path(
  File "/usr/lib/python2.4/site-packages/pkg_resources.py", line 880, in get_cache_path
    self.extraction_error()
  File "/usr/lib/python2.4/site-packages/pkg_resources.py", line 846, in extraction_error
    raise err
pkg_resources.ExtractionError: Can't extract file(s) to egg cache

尝试将文件提取到 Python Egg 时发生以下错误 缓存:

 [Errno 13] Permission denied: '/root/.python-eggs'

Python Egg 缓存目录当前设置为:

 /root/.python-eggs

也许您的帐户没有对此目录的写权限?你可以 通过设置 PYTHON_EGG_CACHE 环境更改缓存目录 变量指向可访问的目录。

I have trouble with php calling a python script, or its calling the script but stops somewhere on the way when trying to import MySQLdb

now after adding, to my user .bash_profile, following this guide How do you fix a Trac installation that begins giving errors relating to PYTHON_EGG_CACHE?

export PYTHON_EGG_CACHE /var/www/html/path/cache

and to httpd.conf

   AddHandler mod_python
   SetEnv PYTHON_EGG_CACHE /var/www/html/path/cache

i still get this error message, the webserver still try to access /root/.python-eggs
and i cant find my exported .python-eggs in my new folder

Array
(
    [stdout] => 
    [stderr] => Traceback (most recent call last):
  File "/var/www/html/grndb/upscgenesearch/python/pythontest.py", line 4, in ?
    import MySQLdb
  File "build/bdist.linux-x86_64/egg/MySQLdb/__init__.py", line 19, in ?
  File "build/bdist.linux-x86_64/egg/_mysql.py", line 7, in ?
  File "build/bdist.linux-x86_64/egg/_mysql.py", line 4, in __bootstrap__
  File "/usr/lib/python2.4/site-packages/pkg_resources.py", line 799, in resource_filename
    return get_provider(package_or_requirement).get_resource_filename(
  File "/usr/lib/python2.4/site-packages/pkg_resources.py", line 1229, in get_resource_filename
    return self._extract_resource(manager, zip_path)
  File "/usr/lib/python2.4/site-packages/pkg_resources.py", line 1249, in _extract_resource
    real_path = manager.get_cache_path(
  File "/usr/lib/python2.4/site-packages/pkg_resources.py", line 880, in get_cache_path
    self.extraction_error()
  File "/usr/lib/python2.4/site-packages/pkg_resources.py", line 846, in extraction_error
    raise err
pkg_resources.ExtractionError: Can't extract file(s) to egg cache

The following error occurred while trying to extract file(s) to the Python egg
cache:

 [Errno 13] Permission denied: '/root/.python-eggs'

The Python egg cache directory is currently set to:

 /root/.python-eggs

Perhaps your account does not have write access to this directory? You can
change the cache directory by setting the PYTHON_EGG_CACHE environment
variable to point to an accessible directory.

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

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

发布评论

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

评论(1

樱&纷飞 2024-11-08 18:17:44

查看 trac 的错误跟踪器这个问题。您应该能够以某种方式修复 apache 的环境(最有可能以发行版/操作系统特定的方式),或者只是升级 trac。

更新:该问题并非 Trac/Genshii 特有的,每个在 apache 内运行并尝试安装 python Egg 的 python 应用程序都会发生这种情况。我使用 Trac 遇到了它并解决了编辑 Web 服务器环境的问题。 此 wiki 页面 明确指出 apache 的 SetEnv 指令不起作用,您应该使用PythonOption。至于修改Web服务器的环境,我在FreeBSD服务器上做到了这一点(您只需在 /usr/local/etc/apache22/envvars.d 中添加一个带有您需要的环境变量的脚本)并且我怀疑你可以在 Ubuntu 上编辑 /etc/apache2/envvars 实现同样的效果。如果您使用的是另一个发行版,只需检查您的 apache 是如何打包的并采取相应的操作。

Have a look at trac's bug tracker or this question. You should be able to fix apache's environment in some way (most likely in a distribution/os specific way), or just upgrade trac.

Update: The problem is not specific to Trac/Genshii, it happens with each python application running inside apache and trying to install a python egg. I came across it using Trac and solved editing the web server's environment. This wiki page explicitly says that apache's SetEnv directive won't work, you should use PythonOption. As for modifying the web server's environment I did that on a FreeBSD server (where you just add a script with the environment vars you nedd inside /usr/local/etc/apache22/envvars.d) and I suspect you could achieve the same on Ubuntu editing /etc/apache2/envvars. If you are on another distro just check how your apache is packaged and act accordingly.

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