Skip to content
  • Categories
  • Tags
  • Popular
  • Users
  • Groups
Skins
  • Light
  • Brite
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (Flatly)
  • No Skin
Collapse

Odoo 中文社区

  1. Home
  2. Categories
  3. Odoo 培训
  4. Odoo-Exp: Odoo中的external_dependencies

Odoo-Exp: Odoo中的external_dependencies

Scheduled Pinned Locked Moved Odoo 培训
1 Posts 1 Posters 1.2k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • D Offline
    D Offline
    digitalsatori
    管理员
    wrote on last edited by digitalsatori
    #1

    在模块开发中,我们往往会引入第三方的python模块。比如当我们在对业务数据做统计分析时,可能会用到pandas Python函数库。在开发者这边我们可以安装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']
    },
    

    其中python key 对应的是python函数包,比如这里就是要求安装pandas函数包。另外这里还有一个bin key,它对应的则是外部命令,比如上例中的`ffmpeg``就是Linux下著名的视频/图片处理命令。

    【上海先安科技】(tony AT openerp.cn)

    1 Reply Last reply
    2

    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
    Reply
    • Reply as topic
    Log in to reply
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes


    • Login

    • Don't have an account? Register

    • Login or register to search.
    • First post
      Last post
    0
    • Categories
    • Tags
    • Popular
    • Users
    • Groups