'ImportError: No module named PySimpleGUI
I am attempting to use PySimpleGUI to create a very simple GUI, but when I run the command "python hello_world.py" I get the error:
File "hello_world.py", line 3, in <module>
import PySimpleGUI as sg
ImportError: No module named PySimpleGUI
I've run the command "pip install PySimpleGUI" and it says "Successfully installed PySimpleGUI-4.55.1." I'm not sure what I'm missing here.
Code snippet here:
# hello_world.py
import PySimpleGUI as sg
sg.Window(title="Hello World", layout=[[]], margins=(100,50)).read()
Solution 1:[1]
check where python is installed
import os
import sys
print(os.path.dirname(sys.executable))
>>C:\Program Files\Python310 #here 310 is python version your may be differrent
if this outputs inside C:\Program Files\Python310
check for C:\Program Files\Python310\Lib\site-packages\PySimpleGUI
if its not there then Run CMD as admin and try python -m pip install PySimpleGUI
Solution 2:[2]
Update pip to the current version via "python -m pip install --update pip".
It's strange, but my PySimpleGUI module became visible after I updated the pip from version 21.2.3 to version 22.0.4 via "python-m pip install --update pip".
Before the pip version update, the contents of my local environment looked like this:
(env) D:\work\PycharmProjects\demo>pip list
Package Version
----------- -------
flake8 4.0.1
mccabe 0.6.1
pip 21.2.3
pycodestyle 2.8.0
pyflakes 2.4.0
setuptools 57.4.0
WARNING: You are using pip version 21.2.3; however, version 22.0.4 is available.
You should consider upgrading via the 'D:\work\PycharmProjects\demo\env\Scripts\python.exe -m pip install --upgrade pip' command.
After the update:
(env) D:\work\PycharmProjects\demo>pip list
Package Version
----------- -------
flake8 4.0.1
mccabe 0.6.1
pip 22.0.4
pycodestyle 2.8.0
pyflakes 2.4.0
PySimpleGUI 4.57.0
setuptools 57.4.0
And the program hello_world.py it began to run successfully.
Solution 3:[3]
EDIT Dec2021:
This seems to me like an bug with pip rather than PySimpleGUI. Try this https://pip.pypa.io/en/stable/installation/ reinstall pip in the python interpreter using this.
Original Answer:
You can check all the installed packages with
python3 -m pip list
And see if you find PySimpleGUI in it. If yes then python3 hello_world.py should work if not (i suspect latter) run
python3 -m pip install PySimpleGUI
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Suraj Shejal |
| Solution 2 | Dmitry Y. |
| Solution 3 |
