當從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目錄位於所有嘗試的路徑中。我不知道爲什麼它會有這樣的表現,有什麼想法嗎?