无法通过 ImportError [Odoo 9.0]
Can't get past ImportError [Odoo 9.0]
我刚刚 运行 浏览了 v9 的 "Building a Module" 文档,并且正在跟进。
我的代码看起来与此处的示例相同:https://www.odoo.com/documentation/9.0/howtos/backend.html。
当我启动服务器时,这是我的错误:
Traceback (most recent call last):
File "/usr/lib/python2.7/dist-packages/werkzeug/serving.py", line 177, in run_wsgi
execute(self.server.app)
File "/usr/lib/python2.7/dist-packages/werkzeug/serving.py", line 165, in execute
application_iter = app(environ, start_response)
File "/usr/lib/python2.7/dist-packages/openerp/service/server.py", line 245, in app
return self.app(e, s)
File "/usr/lib/python2.7/dist-packages/openerp/service/wsgi_server.py", line 184, in application
return application_unproxied(environ, start_response)
File "/usr/lib/python2.7/dist-packages/openerp/service/wsgi_server.py", line 170, in application_unproxied
result = handler(environ, start_response)
File "/usr/lib/python2.7/dist-packages/openerp/http.py", line 1488, in __call__
return self.dispatch(environ, start_response)
File "/usr/lib/python2.7/dist-packages/openerp/http.py", line 1462, in __call__
return self.app(environ, start_wrapped)
File "/usr/lib/python2.7/dist-packages/werkzeug/wsgi.py", line 579, in __call__
return self.app(environ, start_response)
File "/usr/lib/python2.7/dist-packages/openerp/http.py", line 1637, in dispatch
ir_http = request.registry['ir.http']
File "/usr/lib/python2.7/dist-packages/openerp/http.py", line 360, in registry
return openerp.modules.registry.RegistryManager.get(self.db) if self.db else None
File "/usr/lib/python2.7/dist-packages/openerp/modules/registry.py", line 354, in get
update_module)
File "/usr/lib/python2.7/dist-packages/openerp/modules/registry.py", line 385, in new
openerp.modules.load_modules(registry._db, force_demo, status, update_module)
File "/usr/lib/python2.7/dist-packages/openerp/modules/loading.py", line 334, in load_modules
force, status, report, loaded_modules, update_module)
File "/usr/lib/python2.7/dist-packages/openerp/modules/loading.py", line 237, in load_marked_modules
loaded, processed = load_module_graph(cr, graph, progressdict, report=report, skip_modules=loaded_modules, perform_checks=perform_checks)
File "/usr/lib/python2.7/dist-packages/openerp/modules/loading.py", line 123, in load_module_graph
load_openerp_module(package.name)
File "/usr/lib/python2.7/dist-packages/openerp/modules/module.py", line 324, in load_openerp_module
__import__('openerp.addons.' + module_name)
File "/usr/lib/python2.7/dist-packages/openerp/modules/module.py", line 61, in load_module
mod = imp.load_module('openerp.addons.' + module_part, f, path, descr)
File "/home/lslaz/odoo-dev/addons/openacademy/__init__.py", line 2, in <module>
from . import models
ImportError: cannot import name models
^C2016-02-03 19:54:08,626 3329 INFO ? openerp.service.server: Initiating shutdown
2016-02-03 19:54:08,626 3329 INFO ? openerp.service.server: Hit CTRL-C again or send a second signal to force the shutdown.
如果我从 init.py 中删除 "from . import models",我会得到一个不同的错误:
ParseError: "Invalid model name in the action definition.
None" while parsing /home/lslaz/odoo-dev/addons/openacademy/views/views.xml:8, near
<record model="ir.actions.act_window" id="course_list_action">
<field name="name">Courses</field>
<field name="res_model">openacademy.course</field>
<field name="view_type">form</field>
<field name="view_mode">tree,form</field>
<field name="help" type="html">
<p class="oe_view_nocontent_create">
Create the first course
</p>
</field>
</record>
请帮忙!我相信这两件事都是应该的,但在我弄清楚问题出在哪里之前我无法前进。
尝试从行 from . import models
中删除 .
,使其显示为 from import models
。
我不知道为什么,但在我的例子中,Odoo 在新应用程序中生成类似 .py 文件的模型,但不像文件夹。
如果你想为你的模型使用文件夹,你需要:
1) 像这样在 __init__.py
中导入模型:
# -*- coding: utf-8 -*-
import models
2) 在文件夹 models 中创建 __init__.py
并像这样导入所有模型:
# -*- coding: utf-8 -*-
import my_model_one
import one_more_model
# etc.
我知道这有点晚了,但我也在学习教程,这是我解决这个问题的方法:
创建 wizard.py 文件时,教程未显示必要的导入。但是你必须导入以下内容:
# -*- coding: utf-8 -*-
from openerp import fields, models, api
class Wizard(models.TransientModel): ...
希望这对某人有所帮助。
我刚刚 运行 浏览了 v9 的 "Building a Module" 文档,并且正在跟进。
我的代码看起来与此处的示例相同:https://www.odoo.com/documentation/9.0/howtos/backend.html。
当我启动服务器时,这是我的错误:
Traceback (most recent call last):
File "/usr/lib/python2.7/dist-packages/werkzeug/serving.py", line 177, in run_wsgi
execute(self.server.app)
File "/usr/lib/python2.7/dist-packages/werkzeug/serving.py", line 165, in execute
application_iter = app(environ, start_response)
File "/usr/lib/python2.7/dist-packages/openerp/service/server.py", line 245, in app
return self.app(e, s)
File "/usr/lib/python2.7/dist-packages/openerp/service/wsgi_server.py", line 184, in application
return application_unproxied(environ, start_response)
File "/usr/lib/python2.7/dist-packages/openerp/service/wsgi_server.py", line 170, in application_unproxied
result = handler(environ, start_response)
File "/usr/lib/python2.7/dist-packages/openerp/http.py", line 1488, in __call__
return self.dispatch(environ, start_response)
File "/usr/lib/python2.7/dist-packages/openerp/http.py", line 1462, in __call__
return self.app(environ, start_wrapped)
File "/usr/lib/python2.7/dist-packages/werkzeug/wsgi.py", line 579, in __call__
return self.app(environ, start_response)
File "/usr/lib/python2.7/dist-packages/openerp/http.py", line 1637, in dispatch
ir_http = request.registry['ir.http']
File "/usr/lib/python2.7/dist-packages/openerp/http.py", line 360, in registry
return openerp.modules.registry.RegistryManager.get(self.db) if self.db else None
File "/usr/lib/python2.7/dist-packages/openerp/modules/registry.py", line 354, in get
update_module)
File "/usr/lib/python2.7/dist-packages/openerp/modules/registry.py", line 385, in new
openerp.modules.load_modules(registry._db, force_demo, status, update_module)
File "/usr/lib/python2.7/dist-packages/openerp/modules/loading.py", line 334, in load_modules
force, status, report, loaded_modules, update_module)
File "/usr/lib/python2.7/dist-packages/openerp/modules/loading.py", line 237, in load_marked_modules
loaded, processed = load_module_graph(cr, graph, progressdict, report=report, skip_modules=loaded_modules, perform_checks=perform_checks)
File "/usr/lib/python2.7/dist-packages/openerp/modules/loading.py", line 123, in load_module_graph
load_openerp_module(package.name)
File "/usr/lib/python2.7/dist-packages/openerp/modules/module.py", line 324, in load_openerp_module
__import__('openerp.addons.' + module_name)
File "/usr/lib/python2.7/dist-packages/openerp/modules/module.py", line 61, in load_module
mod = imp.load_module('openerp.addons.' + module_part, f, path, descr)
File "/home/lslaz/odoo-dev/addons/openacademy/__init__.py", line 2, in <module>
from . import models
ImportError: cannot import name models
^C2016-02-03 19:54:08,626 3329 INFO ? openerp.service.server: Initiating shutdown
2016-02-03 19:54:08,626 3329 INFO ? openerp.service.server: Hit CTRL-C again or send a second signal to force the shutdown.
如果我从 init.py 中删除 "from . import models",我会得到一个不同的错误:
ParseError: "Invalid model name in the action definition.
None" while parsing /home/lslaz/odoo-dev/addons/openacademy/views/views.xml:8, near
<record model="ir.actions.act_window" id="course_list_action">
<field name="name">Courses</field>
<field name="res_model">openacademy.course</field>
<field name="view_type">form</field>
<field name="view_mode">tree,form</field>
<field name="help" type="html">
<p class="oe_view_nocontent_create">
Create the first course
</p>
</field>
</record>
请帮忙!我相信这两件事都是应该的,但在我弄清楚问题出在哪里之前我无法前进。
尝试从行 from . import models
中删除 .
,使其显示为 from import models
。
我不知道为什么,但在我的例子中,Odoo 在新应用程序中生成类似 .py 文件的模型,但不像文件夹。
如果你想为你的模型使用文件夹,你需要:
1) 像这样在 __init__.py
中导入模型:
# -*- coding: utf-8 -*-
import models
2) 在文件夹 models 中创建 __init__.py
并像这样导入所有模型:
# -*- coding: utf-8 -*-
import my_model_one
import one_more_model
# etc.
我知道这有点晚了,但我也在学习教程,这是我解决这个问题的方法:
创建 wizard.py 文件时,教程未显示必要的导入。但是你必须导入以下内容:
# -*- coding: utf-8 -*-
from openerp import fields, models, api
class Wizard(models.TransientModel): ...
希望这对某人有所帮助。