1

I have a python project where the first line of code is something like sys.path.insert(0, /some/path). Then I try to import from this path. The code works at runtime, but VSCode can't figure out where this package is, and so I get squigglies on the import statements, and it's unable to auto-complete any of the types or methods from the modules in this package.

I'm aware of virtual environments, but is there some way to let VSCode know about this path without going through the hassle of setting up a venv?

I've also tried using a .env file as described here, but I can't get that to work either.

My workspace is D:\code\Util

My env file is D:\code\.env

My python package is D:\code\python\packagename

My settings.json is C:\Users\divis\AppData\Roaming\Code\User\settings.json.

The contents of my settings.json are:

{
    "security.workspace.trust.untrustedFiles": "open",
    "python.envFile": "D:/code/.env"
}

The contents of my .env file are:

PYTHONPATH=python

Then in my code I do this:

sys.path.insert(0, 'D:/code/python')
import packagename

and PyLint can't find it. Is one of the steps above incorrect?

Zachary Turner
  • 738
  • 4
  • 24

1 Answers1

0

I had a similar problem, with a directory format like this

  • C:\someCode\some_lib\some_utility.py
  • C:\someCode\some_app\my_application.py
#import some_lib/some_utility   # pylance shows error 

The solution for me was to add something like this to settings.json

"python.analysis.extraPaths": [
        "../"
    ]