Make Anaconda's Tkinter Aware Of System Fonts Or Install New Fonts For Anaconda
Solution 1:
{tT}kinter
works linking to a Tk/Tcl interpreter that, loosely speaking, is contained in a couple of DLL, in particular the graphical library is libtk6.0.so
.
Most of the extra fonts not seen by tkinter
are managed by the Freetype library and Anaconda's libtk6.0.so
is not built against Freetype...
$ ldd /usr/lib/x86_64-linux-gnu/libtk8.6.so | grep freetype
libfreetype.so.6 => /usr/lib/x86_64-linux-gnu/libfreetype.so.6 (0x00007f0a24597000)
$ ldd miniconda3/lib/libtk8.6.so | grep freetype$
I've tried the following, horrible thing
$ mv lib/miniconda3/lib/libtk8.6.so lib/miniconda3/lib/libtk8.6.sav
$ ln -s /usr/lib/x86_64-linux-gnu/libtk8.6.so lib/miniconda3/lib/libtk8.6.so
$ ipython
Python 3.6.3 |Anaconda, Inc.| (default, Nov 20 2017, 20:41:42)
Type 'copyright', 'credits' or 'license'for more information
IPython 6.2.1 -- An enhanced Interactive Python. Type '?'forhelp.
In [1]: from tkinter import Tk, Label ; from tkinter.font import families
In [2]: r = Tk() ; a = families() ; len(a)
Out[2]: 328
In [3]: r=Tk() ; Label(r, text="Constantia", font=("Constantia", 60)).pack()
In [4]: r.mainloop()
Final thoughts.
- Substituting the DLL is not a clean solution.
- The fonts are not exactly the same. For sure Anaconda has its own Fontconfig subsystem and possibly the directories that are scanned are different, but I have not a correct understanding of the discrepancy in the number of fonts.
- The correct course of action is to persuade Anaconda, Inc. to build
libtk
against Freetype, but I don't know how to report to them, e.g., if I go to https://www.anaconda.com/search/issues what I see is a list of informational articles on the distribution.
Update
W.r.to point 3, I contacted via a github issue Anaconda Inc. and I was told
No we cannot do this. When building our software we need python built very early, well before anything graphical gets built. Adding Freetype as a dep for tkinter causes a cycle in the build graph and we can no longer build the distro.
Why not use something more modern than tkinter anyway?
--- Ray Donnelly (aka mingwandroid)
Solution 2:
I'm working around this by launching gitk in a conda-free environment. I'm newish to conda though so I don't know if there are subtle/hidden problems with doing this.
# Fix gitk fonts in conda environments# The Tcl/Tk environment in conda has font linking issues, so hard-to-read fonts get chosen# Start a subshell ( ), any changes within will die with the subshell# Detect if conda is active, if so deactivate until it isn't# Run gitk in a conda-free environmentalias gitk='( [ -n "${CONDA_SHLVL}" ] && while [ $CONDA_SHLVL -gt 0 ]; do conda deactivate; done; gitk --all & )'
Solution 3:
EDIT: As @gboffi pointed out, this solution only seems like it works, as sudo python
doesn't use Anaconda's install, but rather the system default. Using the full Anaconda Python path with sudo
still yields the limited font options. I'm going to keep exploring this, but this answer as it stands is clearly incorrect.
I was having almost the exact same problem, and the "fix" for me was to run Anaconda's Python with sudo
. Doing so apparently gives it access to the rest of the fonts that, for whatever reason, it doesn't natively have. (Found this info in a sparsely populated Google Groups discussion.)
For reference, my system is running Ubuntu 16.04, and Anaconda 4.4.8 with Python 3.6.4.
python my_script.py
yields:
while sudo python my_script.py
yields:
Oddly they don't overlap, but I'm frustrated enough with Anaconda at this point that I'm done investigating for now. Hope this (maybe) helps! It's a bad solution that's good enough for testing.
Post a Comment for "Make Anaconda's Tkinter Aware Of System Fonts Or Install New Fonts For Anaconda"