0

I am using vscode with python and other languages in a single project. The directory structure is like this:

- base
 - python
  - foo
    foo.py
  - bar
    bar.py
 - bin
 - etc

I am getting 'python(unresolved import)' warnings in vscode when importing modules such as 'foo'.

I used a solution provided by Tomasz C. here: Pylint "unresolved import" error in visual studio code

In my case I have a .env file with

PYTHONPATH=python/

This does not work!

I have renamed this portion of my directory structure to anything else (like PYTHONPATH=python2/) and it does work.

I have also tried multiple linters with no change.

I am not in control of the naming of these directories. Is there some way I can get linting with vscode to work with existing directory structure?

jwodder
  • 54,758
  • 12
  • 108
  • 124

1 Answers1

1

PYTHONPATH should point to a valid python executable instance, it should be the one being used by your environment, so you have to give it the full absolute path, not a relative one. example: /home/user/environment/bin/python, change it according to your setup.

c0x6a
  • 427
  • 1
  • 6
  • 14
  • You are referring to a different python path. There is python.pythonPath in the settings.json, which refers to the executable. I am referring to the environment variable PYTHONPATH: https://docs.python.org/3/using/cmdline.html#envvar-PYTHONPATH – Denjack Jun 11 '19 at 20:23
  • OH, ok, then use just `python` **without** the trailing slash you put `/` or try: `environment/bin/python` (change according your environment setup) – c0x6a Jun 11 '19 at 20:38
  • Thanks, but still no go. I should reiterate that it works with any text other than 'python'. Example: 'pythona' works. – Denjack Jun 11 '19 at 21:46