0

I have a python project, where I have

  • my own modules in subfolders
  • my_paths.py that has all the paths to my_modules
  • a main.py
└── GITHUB_STACK_REPO/ 
    └── Project_root /
        ├── analyzing/
        │   └── py
        ├── filtering/
        │   └── py/
        │       ├── my_module_a.py
        │       └── my_module_a_test.py
        ├── my_paths.py
        └── main.py

This is my_paths.py

import os 
from pathlib import Path
import sys

ROOT_DIR = Path(os.path.dirname(os.path.abspath(__file__)))
my_module_a_DIR = ROOT_DIR.joinpath(r"filtering\py").resolve()

 # add to sys path
sys.path.append(str(my_module_a_DIR))

my_module_a.py

def filter():
    '''
    Some doc string
    ''' 
    print ("filter_function_called")

and main:

import my_paths
import my_module_a

my_module_a.filter()

OUT: #the function works 
filter_function_called

The function runs, however I get a highlited text (inVSCODE) with:

Import "my_module_a" could not be resolvedPylancereportMissingImports

enter image description here And I cannot use autofill with my_module_a.

The first answer at import pathto own script I am able to solve the problem (modleus are recognized, and autofill works).

Howver it doesn't solve the problem for others using this code, so:

  • Is there a simple code-structure reorganization to allow to find the modules
  • Can a file with all the relative paths to modules be written, so that pylance recognizes all the paths?
Leo
  • 1,176
  • 1
  • 13
  • 33

0 Answers0