当我尝试为导入from google.appengine.ext import ndb的模块制作文档时,Sphinx抛出此错误:

Traceback (most recent call last):e/adapters
  File "/usr/local/lib/python2.7/dist-packages/Sphinx-1.1.3-py2.7.egg/sphinx/ext/autodoc.py", line 321, in import_object
    __import__(self.modname)
  File "/home/peto/workspace/mymodule.py", line 11, in <module>
    from google.appengine.ext import ndb
  File "/usr/lib/pymodules/python2.7/google/appengine/ext/ndb/__init__.py", line 7, in <module>
    from tasklets import *
  File "/usr/lib/pymodules/python2.7/google/appengine/ext/ndb/tasklets.py", line 68, in <module>
    from .google_imports import apiproxy_stub_map
  File "/usr/lib/pymodules/python2.7/google/appengine/ext/ndb/google_imports.py", line 33, in <module>
    from google.appengine.ext import gql
ImportError: cannot import name gql


我通过将yaml包含在sys.path中来解决了与gql相同的问题,但不适用于conf.py。我的配置如下:

gae_path = '/usr/lib/google-app-engine'

sys.path[0:0] = [
    gae_path,
    os.path.join(gae_path, 'lib'),
    os.path.join(gae_path, 'lib', 'yaml'),
    os.path.join(gae_path, 'lib', 'yaml', 'lib'),
    os.path.join(gae_path, 'google'),
    os.path.join(gae_path, 'google', 'appengine'),
    os.path.join(gae_path, 'google', 'appengine', 'ext'),
    os.path.join(gae_path, 'google', 'appengine', 'ext', 'gql'), # The gql package is really there
    os.path.abspath('../../'),
]

最佳答案

问题是我在sys.path中的/usr/lib/pymodules/python2.7/google/appengine中有另一个Google程序包,其中没有ext.gql程序包。我删除了该文件夹,它的工作原理很像。

08-16 06:51