First time here? Check out the FAQ!
1

Get exact execution string?

Is there a way to get the exact execution string/environment that Wing uses when launching a script? I have a Python/PySide2/matplotlib application set up in a venv that looks correct when I run it from within wing, but if I run it directly from the command line, the font sizes in my plots are all huge. Apparently Wing is doing something right to make it work, but I don't know what.

ibrewster's avatar
31
ibrewster
asked 2020-01-17 12:37:08 -0600
Wingware Support's avatar
4.2k
Wingware Support
updated 2020-01-17 15:09:28 -0600
edit flag offensive 0 remove flag close merge delete

Comments

add a comment see more comments

1 Answer

0

I suspect the difference is in the environment and you probably want to examine the contents of os.environ either by using the Debug Console or adding prints to your code. There isn't a way to show the command line used by Wing but examining sys.executable and sys.argv should allow you to reconstruct it.

Wingware Support's avatar
4.2k
Wingware Support
answered 2020-01-17 13:16:50 -0600
edit flag offensive 0 remove flag delete link

Comments

Thanks. os.environ seems to be the same other than some additional wing-specific entries on the wing side (such as WINGDB_SPAWNCOOKIE and WINGDB_WINGHOME). sys.executable is exactly as expected when run directly - the python I called it with. On the wing side, it is '/Applications/WingPro.app/Contents/Resources/wingdb’, which doesn’t help much.

A bit more digging shows me that the crucial difference is that, when run through WingIDE, Matplotlib selects the MacOSX backend, while when run directly it selects the Qt5Agg backend. Still doesn't tell me what wing is doing right and I am doing wrong, but at least it's a pointer in the right direction.

ibrewster's avatar ibrewster (2020-01-17 13:44:08 -0600) edit

Is sys.executable the same in both cases? Wing may be running a different Python installation. I'm not sure how matplotlib decides on the default and in fact was under the impression it would always be MacOSX on macOS, but apparently not. You can explicitly set it with matplotlib.use('MacOSX') after importing matplotlib and before doing anything else.

Wingware Support's avatar Wingware Support (2020-01-17 14:01:27 -0600) edit

As I stated, no, sys.executable is NOT the same. To quote: "sys.executable is exactly as expected when run directly - the python I called it with. On the wing side, it is '/Applications/WingPro.app/Contents/Resources/wingdb’"

So far Matplotlib.use('MacOSX') is not working, I'm currently debugging that. Thankfully Wing makes that easy by being able to simply import wingdbstub when I run the program externally, so thanks for that!

ibrewster's avatar ibrewster (2020-01-17 14:05:30 -0600) edit

Oh, sorry, I missed that part somehow. In this case, wingdb will start the Python named in the environment variable WINGDB_PYTHON. The reason sys.executable is set to that is so Wing can debug child processes. You can turn that off with the Debugger > Processes > Replace sys.executable preference although I would do that only for testing and not leave it off because it can break some things (on Windows it entirely breaks child process debugging; on macOS and Linux it's not a critical).

Wingware Support's avatar Wingware Support (2020-01-17 14:10:08 -0600) edit

Just as a further follow-up, apparently it IS getting set properly when I call Matplotlib.use(), but then it gets changed when I call import Matplotlib.pyplot

ibrewster's avatar ibrewster (2020-01-17 14:20:44 -0600) edit

Try goto-definition on matplotlib.use and then set a breakpoint inside use() to see how/when/why pyplot is calling that. It seems odd that it would do that.

Wingware Support's avatar Wingware Support (2020-01-17 14:24:14 -0600) edit
1

pyplot wasn't calling use, at least not according to the debugger (the only time it came up was when I called it) however a) turning off the "Replace sys.executable" preference in wing caused wing to show the same behavior as running directly, so it is something about the executable that is "fixing" the problem, and b) by importing Matplotlib.pyplot immediately after the call to matplotlib.use(), rather than later on where I was doing it seems to "lock in" the MacOSX backend. In fact, by importing it there it automatically selects the correct backend in the first place, thereby eliminating the issue entirely. So apparently there is something in my imports that breaks it if I don't import pyplot soon enough. Oh well. I'll import it earlier and call it good. Thanks for the advice!

ibrewster's avatar ibrewster (2020-01-17 14:34:30 -0600) 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