1

I am working on a script which calls easygui. This has been added to the virtual environment.

The lines involving easygui are

#import module
from easygui import *
#set message and title
msg="Hello World!"
title="Sample Program"
# a simple window showing a message, a title and a ‘Ok’ button
msgbox(msg,title)

The script throws the error below. However, it runs perfectly when I call it from the command line. Why is pycharm throwing an error, but not the command line? Thanks.

Traceback (most recent call last):
  File "/Users/nickriches/PycharmProjects/pythonProject3/main.py", line 12, in <module>
    from easygui import *
  File "/Users/nickriches/PycharmProjects/pythonProject3/venv/lib/python3.7/site-packages/easygui/__init__.py", line 34, in <module>
    from .boxes.button_box import buttonbox
  File "/Users/nickriches/PycharmProjects/pythonProject3/venv/lib/python3.7/site-packages/easygui/boxes/button_box.py", line 18, in <module>
    import global_state
ModuleNotFoundError: No module named 'global_state'

Nick Riches
  • 317
  • 2
  • 13
  • Does [this](https://stackoverflow.com/questions/16886921/can-someone-help-troubleshooting-easygui-with-me) help? – The Singularity Feb 24 '21 at 17:15
  • Thanks. I am installing it in the virtual environment within pycharm using the pycharm interface (the + button at the bottom of the screen). – Nick Riches Feb 24 '21 at 17:23

1 Answers1

1

I had this error this afternoon (MacOS M1, running python 3.9), and this is how I fixed it.

Basically the error is caused by the absence of a properly functioning tkinter installation, even though the error is complaining about "global_state". You can work this out by tracing through the code, which I will not do here.

You can prove to yourself that there is a defect in your tkinter installation by opening python in REPL mode and typing:

"import tkinter".

If you get an error, then you are on the right track to continue below.

The solution therefore is to properly get tkinter working.

I installed tkinter on my Mac by going to https://www.activestate.com/products/tcl/downloads/ and installing it.

Then I installed the "python-tk" module by running:

"brew install python-tk".

After that, when I opened python in REPL and ran "import tkinter", things worked.

Dharman
  • 30,962
  • 25
  • 85
  • 135
Soferio
  • 483
  • 6
  • 14
  • Thanks. Sorry for not picking up on this reply sooner. I am not sure what REPL mode is but I can verify that tkinter fails to import in PyCharm. I downloaded tkinter (package requiring installation), and tried the brew install, but I couldn't get this to work. – Nick Riches May 07 '21 at 12:28