Pylance Showing Yellow Wavy Line Under Module Name When Importing It Even Code Works Fine

Viewed 123

enter image description here

Pylance is showing reportMissingImports even I installed it and code works fine. I can run the code but it was still a very annoying nuisance. How do I fix this? I tried restarting Visual Studio Code and look at it again. Didn't work.

Here is my code. Perhaps it will help.

import cryptocode

str_encoded = cryptocode.encrypt("Encrypted Text", "p")
## And then to decode it:
str_decoded = cryptocode.decrypt(str_encoded, "p")
print(str_decoded)
1 Answers

Make sure you have selected the correct python interpreter.

In your picture it is clear that you have chosen python310 version interpreter, but your cryptocode package is installed under python311 version.

enter image description here

How to choose a python interpreter:

Click directly on the python version in the lower right corner or use Ctrl+Shift+P to open the command palette and choose Python:Select Interpreter, then choose the appropriate python interpreter.

Why did you choose the wrong interpreter and still run successfully:

You run the code directly using the python command in the terminal, your computer should have the environment variable python311 added, or other settings make it the default python version is 311.

If you run the code with the play button in the top right corner, it will use the python interpreter you chose for VS Code (in this case you will get the ModuleNotFoundError: No module named 'cryptocode' error).

Related