Search code examples
python-3.xtkinterinstallationpysimplegui

unable to import PySimpleGUI


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?


Solution

  • 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