rockstiff
rockstiff

Reputation: 383

VScode unresolved import

Im working on a project and want to start using VScode (currently using sublime). The problem is that when i import the folder and open the files, a lot of functions show undefined-variable and undefined-import for the modules.

The file structure is something like this:

trunk
|--libs
    |--proj
         |--module1
         |--module2
|--scripts
    |--script.py

and in my script.py i have

from proj import module1 (here shows the error undefined-import).

module1.functionA() (shows undefined-variable)

Already tried to select the interpreter and reload window in vscode but didnt work. I found that if i use from libs.proj import module1 it works ok, but fails when i run the script. In sublime, from proj import module1 works ok.

Also in my launch.json i have

  "env": {
    "PYTHONPATH": "~/Desktop/project/trunk/libs/"
  },

We dont work with virtual envs. Any ideas?

Upvotes: 3

Views: 1133

Answers (1)

rockstiff
rockstiff

Reputation: 383

So, digging more into google, found an answer to my problem.

Added in settings.json the folow lines:

"python.autoComplete.extraPaths": [
  "${workspaceRoot}/libs/"   
],

So now from proj import module1 works fine

Upvotes: 3

Related Questions