Import failed when the module is already in the sys.path

末鹿安然 提交于 2019-12-01 14:23:52

Can you import google and google.appengine? Are you sure interpreter has read and traverse access rights to the module tree?

I had the same problem on Ubuntu when I wanted to play with google.appengine in console. First I tried to fix it by removing the /usr/lib/python2.7/dist-packages/google package altogether but Ubuntu One complained. Finally I resolved it by merging the GAE SDK google package into the package that caused the collision.

The contents of the /usr/lib/python2.7/dist-packages/google dir now look like this:

/google
    /appengine
    /net
    /protobuf
    /pyglib
    /storage
    /__init__.py
    /__init__.pyc

Looks like you're getting a module (or package) called 'google' from elsewhere -- perhaps /home/tower/googlecode/mygae -- and THAT google module has no appengine in it. To check, print google.__file__ and if possible google.__path__; that should be informative.

Sometimes you can get an import error for a module when the error is something different, like a syntax error. Try putting

import pdb;pdb.set_trace()

just before the import and then s(tep) into the import, and n(ext) thruogh the module in question to see of you get an error.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!