Import “PySimpleGUI” could not be resolved

by Daniel Pham
Published: Updated:

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

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.

Import "PySimpleGUI" could not be resolved
Find the setting python.analysis.extraPaths

Then the result look like this one.

Import "PySimpleGUI" could not be resolved
Add path of folder lib PySimpleGUI.

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 !

5 1 vote
Article Rating

You may also like

Subscribe
Notify of
guest
2 Comments
Newest
Oldest Most Voted
Inline Feedbacks
View all comments
Geeta
Geeta
Guest
1 year ago

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

DevOps Lite is a personal blog specializing in technology with main topics about DevOps, DevSecOps, SRE and System Administrator. Articles are shared for free and contributed to the community.

SUPPORT US

FOLLOW US

Subscribe my Newsletter for new blog posts. Stay updated from your inbox!

© 2021-2024 DevOpsLite.com – All rights reserved.

Please write sources “DevOpsLite.com” when using articles from this website.

This website uses cookies to improve your experience. We'll assume you're ok with this, but you can opt-out if you wish. Accept Read More

0
Would love your thoughts, please comment.x
()
x

Adblock Detected

Please support us by disabling your AdBlocker extension from your browsers for our website.