与virtualenv + google-app-engine-django的unittest导入错误

时间:2010-01-26 13:42:23

标签: django google-app-engine virtualenv

我正在使用google-app-engine-django + zipped django。刚运行“python manage.py test”成功没有错误。

但是使用virtualenv,测试失败了“import unittest error”。与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

1 个答案:

答案 0 :(得分: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&lt; - django-nonrel来源和我的消息来源      djangoappengine /&lt; - 来自wkornewald的bitbucket消息来源      django /&lt; - 也是wkornewald的bitbucket ..      /&lt; - 我们的申请

./ www&lt; - 我的django root      manage.py,app.yaml,settings.py,templates / etc.      common-apps /&lt; - django-nonrel想要包在这里                .google_appengine&lt; - 指向我的GAE安装链接

我使用'python2.5 manage.py runserver'启动开发服务器 上面名为'www /'的目录。

(基本上是rh0dium建议的目录结构 http://rh0dium.blogspot.com/2010/02/development-strategy-for-google-app.html

我在上面的顶级目录中创建了virtualenv:

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

然后我把两个文件放在lib / python2.5 / site-packages中:

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进行创建 开发蛋至少让我有一个互动提示,可以 导入Django设置可以导入的所有内容,用于播放和播放 测试