bulkloader not importing ndb.model

不想你离开。 提交于 2020-01-03 04:24:09

问题


I am still new to Python and GAE. I have an application on local server that is running just fine. I can add entity to my datastore, I can view my website, etc: everything is fine.

Now I am trying to use bulkloader to add entities to my datastore. I followed the tutorial at https://developers.google.com/appengine/docs/python/tools/uploadingdata. My loader is below:

from google.appengine.ext import ndb
from google.appengine.tools import bulkloader
import my_model

class ArticleLoader(bulkloader.Loader):
  def __init__(self):
    bulkloader.Loader.__init__(self, 'Article',
                               [('title', str),
                                ('author', str)
                                ])

loaders = [ArticleLoader]

I am getting the error:

No module named my_model

Does anyone have a fix for this?

Note: I am only using one directory. So my loader is in the same location as the other file that imports the my_model module.


回答1:


This can also happen if your PYTHONPATH is not properly set up. If you're on Linux, try running this before you run the Bulkloader:

export PYTHONPATH=$PYTHONPATH:.

This appends your current directory to your PYTHONPATH and should make your my_model module visible. Since my memory is terrible and I always forget to do it, I've ended up using a simple shell script that includes this at the beginning and then the bulkload command itself.

If you're on Windows, you should be able to modify your path by using sys.path.append. Haven't tested this, but you could try adding this to your script (note that this should work on Linux as well):

import sys
# ...
sys.path.append('.')



回答2:


Your code should be located in a file named my_model.py. You are getting that error because there is no module named my_module. Might be worth a read of the Python module and package docs.



来源:https://stackoverflow.com/questions/13777605/bulkloader-not-importing-ndb-model

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