当从PIP到位桶回购安装django-piston,我发现了一些奇怪的(第一缩进输出线):Django项目(阿帕奇,mod_wsgi的)不能导入命名空间的包
$ 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
皮普不会安装活塞的__init__.py
,表明这是因为'活塞'在setup.py
中被指定为namespace_packages
之一。
此外,当我看了“django_piston-0.2.3rc1-nspkg.pth”文件中,我发现这一点,似乎是在“虚拟软件包”的尝试:
# File: [virtualenv]/lib/python2.6/site-packages/django_piston-0.2.3rc1-py2.6-nspkg.pth
# Originally all on one line; broken apart here for readability.
import sys,new,os;
p = os.path.join(sys._getframe(1).f_locals['sitedir'], *('piston',));
ie = os.path.exists(os.path.join(p,'__init__.py'));
m = not ie and sys.modules.setdefault('piston',new.module('piston'));
mp = (m or []) and m.__dict__.setdefault('__path__',[]);
(p not in mp) and mp.append(p)
我可以看到它在这里做什么;它基本上创建了一个“假模块”,活塞应该是,它基本上聚集了所有活塞的子模块。
这似乎对命令行工作正常(我可以从django shell导入活塞[虽然它的repr是<module 'piston' (built-in)>
],而且事情似乎在runserver中很好。),但是我的项目运行在apache mod_wsgi上,会在每个页面上引发500错误,因为有“没有名为piston.handler的模块”。
我排除了python路径问题; site-packages目录位于所有尝试的路径中。我不知道为什么它会有这样的表现,有什么想法吗?