bulkloader不导入ndb.model [英] bulkloader not importing ndb.model
问题描述
我对Python和GAE仍然很陌生。我有一个运行良好的本地服务器上的应用程序。我可以添加实体到我的数据存储,我可以查看我的网站等:一切正常。
现在我试图使用bulkloader将实体添加到我的数据存储中。我遵循 https://developers.google.com/appengine/docs/上的教程蟒蛇/工具/ uploadingdata 。我的装载程序如下:
from google.appengine.ext从google.appengine.tools导入ndb
导入bulkloader
导入my_model
$ b $ class ArticleLoader(bulkloader.Loader):
def __init __(self):
bulkloader.Loader .__ init __(self,'Article',
[('title',str),
('author',str)
])
loaders = [ArticleLoader]
我收到错误消息:
否模块名为my_model
有没有人为此做过修复?
注意:我只使用一个目录。因此,我的加载程序与导入
my_model
模块的其他文件位于同一位置。解决方案如果您的
PYTHONPATH
未正确设置,也会发生这种情况。如果您使用的是Linux,请在运行Bulkloader之前尝试运行它:
export PYTHONPATH = $ PYTHONPATH :.
将当前目录追加到
PYTHONPATH
并应使my_model
模块可见。由于我的记忆非常糟糕,而且我总是忘记这么做,所以我最终使用了一个简单的shell脚本,它在开始时包含了这个脚本,然后是bulkload命令。
如果你在Windows上,你应该可以通过使用
sys.path.append
来修改你的路径。还没有测试过,但你可以尝试添加到你的脚本(注意,这也适用于Linux):
import sys
#...
sys.path.append('。')
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.解决方案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 yourmy_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('.')
这篇关于bulkloader不导入ndb.model的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!