Odoo-Exp: Odoo中的external_dependencies
-
在模块开发中,我们往往会引入第三方的python模块。比如当我们在对业务数据做统计分析时,可能会用到
pandasPython函数库。在开发者这边我们可以安装pandas包,然后在我们的代码中可以导入pandas包中的函数或类:from pandas import DataFrame这样操作,开发者本地没有问题。但是如果这个Odoo模块独立发布出去,客户拿来一安装,服务器立即吐一堆的错误信息,如下面的import错误,因为客户并不知道需要先安装
pandas:... ... ImportError: No module named pandas怎么样在安装模块时能友好的提醒用户安装需要的Python函数包,而不是丢一堆错误信息给用户呢?
首先在import的时候,做
try...except如下:try: from pandas import DataFrame except ImportError: pass然后在
__manifest__.py文件中添加external_dependencies说明,如下:"external_dependencies": { 'python': ['pandas'], 'bin': ['ffmpeg'] },其中
pythonkey 对应的是python函数包,比如这里就是要求安装pandas函数包。另外这里还有一个binkey,它对应的则是外部命令,比如上例中的`ffmpeg``就是Linux下著名的视频/图片处理命令。
Hello! It looks like you're interested in this conversation, but you don't have an account yet.
Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.
With your input, this post could be even better 💗
Register Login