Skip to Content
Menu
This question has been flagged
9 Replies
22867 Views


First of i want to say that this issue is not breaking my installation its just hindering in my workflow.

When i import the odoo module like so: "from odoo import api, models, fields" i get the follwing warning:

'unresolved import 'odoo'Python(unresolved-import)' and there is a wavy line  underneath the word odoo.

Also because VSCode doesnt recognize odoo everytime the work fields is written i get a warning: 'Undefined variable:' fields'

As i said before i can compile and everything runs like expected but i see alot of warning i cant get rid of.

I googled the issue but couldnt find anything that fixed the problem.

I am probably missing something in my config files somewhere. 

Thanks for your help in advance.

Best wishes,

 Sebastian


Avatar
Discard
Best Answer

To properly import odoo without a sweat, there's a simple tutorial: 


Avatar
Discard
Best Answer

File -> Preferences -> Settings -> type import -> Choose Python on the left

Click on "Edit in settings.json":

"python.analysis.extraPaths": ["/your/path/to/odoo-16.0/" ]

Restart VS Code and enjoy.

Avatar
Discard
Best Answer

Following process worked for me:

Open Workspace Settings:

  • In the Command Palette, search for Preferences: Open Workspace Settings (JSON), or select the workspace tab if you see it in the settings menu.

Add python.analysis.extraPaths in Workspace settings.json:

  • Add the following line with the path to your Odoo source:
    jsonCopy code"python.analysis.extraPaths": [
        "/your/path/to/odoo-16.0/"
    ]
    
  • Replace "/your/path/to/odoo-16.0/" with the actual path to your Odoo source folder.

Save and Restart:

  • Save your changes in the settings.json file and restart VS Code to apply the settings.
Avatar
Discard
Best Answer

Hi, I know your question was a long time ago but I'm new to odoo and I have this same problem. Finally, how did you solve it? I tried the solutions they gave you but it didn't work.

Avatar
Discard
Best Answer

Hello, I find myself having the same problem, did you manage to solve it????

I have spent several days looking for a way to solve the problem but still can't find it... 

Avatar
Discard
Best Answer

Do you have how to solve this problem ?

i have temporary problem to solve it
1. add the folder script in setting.json and add python.analysis.extraPaths setting for the workspace.
'Import "Path.to.own.script" could not be resolved Pylance (reportMissingImports)' in VS Code using Python 3.x on Ubuntu 20.04 LTS. but this is not work for me
2. below the SO answer, there are (1) 
In VS code you can edit the setting.json file. If you add "python.analysis.useImportHeuristic": true the linting error will be removed. i think this is dangerous because make you not cant see problem
3. (2) The alternative is to add # type: ignore at the end of the import code. i like this answer after compile and there are no error, i can put #type : ignore and problem is gone

Avatar
Discard
Best Answer

That wavy line you are seeing because you may be opening a folder which contains odoo. Try opening only odoo named folder that you have downloaded at the time of installation. Your issue will be solved.

It troubled me as well when i initially started using odoo.

Avatar
Discard

On the contrary, the squiggly line appears because the odoo folder is not included, so the vscode app opens the directory at the next level. For example, your vscode works in the odoo-dev/my_library folder, and the odoo module from odoo import models, fields will have wavy lines. To solve it simply, vscode can open the directory odoo-dev at the next level as the working directory. Tip: There's odoo-dev/odoo inside

Author Best Answer

Sorry our company only uses VSCode so PyCharm is not an option for us. Thank you anyways

Avatar
Discard
Best Answer

Have you tried PyCharm? This editor has many advantages over VSCode as is its search for code based on regex. It does not answer your question but the alternative is worth trying.

Avatar
Discard

VS Code does everything you can do with Pycharm and more, Regex search is possible.
The only issue I've seen, which is more of a Windows + VsCode issue, is that it doesn't always end the process on rebuild.

PS: I've used PyCharm for 3 Years, and VS Code since it was released for multiple languages and stacks.

Related Posts Replies Views Activity
2
May 24
1271
2
Dec 21
6543
0
Oct 20
5230
6
Sep 20
4273
2
Nov 19
5842