我是一個非常新的金字塔學習者,我只是按照創建一個新的金字塔項目的文檔:我成功地安裝了包含金字塔1.5包的virtualenv並運行項目發展模式與'pserve'。apache/mod_wsgi上的金字塔:ImportError:沒有模塊命名的註冊表
但是,使用Apache + mod_wsgi的時候,這是另一個故事:我得到這個錯誤到Apache的錯誤日誌:
[Fri May 02 09:08:53 2014] [error] [client 127.0.0.1] File "/home/eric/perso/projects/Pyratest/pyramid.wsgi", line 8, in <module>
[Fri May 02 09:08:53 2014] [error] [client 127.0.0.1] from pyramid.paster import get_app, setup_logging
...
[Fri May 02 09:08:53 2014] [error] [client 127.0.0.1] File "/home/eric/perso/projects/venv/local/lib/python2.7/site-packages/pyramid-1.5-py2.7.egg/pyramid/threadlocal.py", line 3, in <module>
[Fri May 02 09:08:53 2014] [error] [client 127.0.0.1] from pyramid.registry import global_registry
[Fri May 02 09:08:53 2014] [error] [client 127.0.0.1] File "/home/eric/perso/projects/venv/local/lib/python2.7/site-packages/pyramid-1.5-py2.7.egg/pyramid/registry.py", line 5, in <module>
[Fri May 02 09:08:53 2014] [error] [client 127.0.0.1] from zope.interface.registry import Components
[Fri May 02 09:08:53 2014] [error] [client 127.0.0.1] ImportError: No module named registry
我加了sys.path中轉儲到我pyramid.wsgi:
import sys
print "=" * 80
for p in sys.path:
print p
from pyramid.paster import get_app, setup_logging
ini_path = '/home/eric/perso/projects/Pyratest/production.ini'
setup_logging(ini_path)
application = get_app(ini_path, 'main')
我可以看到apache用戶可以訪問zope/interface/registry.py的路徑。 此路徑位於sys.path的最開始處,因此不應該在某處存在路徑衝突。
我的Apache虛擬主機的定義:
Listen 9999
NameVirtualHost localhost:9999
<VirtualHost localhost:9999>
ServerAdmin [email protected]
<Directory />
Options FollowSymLinks
AllowOverride None
</Directory>
ErrorLog /var/log/apache2/pyramid-test-error.log
LogLevel warn
CustomLog /var/log/apache2/pyramid-test-access.log combined
ServerSignature On
Alias /static/ /home/eric/perso/projects/Pyratest/pyratest/static/
<Location "/static/">
<IfModule mod_deflate.c>
AddOutputFilterByType DEFLATE text/html text/plain text/xml application/javascript
</IfModule>
Options Indexes FollowSymLinks MultiViews
Order allow,deny
allow from all
</Location>
WSGIApplicationGroup %{GLOBAL}
WSGIPassAuthorization On
WSGIDaemonProcess pyramid-test user=eric group=eric processes=4 threads=1 python-path=/home/eric/perso/projects/Pyratest/:/home/eric/perso/projects/venv/lib/python2.7/site-packages
WSGIProcessGroup pyramid-test
WSGIScriptAlias//home/eric/perso/projects/Pyratest/pyramid.wsgi
<Directory /home/eric/perso/projects/venv>
WSGIProcessGroup eric
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
當我運行手動VENV Python解釋器,我可以導入zope.interface.registry沒有任何問題。我不明白爲什麼用mod_wsgi,它不起作用。 我嘗試了很多次,通過創建許多venv和只使用easy_install或pip填充,有或沒有--no-site-packages,我已經採用了最新版本的virtualenv,distribute,pip,setuptools,但仍然一樣問題。只有一個常量:只有zope.interface.registry似乎無法訪問:爲什麼這個而不是其他金字塔包?
UPDATE 1:的registry.py和pyc文件是可讀:
[email protected]:~/perso/projects$ . ./venv/bin/activate
(venv)[email protected]:~/perso/projects$ python
Python 2.7.3 (default, Aug 1 2012, 05:14:39)
[GCC 4.6.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import zope.interface.registry
>>> print zope.interface.registry.__file__
/home/eric/perso/projects/venv/lib/python2.7/site-packages/zope.interface-4.1.1-py2.7-linux-x86_64.egg/zope/interface/registry.pyc
>>>
(venv)[email protected]:~/perso/projects$ ls /home/eric/perso/projects/venv/lib/python2.7/site-packages/zope.interface-4.1.1-py2.7-linux-x86_64.egg/zope/interface/registry.pyc
/home/eric/perso/projects/venv/lib/python2.7/site-packages/zope.interface-4.1.1-py2.7-linux-x86_64.egg/zope/interface/registry.pyc
(venv)[email protected]:~/perso/projects$ ls -la /home/eric/perso/projects/venv/lib/python2.7/site-packages/zope.interface-4.1.1-py2.7-linux-x86_64.egg/zope/interface/registry.pyc
-rw-rw-r-- 1 eric eric 25127 mai 2 08:54 /home/eric/perso/projects/venv/lib/python2.7/site-packages/zope.interface-4.1.1-py2.7-linux-x86_64.egg/zope/interface/registry.pyc
(venv)[email protected]:~/perso/projects$ ls -la /home/eric/perso/projects/venv/lib/python2.7/site-packages/zope.interface-4.1.1-py2.7-linux-x86_64.egg/zope/interface/registry.py
-rw-rw-r-- 1 eric eric 18877 mai 2 08:54 /home/eric/perso/projects/venv/lib/python2.7/site-packages/zope.interface-4.1.1-py2.7-linux-x86_64.egg/zope/interface/registry.py
更新2:這裏是安裝的軟件包:
(venv)[email protected]:~/perso/projects/venv$ pip freeze
Chameleon==2.15
Mako==0.9.1
MarkupSafe==0.21
PasteDeploy==1.5.2
Pygments==1.6
Pyratest==0.0
WebOb==1.3.1
argparse==1.2.1
pyramid==1.5
pyramid-chameleon==0.1
pyramid-debugtoolbar==2.0.2
pyramid-mako==1.0.2
repoze.lru==0.6
translationstring==1.1
venusian==1.0a8
waitress==0.8.8
wsgiref==0.1.2
zope.deprecation==4.1.1
zope.interface==4.1.1
更新3:我終於找到了一種啓動金字塔的方法,但它太奇怪了,我不能認爲這是一個解決方案:
- use pip install instead of easy_install
- add "import pip" at the top of the pyramid.wsgi file (!!!)
更新4:我重做這裏的文檔Running a Pyramid Application under mod_wsgi的確切的過程,那就是:一個modwsgi目錄,virtualenv中內內的virtualenv終於Pyratest:還是一樣的東西:不阿帕奇mod_wsgi的工作:導入錯誤:沒有模塊命名註冊表
更新5:我決定從頭開始安裝一個全新的ubuntu 12.04通過使用vagrant,通過這種方式,一切工作正常。所以問題是爲什麼它不能在我平常的桌面上工作:對於這兩個,它不工作...我對他們運行Django沒有任何問題,可能有一些調音與金字塔衝突...
該死的......這真是醜陋,但我自己也碰到過這種情況,不得不應用類似的可怕黑客攻擊來重新開始工作重建venv);順便說一下,在我的情況下,這個項目已經在venv下了,我已經按照指南在mod_wsgi下運行Pyramid了。非常感謝發佈解決方案(儘管我一定希望找到更清潔的解決方案!) –
看起來有一個[稍微更清潔的選項](http://blog.dscpl.com.au/2014/09/using- python-virtual-environments-with.html),但它取決於比我目前得到的更新版本的mod_wsgi –