Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Fixing Python 3 tkinter issues on Mac with a virtualenv

I think the short version of this question is: How do I get a virtualenv running Python 3.5 to point to the correct version of ActiveTcl on a Mac?


Here's the longer version:

I'm trying to run this Korg Electribe sample editor project on a Mac. The author has only tested it on Windows, and based on the screenshots, it appears to work. I've been able to run the basic python script fine, but as I mention in an issue that I've opened, the full window turns black after loading a file.

After doing some research, I've found that there is a known issue with Aqua Cocoa Tk, and python.org has provided some instrunctions about how to fix tkinter for Mac OS 10.9 and up. I've attempted installing both of the suggested ActiveTcl (8.5.18.0) as well as the newer 8.6.x.x version without success.

I'm pretty sure this is a different issue than Tkinter not working mac osx el capitan, since the script does run, and the window is drawn properly on launch. It's only after I've attempted to load a .all file (there's a sample file in the Github issue) that the screen goes black.

After some more research, I've found this question that seems related, but is specific to Windows: TKinter in a Virtualenv

I'm under the impression that if I can figure out what to set TCL_LIBRARY to, that I'll be able to make some head-way, but I can't seem to find that information for the packages listed on python.org.

Somewhat related, it would also seem to be helpful if I could figure out which version of Tcl/Tk that tkinter is pointing to from within Python, so if anyone could help with that as well, I'd greatly appreciate it.

Thanks!

like image 910
Kevin Avatar asked May 04 '16 18:05

Kevin


People also ask

Does Virtualenv work with Python 3?

Virtualenv is only installed on DreamHost servers for Python 2. If you're working with Python 3, you must install virtualenv using pip3. pip3 is not installed on the server by default. You must first install a custom version of Python 3.

Does Python Tkinter work on Mac?

Install Tkinter on macOSTo install Python and Tkinter on macOS I recommend you use Homebrew. Homebrew is a package manager for command-line software on macOS. Homebrew has both Python 3 and Tkinter available in their repositories. This is also available to copy and paste from the Homebrew homepage.


1 Answers

I succeeded in using tkinter in a python3 virtualenv on OSX 10.13 by :

  • installing the official OSX Python 3 from https://www.python.org/
  • installing activeTcl from https://www.activestate.com/activetcl
  • creating a new virtualenv

    mkvirtualenv myenv --python=python3
    
  • locating the tkinter location in the Python3 directory. For me it was here :

    /usr/local/Cellar/python3/3.6.3/Frameworks/Python.framework/Versions/3.6/lib/python3.6/tkinter
    
  • creating a symbolic link in the virtualenv library pointing to the tkinter location

    cd ~/.virtualenvs/myenv/lib/python3.6
    ln -s /usr/local/Cellar/python3/3.6.3/Frameworks/Python.framework/Versions/3.6/lib/python3.6/tkinter tkinter
    
like image 151
olitocin Avatar answered Nov 15 '22 01:11

olitocin