First time here? Check out the FAQ!
1

How can I run a PyGTK program in WingIDE?

I have a Python module that I used to be able to run from within WingIDE on Windows, that has the following GTK code in the header:

from gi import require_version
require_version('Gtk', '3.0')
from gi.repository import Gtk, Gdk, Pango

But since I've gotten a new computer, I can't seem to get the PyGObject modules set up in my Python 3.8.10 installation, i.e. "import gi" and related commands don't work.

At https://pygobject.readthedocs.io/en/lat… it talks about installing msys2 to use pyGObject in Windows, and if I follow those instructions, I can indeed run the gtk4-demo module in the msys2 environment.

But how do I now run my module from within WingIDE? I assume that it has something to do with setting up a custom environment in the Project Properties, but I don't think I did that on my old computer - I think I somehow managed to install PyGObject in the main Python installation? (If you do a Google search, you can see that a lot of people have struggled with this, and there have been different solutions over time.) I haven't really done anything with custom environments before, so please be specific (and gentle... :-) in your reply.

JeffH's avatar
31
JeffH
asked 2023-08-26 15:44:04 -0500
edit flag offensive 0 remove flag close merge delete

Comments

add a comment see more comments

1 Answer

0

The most common problem is using a different Python installation than the one you installed PyGTK into. If you can run things outside of Wing you can get the full path to the correct interpreter with 'import sys' followed by 'print(sys.executable)'. Then set Python Executable in Project Properties to Command Line and enter that full path there.

Another way in Wing Pro is to create a new project in Wing and create a new virtualenv at the same time and either specify the PyGTK package(s) in the New Project dialog or add them afterward with the Packages tool from the Tools menu.

Wingware Support's avatar
4k
Wingware Support
answered 2023-08-27 06:13:51 -0500
edit flag offensive 0 remove flag delete link

Comments

I have succeeded in installing an MSYS2 environment with all of the necessary modules required to run my Python module, and I can point the Python Executable in the Project Properties as you suggested, so that my module with GTK3 runs successfully. Thank you! When I put breakpoints in my code, however, the execution doesn't stop at those breakpoints. What additional step do I need to take to get debugging to work in this MSYS2 environment?

JeffH's avatar JeffH (2023-09-07 19:34:15 -0500) edit

This might be a hint... If I put an error in the code, like divide by zero, it throws an exception, and tells me which line in the module the error is on, but if I double-click on the error/line number, it does NOT take me to the offending line in the code. (In my previous set-up, it would.) So there seems to be some problem with the debug connection to my code.

JeffH's avatar JeffH (2023-09-07 19:44:50 -0500) edit

Looking a little closer, the reason it can't open the offending line in the code is that the path to the file is garbled, with the path sort of duplicated, as seen in this output from the Exceptions tab:

File "C:\Users\jeff_\Data\Technology\Programming\Python\mytest/c:\Users\jeff_\Data\Technology\Programming\Python\mytest\mytest.py", line 2969, in

builtins.ZeroDivisionError: division by zero

So where would it get that path? The code appears correctly in the editor, and if I right-click on the file tab and select Show in Explorer, it takes me to the right place. It seems to be only running/debugging that gets the weird double path.

JeffH's avatar JeffH (2023-09-07 19:55:47 -0500) edit

It's likely the Python was compiled into byte code in such a way that the __file__ for the module or the file names stored in the byte code are wrong. This is might be caused by having a partial path on the PYTHONPATH, either set from outside Wing and inherited in the environment, or set in the Environment in Project Properties. Replacing those with the full path should solve it. It might also be caused by code the precompiles Python code into byte code, for example during an install set, but that doesn't seem likely given the file name you give (clearly your own code).

What Python version do you have? We have code in the debugger to try to prevent this but I think there are some limitations, at least in some Python versions. The Python version also affects where the byte code files are stored (in Python 3 ... (more)

Wingware Support's avatar Wingware Support (2023-09-08 02:38:34 -0500) edit
add a comment see more comments

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account. This space is reserved only for answers. If you would like to engage in a discussion, please instead post a comment under the question or an answer that you would like to discuss.

Add Answer