-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
WIP: Delay setting the matplotlib backend until the user asks to launch the GUI #1730
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
2ea36bb to
30f28c6
Compare
|
I like your solution @hmaarrfk! |
|
Thank you. I'm not sure if you have other entry points you want to add a similar thing to. This seems to work for me for launching the main GUI. Let me know if there is somewhere i should add a release note. |
|
This is a very lean solution, nice @hmaarrfk ! While Because in my case I get |
|
Do you have anything in your python rc or ipython rc file |
|
I think you also mean to say; since |
30f28c6 to
93fc79b
Compare
|
can you confirm that you are running things from the terminal and not something like the |
|
I am running from |
|
Hmm, you are right. Thank you for specifying ipython. ipython has many strangeness. My understanding was that was not the suggested way to start up deeplabcut. In fact, in ipython, if I run all on one line (as my first line), it seems to work. There might be something else setting the matplotlib backend that I am unaware of. My guess is somewhere in the ipython stack. Detects if matplotlib has been "imported" and sets the backend to |
this works indeed! I agree that ipython has many peculiarities. Thank you for looking into it! :) |
|
@intergalactic-mammoth I feel like there is something else that is actually going on with matplotlib that is causing the selection of strange backend. I've seen that with some functions, unrelated display, the backend would get selected. For me, it happened to try to select the qtpy + PyQt5 backend, when I didn't have PyQt5 installed (I had PySide2 installed). |
Yes it is peculiar, I also tried to look into it, but didn't reach to a proper understanding of what is happening. Thank coming back to give extra info :) let;s see if we will decode ipython's mysteries... |
|
Ok.... so I finally understand what is going. TLDR, anybody running the code: before deeplabcut will effectively stop setting WxAgg as the backend. Minimum reproducible code: So there are 2 things:
I mean ultimately, you could work hard to get rid of this code in DeepLabCut. But..... will you get rid of it everywhere where people use deeplabcut? I'm ok with this patch as is. If a DeepLabCut developer wants to merge it, I can unmark it as draft (or maybe they can?) and merge. Link to matplotlib reference where this is explained: |
|
And for reference, I think this will be fixed in the next release of matplotlib: |
|
@hmaarrfk great detective work really, thank you so much! 💪🙏🏻 |
|
Reading this I think the explanation of what is going on here is:
So if you run everything as one line, then you set the qt inputhook, set the wx inputhook, then let the wx inputhook run and everything works. If you do this in multiple lines after the first one the qt inputhook fires, the QAppliaction gets created, and Matplotlib refuses to switch backends. On the Matplotlib side we have made the automatic backend selection even lazier (not doing it until the user creates a figure). On the IPython side, I think there is a strong case to have them fast-exit if no QApplication exists. In the past I advocated for the current situation, but on consideration I think I was wrong IPython should never make a QApplication. [could someone take the lead on pushing for that change 🙏🏻 I do not have the bandwidth at the moment]. 🐑 Sorry about this, I am at least partially responsible for all of the parts that are interacting badly here. |
|
@tacaswell thank you so much for spending the time troubleshooting, and all the previous time making it possible to lazily select the backend. I'm not too sure I understand the issue to formulate it now to ipython. For one, I don't have a minimum code that reproduces the issue (I got it down to 3 matplotlib lines!) I will keep this in mind as I move forward. I think building software systems is really difficult especially when you have to make optimizations based on your time and your own goals (or the projects goals). |
This is my attempt at addressing users' ability to import their DeepLabCut environment in both a Jupyter noteook and using the provided GUI (which is really useful!)
I still need to test it on a variety of configurations, but this makes
wxa truely optional dependency, and doesn't affect the behavior of matplotlib until the user calls the GUI launching script.Closes #1548