Import “PySimpleGUI” could not be resolved
If you see above message when try to import library PySimpleGUI in VSCode, I hope this simple trick can help you.
Import “PySimpleGUI” could not be resolved
Table of Contents
I learning about python GUI and found some great tutorials on Youtube. Most of them guide about PySimpleGUI so I decided to learn it.
First of all, my laptop is running Zorin OS 16, it is base on Ubuntu.
So if you’re using Ubuntu or some kind of OS base on Ubuntu, there is no problem with this trick.
Some other information about my environment:
- Python version 3.8.10
- Install pip with this command:
sudo apt-get install python3-pip
- Install PySimpleGUI with this command:
python3 -m pip install pysimplegui
And then, on my VSCode, I imported the lib with this lines:
# Import lib to create GUI
import PySimpleGUI as sg
But the VSCode shows me an error:
Import “PySimpleGUI” could not be resolved
Fix import “PySimpleGUI” could not be resolved
This error happened because of VSCode doesn’t know the path to folder lib PySimpleGUI. We have to define its path to VSCode.
As this post, I know that the lib for Python usually place at 2 paths:
/usr/lib/python3.8/site-packages
/usr/local/lib/python3.8/site-packages
But when I tried to find the lib PySimpleGUI inside 2 paths above, it’s not there.
So I tried another command to find it.
sudo find / -type d -name "PySimpleGUI"
And the result let me know that lib is place on my home folder.
/home/dung/.local/lib/python3.8/site-packages/PySimpleGUI
Okay, now how to define above path to VSCode. Quite simple, follow this post, you open VSCode’s settings.
Search for this string: python.analysis.extraPaths
You will see a window like below. Then click button Add Item. Add the path of folder lib PySimpleGUI that found above to it and click OK.
Then the result look like this one.
And all done.
Conclusion
After you define the path of folder lib PySimpleGUI to VSCode, the error will gone. And you can enjoy to code your app, cheer !
Hi Dung,
Can you tell me why i can open my file -> right click, open with VSCode then it runs well (has tkinter module ) but when i open the folder inside VSCode and open python file from there, it sys tkinter module not found?
I am sure some config issues, but im not able to resolve