【问题标题】:Import error when running google app engine django project through pycharm通过pycharm运行google app engine django项目时导入错误
【发布时间】:2014-12-24 01:04:59
【问题描述】:

我正在为谷歌应用引擎编写一个 django (1.5) 应用程序。当我运行应用程序引擎服务器(通过 pycharm)时,我收到一个 django 导入错误,提示“没有名为 oauth2client.django_orm 的模块”。我之前已经安装并成功使用了 google python api 客户端,所以我知道一切都应该正常工作,并且据我所知包含在我的 python 路径中。此外,如果运行 django 控制台(通过 pycharm)并输入“import oauth2client”,它就可以工作。所以我唯一的想法是开发服务器可能没有访问模块的权限?我完全迷失了,任何人都可以帮助 plzzzz。

以下是错误页面的内容:

ImportError at /
No module named oauth2client.django_orm
Request Method: GET
Request URL:    <localhost>
Django Version: 1.5.8
Exception Type: ImportError
Exception Value:    
No module named oauth2client.django_orm
Exception Location: /Users/andrewschmitt/Projects/VMS/directory/models.py in <module>, line 3
Python Executable:  /usr/bin/python
Python Version: 2.7.6
Python Path:    
['/Users/andrewschmitt/Projects/VMS',
 '/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine',
 '/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine',
 '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7',
 '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-dynload',
 '/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/lib/django-1.5',
 '/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/lib/protorpc-1.0',
 '/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/lib/webapp2-2.3',
 '/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/lib/webob-1.1.1',
 '/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/lib/yaml-3.10']
Server time:    Tue, 28 Oct 2014 14:26:45 +0000

这是回溯:

Environment:


Request Method: GET
Request URL: <localhost>

Django Version: 1.5.8
Python Version: 2.7.6
Installed Applications:
('django.contrib.admin',
 'django.contrib.auth',
 'django.contrib.contenttypes',
 'django.contrib.sessions',
 'django.contrib.sites',
 'django.contrib.messages',
 'django.contrib.staticfiles',
 'foundation',
 'directory')
Installed Middleware:
('django.middleware.common.CommonMiddleware',
 'django.contrib.sessions.middleware.SessionMiddleware',
 'django.middleware.csrf.CsrfViewMiddleware',
 'django.contrib.auth.middleware.AuthenticationMiddleware',
 'django.contrib.messages.middleware.MessageMiddleware')


Traceback:
File "/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/lib/django-1.5/django/core/handlers/base.py" in get_response
  101.                     resolver_match = resolver.resolve(request.path_info)
File "/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/lib/django-1.5/django/core/urlresolvers.py" in resolve
  338.             for pattern in self.url_patterns:
File "/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/lib/django-1.5/django/core/urlresolvers.py" in url_patterns
  366.         patterns = getattr(self.urlconf_module, "urlpatterns", self.urlconf_module)
File "/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/lib/django-1.5/django/core/urlresolvers.py" in urlconf_module
  361.             self._urlconf_module = import_module(self.urlconf_name)
File "/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/lib/django-1.5/django/utils/importlib.py" in import_module
  35.     __import__(name)
File "/Users/andrewschmitt/Projects/VMS/VMS/urls.py" in <module>
  5. admin.autodiscover()
File "/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/lib/django-1.5/django/contrib/admin/__init__.py" in autodiscover
  29.             import_module('%s.admin' % app)
File "/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/lib/django-1.5/django/utils/importlib.py" in import_module
  35.     __import__(name)
File "/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/lib/django-1.5/django/contrib/auth/admin.py" in <module>
  179. admin.site.register(Group, GroupAdmin)
File "/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/lib/django-1.5/django/contrib/admin/sites.py" in register
  98.                 validate(admin_class, model)
File "/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/lib/django-1.5/django/contrib/admin/validation.py" in validate
  22.     models.get_apps()
File "/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/lib/django-1.5/django/db/models/loading.py" in get_apps
  134.         self._populate()
File "/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/lib/django-1.5/django/db/models/loading.py" in _populate
  75.                     self.load_app(app_name)
File "/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/lib/django-1.5/django/db/models/loading.py" in load_app
  96.             models = import_module('.models', app_name)
File "/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/lib/django-1.5/django/utils/importlib.py" in import_module
  35.     __import__(name)
File "/Users/andrewschmitt/Projects/VMS/directory/models.py" in <module>
  3. from oauth2client.django_orm import FlowField

Exception Type: ImportError at /
Exception Value: No module named oauth2client.django_orm

更新:如果我打开一个终端并使用 django 的 runserver (python manage.py runserver) 启动应用程序,则模块加载正常。因此,Pycharm 或 Google 的开发服务器(通过 Pycharm 启动)必须存在某种权限问题。

【问题讨论】:

  • 如果您将 Pycharm 正在执行的命令(调试控制台上的第一行)添加到您的问题中,这可能会很有用。

标签: python django google-app-engine python-2.7


【解决方案1】:

检查此链接以验证您是否正确配置了所有内容。

我认为是缺少模块的问题。要么没有导入,要么拼写错误。

看看这个

http://google-api-python-client.googlecode.com/hg/docs/epy/oauth2client.django_orm-pysrc.html

【讨论】:

  • 疯狂的是。我使用纯 django (1.7) 编写了这个应用程序,没有任何问题。我可以在本地运行它并且加载该模块没有问题。我所做的只是打开 pycharm,启动了一个支持 django 的新应用程序引擎项目。然后复制我的代码。现在突然之间它无法导入模块。我什至不知道如何解决这个问题。
  • 如果打开终端并使用 django 的 runserver 启动应用程序,它可以正常工作。所以问题是直接从终端运行和从 pycharm 运行有什么区别
  • pycharm 运行项目的命令在启动时显示在控制台中。您可以将其直接粘贴到控制台中。
【解决方案2】:

您需要下载 GAE 的 google api 客户端 google-python-api-client-gae-x.x.zip (https://code.google.com/p/google-api-python-client/downloads/list)。然后解压缩文件夹并将您想要的每个库添加到应用引擎项目的根目录中。

【讨论】:

  • 是否总是需要将您想要的每个库添加到应用引擎项目的根目录中?有没有其他办法?
猜你喜欢
  • 1970-01-01
  • 2015-04-21
  • 2011-01-09
  • 1970-01-01
  • 2013-05-17
  • 1970-01-01
  • 1970-01-01
  • 2017-01-29
  • 1970-01-01
相关资源
最近更新 更多