3

I am trying to explore PySimpleGUI. Following this link PySimpleGUI

But when I do,

import PySimpleGUI

getting error as,

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python3.7/site-packages/PySimpleGUI/__init__.py", line 2, in <module>
    from .PySimpleGUI import *
  File "/usr/local/lib/python3.7/site-packages/PySimpleGUI/PySimpleGUI.py", line 4, in <module>
    import tkinter as tk
  File "/usr/local/lib/python3.7/tkinter/__init__.py", line 36, in <module>
    import _tkinter # If this fails your Python may not be configured for Tk
ModuleNotFoundError: No module named '_tkinter'

I tried,

sudo apt-get install python3-tk 
and
sudo apt-get install python3.7-tk 

but could not get rid of the above mentioned error.

My current system details:

OS - Ubuntu 19.04
python - Python 3.7.3
PySimpleGUI - 3.29.0
tcl - 8.6.9

How to solve this issue?

Charles Merriam
  • 19,908
  • 6
  • 73
  • 83
2017kamb
  • 192
  • 3
  • 8
  • 27
  • Just to be clear, this is entirely a tkinter/system config problem. Really doesn't have anything to do with PySimpleGUI itself. If you wanted to code with tkinter, this would be the problem that would immediately happen. The same error will happen: ModuleNotFoundError: No module named '_tkinter' – Mike from PSG Jan 20 '21 at 20:47

5 Answers5

4

Now I am able to solve the issue, for that I used pyenv and install python through pyenv.

I used the following steps:

curl -L https://raw.githubusercontent.com/yyuu/pyenv-installer/master/bin/pyenv-installer | bash
sudo apt update && sudo apt upgrade
sudo apt-get install -y make build-essential libssl-dev zlib1g-dev libbz2-dev libreadline-dev libsqlite3-dev wget curl llvm libncurses5-dev git

Add to ~/.bashrc

export PATH="~/.pyenv/bin:$PATH"
eval "$(pyenv init -)"
eval "$(pyenv virtualenv-init -)"

Reload bashrc

source ~/.bashrc

Install python latest version

pyenv install 3.7.0

list python versions

pyenv versions

set global version

pyenv global 3.7.0

check python version

python -V

install PySimpleGUI

pip3 install PySimpleGUI

That's it, now I am able to import PySimpleGUI.

import PySimpleGUI
2017kamb
  • 192
  • 3
  • 8
  • 27
  • Virtual environments often cause these "missing package" type errors. Did you start out using a virtual environment and that's the root cause of your problem, or did you introduce them as part of the solution only? – Mike from PSG May 24 '19 at 12:26
  • I used virtual environment as part of the solution. – 2017kamb May 26 '19 at 03:04
1

tk is already in python - you don't need to install it.

You can try these steps:

- reinstall the python3
- (on UNIX* OS) use pip3, not pip
- pip3 install PySimpleGUI
- pip3 install --upgrade --force PySimpleGUI
JayRizzo
  • 3,234
  • 3
  • 33
  • 49
Nikolay Gogol
  • 819
  • 7
  • 6
  • I did, sudo apt-get remove python3.7 sudo apt-get install python3.7 pip3 install PySimpleGUI but still issue is not resolved – 2017kamb May 23 '19 at 06:00
  • This sounds like a tkinter installation problem. Take PySimpleGUI out of the equation. If you run python3 and type >>> import tkinter, and it fails, then you've still not fixed the problem. Are there problems with tk releasing on some versions on Linux? – Mike from PSG May 23 '19 at 12:22
0

You can try this to list all packages under pip. Tkinter should be installed by default and PySimpleGUI should show up in the list.

python -m pip list
kephalian
  • 84
  • 6
0

I solved this problem by using Conda

I uninstalled python and installed python through Conda. Then I created a new project that uses Conda as the env and simply chose which version of Python I wanted, and then it worked.

cigien
  • 57,834
  • 11
  • 73
  • 112
0

I solved the issue by going to Visual Studio Code - bottom right where it says the Python version. I had 2 choices: Python 3.10.7 ('.venv':venv) - selected Python 3.10.7 64 bit (C:\Program Files\Python310\Python.exe

First one was selected, I switched to the 64 bit one and "import PySimpleGUI as sg" was successfull. Maybe PySimpleGUI is only compatible with Python 64 bit?

Dumitru Daniel
  • 571
  • 4
  • 19