如何在App Engine上进行相对导入? (Python) [英] How to do relative imports on app engine? (python)
问题描述
我正在尝试使用python在App Engine中进行相对导入.这是我的基本情况:
I'm trying to do a relative import in App Engine using python. Here is my basic situation:
app/
models.py
app.yaml
/mymodule/
test.py
mymodule.yaml
我正在尝试导入models.py ..基本上,我具有在不同模块中使用的相同数据存储区模型,因此我希望能够从test.py(或任何其他内部)中导入models.py模块).
I'm trying to import models.py.. basically I have the same datastore models that are being using across different modules, so I was hoping to be able to import models.py from within test.py (or any other module).
相对导入如何与App Engine一起使用?谢谢.
How do relative imports work with App Engine? Thanks.
编辑:我的app.yaml文件:
Edit: My app.yaml file:
application: [my app name]
version: main
runtime: python27
api_version: 1
threadsafe: true
inbound_services:
- mail
builtins:
- appstats: on
handlers:
[my handlers]
libraries:
- name: webapp2
version: "2.5.1"
- name: jinja2
version: latest
- name: markupsafe
version: latest
- name: ssl
version: latest
推荐答案
我相信解决方案是将mymodule.yaml
放在应用程序下.似乎PYTHONPATH
中代码的根目录是模块的yaml
文件所在的目录.
I believe the solution is to put the mymodule.yaml
under app. It seems that the root of your code in the PYTHONPATH
is the directory where your module's yaml
file is.
这篇关于如何在App Engine上进行相对导入? (Python)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!