Skip to content
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

Mac Big Sur Tkinter Black Screen #849

Closed
hefischer opened this issue Dec 28, 2020 · 29 comments · Fixed by #1526
Closed

Mac Big Sur Tkinter Black Screen #849

hefischer opened this issue Dec 28, 2020 · 29 comments · Fixed by #1526

Comments

@hefischer
Copy link

Current python (3.9.1) cx-Freeze (6.4.2) on samples/Tkinter (as well as other tkinter applications) causes a completely black Tk window on MacOS Big Sur (11.1). (Works fine when running from source.)

This is a blocker, any thoughts on a work around? (Compile 3.9 from scratch? Newer tkinter?)

(Also note that one must now "codesign --remove-signature lib/Python" inside the built App.)

@marcelotduarte
Copy link
Owner

What version of tkinter? Do you can put a relevant part of pip list?

@hefischer
Copy link
Author

hefischer commented Jan 4, 2021 via email

@marcelotduarte
Copy link
Owner

Please note: py39 is experimental for us
I see some installed py39 with tk 8.6.10
Can you check if comments in issue #684 can help you?

@hefischer
Copy link
Author

hefischer commented Jan 4, 2021 via email

@hefischer
Copy link
Author

I've tried the above with python 3.8.7 (instead of 3.9), downloaded from python.org, on Big Sur and the SampleTkApp.py behaves exactly the same, a completely black Tk window.

@hefischer
Copy link
Author

otool inspection of library references in the frozen dylibs leads me to wonder if the Big Sur library cache somehow is related to this issue?

@marcelotduarte
Copy link
Owner

Can you test the PR #887 (if you have a C compiler):
pip install -U git+https://github.com/marcelotduarte/cx_Freeze.git@refs/pull/887/head

@hefischer
Copy link
Author

Tested PR #887, although it didn't fix the tkinter black window issue it does fix needing these two setup lines (needed before due to capital T in Tkinter that got put into lib):
"packages": ["tkinter"],
"excludes": ["Tkinter"],

Probably unrelated but on the tkinter sample still has the codesign issue on lib/Python.

New issue, must manually chmod a+x the main program in .app/Contents/MacOS.

Blocker: still black background for tkinter.

@marcelotduarte
Copy link
Owner

@cainesi

@hefischer
Copy link
Author

hefischer commented Jan 22, 2021

Found a work around for python3.9 on mac Big Sur. Borrow tcl and tk 8.6.11 from python 3.10 0a3 as follows:

  1. install python3.10 0a3
  2. don't bother trying cx_freeze under this early 3.10, it, and many other libraries (like regex), don't work yet in this early 3.10 pre-release
  3. cd into /Library/Frameworks/Python.framework/Versions/3.9/lib
  4. mv tcl8.6 tcl8.6.distributed
  5. mv tk8.6 tk8.6.distributed
  6. cp -r /Library/Frameworks/Python.framework/Versions/3.10/lib/tcl8.6 .
  7. cp -r /Library/Frameworks/Python.framework/Versions/3.10/lib/tk8.6 .
  8. cd /Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/lib-dynload
  9. mv _tkinter.cpython-39-darwin.so _tkinter.cpython-39-darwin.so.distributed
  10. cp /Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/lib-dynload/_tkinter.cpython-310-darwin.so _tkinter.cpython-39-darwin.so

This seems to make tkinter operable again under cx_freeze (no more black window)

@cainesi
Copy link
Contributor

cainesi commented Jan 22, 2021

No insights from me. I have not used tkinter in years, though I know there is a bunch of special code for dealing with it scattered around cx_freeze.

@marcelotduarte
Copy link
Owner

@cainesi I mentioned you because he tested your PR #887, not because tkinter.

@cainesi
Copy link
Contributor

cainesi commented Jan 23, 2021

Understood. I'm just saying that I know that tkinter gets special handling elsewhere in the code, but I am not sure if I should be adding anything special into darwintools.py.

The fact the copying over the tcl/tk libraries from another version of python lets it work is a little strange!

Hefischer—if it is not too much trouble, would you mind up-loading the output of "otool -l" for the original and replaced libraries? Thanks.

@hefischer
Copy link
Author

@cainesi
Copy link
Contributor

cainesi commented Jan 23, 2021

Thanks. I remember that I looked into tkinter before, and was confused about how it could work on Darwin under cx_Freeze.

The issue is that tcl/tk have some directories of supporting tcl libraries that they appear to need to function. There is a hook in hooks.py ("load_tkinter()") to ensure that those files are copied, but the hook only functions on Windows (not on Darwin). My guess is that when the code was originally written, it was assumed that the user was using the built-in python, so did not need the tcl/tk support directories because they would also be on the user machine.

I suspect that the work around above does not really create a good frozen app. It would work locally because the tcl/tk files are already installed there, but (I guess) would not work on a machine where they were not present. Do you have a clean Big Sur install (without python separately installed) that you could test it on?

Not actually sure if this is the full explanation for the black windows (or if there are further issues), but I think it is something that needs to be addressed to get tkinter really working with cx_freeze.

@hefischer
Copy link
Author

hefischer commented Jan 23, 2021

I'm using a shell script running after cx_freeze to straighten out the tk/tcl libraries.

Testing on a VM under parallels for a "bare machine" Big Sur.

Now struggling with code signing, which seems to require most python (such as numpy and matplotlib) to be under Resources, not MacOS. For now using a post-cx_Freeze script to try to straighten this out. but not done yet.

@hefischer
Copy link
Author

I have another idea, maybe relates to Big Sur code signing requires otool-reported SDK > 10.9 but Python 3.9 has SDK 9.4.1. (Python 3.10a3 is SDK 11.1)

I can't codesign the cx_frozen app because of old SDK of python 3.9 .so's.

@hefischer
Copy link
Author

Agree, to cx_freeze for Mac after Big Sur and be both signed and notarized probably requires custom compiling Tcl/Tk, Python, major libraries (such as ssl) and pip-installables (those with .so or .dynlibs). All is difficult and will probably mean detailed instructions, or maybe we could have some kind of shell script (if anybody has loads of time).

For product I support with cx_freeze (arelle.org) I've given up on sign/notarize for now, which is uncomfortable to end users.

@cainesi
Copy link
Contributor

cainesi commented Jan 24, 2021

For what it is worth, my experience is that I use python installed via MacPorts and signing and notarization are working fine for me on Big Sur. There was one case where (if I am remembering correctly) I had a problem because MacPorts had installed a binary distribution of a package that had been built against an old SDK, but that was easy enough to fix by reinstalling the package form source.

So maybe we can just direct people who have an issue to try using one of the package management systems, instead of the installer from python.org?

Marcelo--thanks for the information about. Tkinter does seem to have its own special issues.

I wonder if the original issue is about the program finding a different tcl/tk installation when running on a clean machine? We could do something like on windows and copy tcl/tk into the application bundle as well--but I'm not sure how to figure out which copy of tcl/tk tkinter is using...

@vipinbp36
Copy link

vipinbp36 commented Apr 26, 2021

Found a work around for python3.9 on mac Big Sur. Borrow tcl and tk 8.6.11 from python 3.10 0a3 as follows:

  1. install python3.10 0a3
  2. don't bother trying cx_freeze under this early 3.10, it, and many other libraries (like regex), don't work yet in this early 3.10 pre-release
  3. cd into /Library/Frameworks/Python.framework/Versions/3.9/lib
  4. mv tcl8.6 tcl8.6.distributed
  5. mv tk8.6 tk8.6.distributed
  6. cp -r /Library/Frameworks/Python.framework/Versions/3.10/lib/tcl8.6 .
  7. cp -r /Library/Frameworks/Python.framework/Versions/3.10/lib/tk8.6 .
  8. cd /Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/lib-dynload
  9. mv _tkinter.cpython-39-darwin.so _tkinter.cpython-39-darwin.so.distributed
  10. cp /Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/lib-dynload/_tkinter.cpython-310-darwin.so _tkinter.cpython-39-darwin.so

This seems to make tkinter operable again under cx_freeze (no more black window)

This worked for me! Thank you very much!
I was using python 3.9, and when i created a binary using pyinstaller, the tkinter window was black. Though i could enter the data and click on buttons (by guess work). Surprisingly, i did no see the issue while executing the same script using pycharm.

@avi-arora
Copy link

facing the same issue, complete black screen, @hefischer workaround is complicated.

why its not fixed yet in the distribution itself ?

@hefischer can you suggest how to fix (for someone who are noob in python), will be very grateful.

Thanks

@marcelotduarte
Copy link
Owner

I believe that with python 3.10 this issue does not occur, since Tkinter was used from that version on python 3.9.

@avi-arora
Copy link

@marcelotduarte Thank you so much, yes it's working fine now,

and thanks again for the quick reply.

@network-shark
Copy link

network-shark commented Apr 27, 2022

@avi-arora Which 3.10 are you using . I am on 3.10 and it does not work , but I have to add that I am using an M1 12.3.1 not Big Sur

Solved , had to use tk 8.6

@chrisdel101
Copy link

chrisdel101 commented Jun 11, 2022

@network-shark How did U switch to tk 8.6? I don't know how to switch tk.

I've tried many py version including 3.10.4 and I get a black screen for every one. This has nothing to do with cx_freeze btw.

@network-shark
Copy link

@chrisdel101 I am using pyenv and I think I have used this tutorial. https://xogk39.medium.com/install-tkinter-on-mac-pyenv-f112bd3f4663

@marcelotduarte
Copy link
Owner

I made a PR to solve issues with Tkinter (read the comment).
Can you test?
To install the latest development build:

pip install --pre --extra-index-url https://marcelotduarte.github.io/packages/ cx_Freeze

@marcelotduarte
Copy link
Owner

cx_Freeze 6.12.0 has just been released.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants