0

I am running a script in Visual Studio Code 2, for which I have the following import line from module_name.blah.foo import bar

The script works fine, but I get a "problem" message saying Import "module_name.blah.foo" could not be resolved.

If I hover above the line in the script, I get the message Import "module_name.blah.foo" could not be resolved Pylance(reportMissingImports)

As the script works, this isn't hugely important, but I would like to get rid of the ever-present list of "problems" indicated for the script in the problems window and next to the filename, so I'd like to solve this if possible.

I saw another stack overflow post that might help. However, when I tried the first step, print(module_name.__file__), I get the error NameError: name 'module_name' is not defined

Does anyone know how to deal with this?

abra
  • 153
  • 2
  • 10
  • 1
    Do you have the right python interpreter selected? https://code.visualstudio.com/docs/python/environments#_working-with-python-interpreters – ringo Jun 12 '23 at 05:32
  • @ringo Sorry, I solved this myself and never put up a solution. This was actually exactly the issue. I found & specified the python interpreter path manually, using the path within the docker container, and the warnings went away. Thanks! – abra Jul 19 '23 at 14:33

1 Answers1

0

I ended up solving this.

The solution is easy and may seem obvious, but for others like me who don't know where to look, here is what I did:

(1) Find python used in docker container: I suspected I had the wrong python interpreter, but I didn't know where to find the python interpreter used within the docker container. What worked is I opened a terminal within Visual Studio Code 2 and, starting from root ("/"), searched until I found the python interpreter.

Alternatively, typing which python in the terminal also gave me the same answer.

(2) Set interpreter path manually: I then clicked on the button on the bottom bar of the VSCode2 window that specifies the python interpreter, and entered its path manually using the path I discovered within the docker container. (See official reference for setting VSCode2 python interpreter here).

Once I did this, the warnings went away.

abra
  • 153
  • 2
  • 10