I am getting pylint errors in VSCode that say they are unable to import local files. However, I am able to run the files through the debugger with no problem. I thought that pylint used the same PYTHONPATH that the interpreter uses, so I don't know why this is happening.
I have my code set up like so:
dir0
-dir1
--__init__.py
--src
---__init__.py
---srcdir1
----__init__.py
----file1.py
---srcdir2
----__init__.py
----file2.py
file1.py looks like this:
def func1():
return 1
file2.py looks like this:
from srcdir1.file1 import func1
func1()
in launch.json I have:
"env": {"PYTHONPATH": "/full/path/to/dir0/dir1/src:/usr/local/bin/python"}
Pylint is giving me an import error around "from srcdir1.file1". When I go into the debugger and click run debugger, the file runs with no issues. However, if I right click and select Run Code, I get import errors that match the pylint errors.
EDIT:
I created a file in my workspace folder called .env
in my workspace folder. It is as follows:
PYTHONPATH=/Library/Python/2.7/site-packages:/Users/user/path/dir0/dir1/src:/Users/user/path/client/src:/Users/user/path/product/src
Interestingly, I can import from product (the third in the list) but not from client. Is there somewhere that this environment is being overridden?
I also have the following in the file:
import os
import shutil
import sys
For some reason, import sys
(but not the others) gives me the following error: unresolved import 'sys'Python(unresolved-import)