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. odoo14 自定义模块 from import 报错

odoo14 自定义模块 from import 报错

Scheduled Pinned Locked Moved Odoo 开发与实施交流
2 Posts 1 Posters 1.6k Views 1 Watching
  • 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.
  • S Offline
    S Offline
    steven
    wrote on last edited by
    #1

    请教:
    为了将自定义模块与odoo原有模块区别开来,我在另一个单独的目录(非odoo原模块所在目录)下新建了一个“myaddons”目录,结果,开发工具pycharm中代码“from odoo import models, fields, api”报错,显示
    a69533e2-c18b-4836-adff-fd09aa7f7800-image.png 。

    我能想到是解释器会先从环境变量里,再从本文件的同级目录中去查找相应的模块,没有找到才会报错。但我已经在环境变量里选择了对应的解释器。不知道是何原因?该如何解决?

    7c2af2bb-6691-420e-a974-421ea6bdb420-image.png

    S 1 Reply Last reply
    0
    • S steven

      请教:
      为了将自定义模块与odoo原有模块区别开来,我在另一个单独的目录(非odoo原模块所在目录)下新建了一个“myaddons”目录,结果,开发工具pycharm中代码“from odoo import models, fields, api”报错,显示
      a69533e2-c18b-4836-adff-fd09aa7f7800-image.png 。

      我能想到是解释器会先从环境变量里,再从本文件的同级目录中去查找相应的模块,没有找到才会报错。但我已经在环境变量里选择了对应的解释器。不知道是何原因?该如何解决?

      7c2af2bb-6691-420e-a974-421ea6bdb420-image.png

      S Offline
      S Offline
      steven
      wrote on last edited by
      #2

      @steven
      问题已经自己解决了。
      方法是将“myaddons”文件夹放到与"odoo"在同一层级的目录下即可。
      原来出现问题的可能是:import(无论绝对引用或相对引用) 需要从根节点开始查找对应模块,所以“myaddons”至少与根节点在同一目录层级或之内。

      fd09e17c-5af0-4e99-9b28-d14c99d28b6a-image.png

      1 Reply Last reply
      0

      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