2010-01-26 90 views
4

我正在與谷歌應用程序引擎Django +壓縮django。只要運行「python manage.py test」就可以成功,而且不會出錯。unittest導入錯誤與virtualenv +谷歌應用程序引擎Django

但與virtualenv,測試失敗,導入unittest錯誤。與Django 1.1相同的錯誤。

- OSX 10.5.6 
- google-app-engine-django (r101 via svn) : r100 was failed with launcher 1.3.0 
- GoogleAppLauncher 1.3.0 
- Django 1.1 & 1.1.1 (zipped) : both failed 
- virtualenv 1.4.5 
- virtualenvwrapper 1.24 

錯誤消息:

(django_appengine)Reiot:warclouds Reiot$ python manage.py test 
WARNING:root:Could not read datastore data from /var/folders/UZ/UZ1vQeLFH2ShHk4kIiLcFk+++TI/-Tmp-/django_google-app-engine-django.datastore 
INFO:root:zipimporter('/Volumes/data/Documents/warclouds/django.zip', 'django/core/serializers/') 
.WARNING:root:Can't open zipfile /Users/Reiot/.virtualenvs/django_appengine/lib/python2.5/site-packages/setuptools-0.6c11-py2.5.egg: IOError: [Errno 13] file not accessible: '/Users/Reiot/.virtualenvs/django_appengine/lib/python2.5/site-packages/setuptools-0.6c11-py2.5.egg' 
WARNING:root:Can't open zipfile /Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/site-packages/setuptools-0.6c9-py2.5.egg: IOError: [Errno 13] file not accessible: '/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/site-packages/setuptools-0.6c9-py2.5.egg' 
ERROR:root:Exception encountered handling request 
Traceback (most recent call last): 
    File "/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/google/appengine/tools/dev_appserver.py", line 3177, in _HandleRequest 
    self._Dispatch(dispatcher, self.rfile, outfile, env_dict) 
    File "/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/google/appengine/tools/dev_appserver.py", line 3120, in _Dispatch 
    base_env_dict=env_dict) 
    File "/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/google/appengine/tools/dev_appserver.py", line 515, in Dispatch 
    base_env_dict=base_env_dict) 
    File "/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/google/appengine/tools/dev_appserver.py", line 2379, in Dispatch 
    self._module_dict) 
    File "/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/google/appengine/tools/dev_appserver.py", line 2289, in ExecuteCGI 
    reset_modules = exec_script(handler_path, cgi_path, hook) 
    File "/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/google/appengine/tools/dev_appserver.py", line 2185, in ExecuteOrImportScript 
    exec module_code in script_module.__dict__ 
    File "/Volumes/data/Documents/warclouds/main.py", line 28, in <module> 
    from appengine_django import InstallAppengineHelperForDjango 
    File "/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/google/appengine/tools/dev_appserver.py", line 1264, in Decorate 
    return func(self, *args, **kwargs) 
    File "/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/google/appengine/tools/dev_appserver.py", line 1914, in load_module 
    return self.FindAndLoadModule(submodule, fullname, search_path) 
    File "/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/google/appengine/tools/dev_appserver.py", line 1264, in Decorate 
    return func(self, *args, **kwargs) 
    File "/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/google/appengine/tools/dev_appserver.py", line 1816, in FindAndLoadModule 
    description) 
    File "/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/google/appengine/tools/dev_appserver.py", line 1264, in Decorate 
    return func(self, *args, **kwargs) 
    File "/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/google/appengine/tools/dev_appserver.py", line 1767, in LoadModuleRestricted 
    description) 
    File "/Volumes/data/Documents/warclouds/appengine_django/__init__.py", line 44, in <module> 
    import unittest 
ImportError: No module named unittest 
INFO:root:"GET/HTTP/1.1" 500 - 
INFO:root:zipimporter('/Users/Reiot/.virtualenvs/django_appengine/lib/python2.5/site-packages/setuptools-0.6c11-py2.5.egg', '') 
INFO:root:zipimporter('/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/site-packages/setuptools-0.6c9-py2.5.egg', '') 
F........................................................... 
====================================================================== 
FAIL: a request to the default page works in the dev_appserver 
---------------------------------------------------------------------- 
Traceback (most recent call last): 
    File "/Volumes/data/Documents/warclouds/appengine_django/tests/integration_test.py", line 176, in testBasic 
    self.assertEquals(rv.status_code, 200) 
AssertionError: 500 != 200 

我也試圖與控制檯的進口,但它是好的。

> which python 
/Users/Reiot/.virtualenvs/django_appengine/bin/python 
> python 
>>> import unittest 

這裏是我的環境:

$ mkvirtualenv --no-site-packages no-django 
$ mkvirtualenv --no-site-packages django-1.1 
$ mkvirtualenv --no-site-packages django-1.1.1 
(django-1.1)$ easy_install Django-1.1.tar 
(django-1.1.1)$ easy_install Django-1.1.1.tar 
$ mkdir google-app-engine-django-svn 
$ cp -r google-app-engine-django-svn google-app-engine-django-svn-django-1.1 
// copy appropriate django.zip 
$ cp -r google-app-engine-django-svn google-app-engine-django-svn-django-1.1.1 
// copy appropriate django.zip 
+0

我也看到了這一點。起初,我認爲這是我的Python安裝 - 沒有股票10.6也顯示了這一點。 Virtualenv沒有采取所有的路徑.. – rh0dium 2010-02-28 04:52:18

+0

看看這個主題.. http://groups.google.com/group/python-virtualenv/browse_thread/thread/e33c2dc94e6196a1/09f54ee4b39a59b2?lnk=gst&q=paths#09f54ee4b39a59b2 – rh0dium 2010-02-28 04:58:39

回答

3

這是相當複雜的實現。我研究瞭如何創建一個 的virtualenv - GAE - 現在Django的組合,我會回來 與後來的更多信息,但是這是我現在所擁有的:

這裏的一個區別是,我使用Django-nonrel,但我也嘗試過 google-app-engine-django,並且在virtualenv方面,他們似乎 的工作原理是一樣的。

的virtualenv'd Python解釋器將無法直接啓動manage.py :Django的manage.pydev_appserver.py要廣泛 控制sys.path,明顯的方式,使共存 用的virtualenv可能。

然而,共存一定程度似乎是可能的:

我創建這樣的目錄結構:

./src < - Django的nonrel來源和我的消息來源 djangoappengine/< - 從wkornewald的到位桶來源 的Django/< - 也wkornewald的到位桶.. /< - 我們的應用程序

./www < - 我的Django根 manage.py,app.yaml中,settings.py,模板/等。 共應用/ < - Django的nonrel這裏要包 .google_appengine < - 鏈接到我的安裝GAE

我使用'python2.5 manage.py runserver'在 上面的'www /'目錄啓動開發服務器。

(基本處於 http://rh0dium.blogspot.com/2010/02/development-strategy-for-google-app.html 由rh0dium建議的目錄結構)

創建我在上面的頂層目錄的virtualenv:

$ virtualenv --python=python2.5 --no-site-packages --distribute . 

然後,我把兩個文件中的lib/python2。5 /站點包:

gae.pth

<full path to GAE> 
<full path to GAE>/lib/antlr3 
<full path to GAE>/lib/webob 
<full path to GAE>/lib/yaml/lib 

django-nonrel.pth

<project path>/src/django-nonrel 
<project path>/src 

(這些文件可能/(應該)被分開了,但我把它簡單的 現在。

這樣做與正確設置setup.py結合創建 開發蛋至少le我有一個交互式提示,可以導入Django設置可以導入的所有東西,用於播放和 測試。

相關問題