CTRL+Click not working in Visual Studio Code for Python imports that are not in sub directories

Viewed 86

First of all I want to say I have searched for this on several occasions, but I could not find a solution that worked.

I have a folder structure similar to the following (names have been generalized)

Dev
 |-> MyModules
 |   |-> Module1
 |   |   |-> Module1.py
 |   |-> Module2
 |   |   |-> Module2.py
 |   |-> Module3
 |   |   |-> Module3.py
 |-> Project 1
 |   |-> ScriptA.py
 |   |-> ScriptB.py
 |-> Project 2
 |   |-> ScriptC.py
 |   |-> ScriptD.py

Then in the script (say ScriptA.py) there is:

from pathlib import Path
import sys
sys.path.append(Path(__file__).resolve().parents[1].__str__())

import MyModules.Module1.Module1 as M1
M1.Foo()

The ScriptA.py runs and debugs fine, but if I Ctrl+Click on Foo() or M1 I get a unresolved tab and a message saying the editor cannot open the file as it is not found.

I have tried to add the MyModules and other various combinations of paths to the workspace, but this has done nothing.

I hope there is a solution as I like using the CTRL+Click and auto complete feature.

0 Answers
Related