I'm getting a "no $DISPLAY environment variable" with Python on macOS. That's MacPorts python 3.7, not the native python. I want to use MacPorts python with virtual environments so I can keep my projects clean. I also have to use MacPorts not Homebrew.
I've unsuccessfully tried setting the $DISPLAY value to :0.0 and the following link doesn't help because I'm not using matplotlib and I'm running on a machine with a display Issue with tkinter, python and seaborn: _tkinter.TclError: no display name and no $DISPLAY environment variable
I understand from here [https://www.python.org/download/mac/tcltk/#built-in-8-6-8] that using X11 is no longer the recommended path, rather using Aqua Cocoa Tk is.
The question: What's the trick to getting this environment variable set correctly?
My stack is:
macOS Mojave
Macports with the following relevant ports installed:
- py37-tkinter @3.7.4 python/py-tkinter
- py37-virtualenv @16.7.2 python/py-virtualenv
- python37 @3.7.4 lang/python37
- tcl @8.6.9 lang/tcl
- tk @8.6.9 x11/tk
- virtualenv_select @0.1 python/virtualenv_select
when I run
import tkinter as tk
tk._test()
I get
_tkinter.TclError: no display name and no $DISPLAY environment variable