Django project(apache,mod_wsgi)无法导入命名空间包

2024-04-24 14:12:01 发布

您现在位置:Python中文网/ 问答频道 /正文

当用pip从bitbucket repo安装django-piston时,我注意到一些奇怪的东西(输出的第一个缩进行):

$ pip install hg+http://bitbucket.org/jespern/django-piston
Downloading/unpacking hg+http://bitbucket.org/jespern/django-piston
Cloning Mercurial repository http://bitbucket.org/jespern/django-piston to /tmp/pip-v1h8Sh-build
Running setup.py egg_info for package from hg+http://bitbucket.org/jespern/django-piston
Installing collected packages: django-piston
Running setup.py install for django-piston
    Skipping installation of [venv]/lib/python2.6/site-packages/piston/__init__.py (namespace package)
    Installing [venv]/lib/python2.6/site-packages/django_piston-0.2.3rc1-py2.6-nspkg.pth
Successfully installed django-piston
Cleaning up

Pip不会安装活塞的__init__.py,这表明这是因为'活塞'被指定为setup.py中的namespace_packages之一。在

此外,当我查看“django_活塞-0.2.3rc1”内部时-nspkg.pth公司“文件,我发现这个,似乎是在尝试“虚拟包”:

^{pr2}$

我可以看到它在这里做什么;它基本上是在创建一个“假模块”,其中活塞应该是的,它基本上聚合了活塞的所有子模块。在

从服务器上运行一个名为'dji>的命令行,{cd4}似乎无法正常工作,因为从这个命令行中,{cd4}似乎可以正常工作装卸机活塞". 在

我已经排除了python路径问题;site packages dir在所有尝试的路径中。我不知道它为什么会这样,有什么想法吗?在


Tags: installpipdjangopyorghttpbitbucketfor
1条回答
网友
1楼 · 发布于 2024-04-24 14:12:01

再看了一些之后,我在the docs for mod_wsgi中发现了答案:

As an additional step however, the WSGI script file described in the instructions would be modified to overlay the virtual environment for the application on top of the baseline environment. This would be done by adding at the very start of the WSGI script file the following:

import site
site.addsitedir('/usr/local/pythonenv/PYLONS-1/lib/python2.5/site-packages')

Note that in this case the full path to the 'site-packages' directory for the virtual environment needs to be specified and not just the root of the virtual environment.

Using 'site.addsitedir()' is a bit different to simply adding the directory to 'sys.path' as the function will open up any '.pth' files located in the directory and process them. This is necessary to ensure that any special directories related to Python eggs are automatically added to 'sys.path'.

site.addsitedir调用添加到我的wsgi脚本中(而不是像我刚才那样附加到sys.path)就解决了所有问题。在

相关问题 更多 >