You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When using Python's tkinter directly or indirectly a local installation of tcl and tk is necessary.
And while JavaCPP's cPypthon includes the tkinter module it doesn't contain tcl/tk.
Therefore I would like to suggest to include tcl/tk into JavaCPP's cpython-preset for Windows.
Without that the following Python program cannot be executed using javacpp-embedded-python:
org.bytedeco.embeddedpython.PythonException: Failed to execute:
import matplotlib.pyplot as plt
import numpy as np
x = np.linspace(0, 2 * np.pi, 200)
y = np.sin(x)
fig, ax = plt.subplots()
ax.plot(x, y)
fig.savefig('plot.png')
Traceback (most recent call last):
File "<string>", line 6, in <module>
File "~\.javacpp\cache\cpython-3.12.1-1.5.10-windows-x86_64.jar\org\bytedeco\cpython\windows-x86_64\lib\site-packages\matplotlib\pyplot.py",
line 1759, in subplots
fig = figure(**fig_kw)
^^^^^^^^^^^^^^^^
File "~\.javacpp\cache\cpython-3.12.1-1.5.10-windows-x86_64.jar\org\bytedeco\cpython\windows-x86_64\lib\site-packages\matplotlib\pyplot.py",
line 1027, in figure
manager = new_figure_manager(
^^^^^^^^^^^^^^^^^^^
File "~\.javacpp\cache\cpython-3.12.1-1.5.10-windows-x86_64.jar\org\bytedeco\cpython\windows-x86_64\lib\site-packages\matplotlib\pyplot.py",
line 550, in new_figure_manager
return _get_backend_mod().new_figure_manager(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "~\.javacpp\cache\cpython-3.12.1-1.5.10-windows-x86_64.jar\org\bytedeco\cpython\windows-x86_64\lib\site-packages\matplotlib\backend_bases.py",
line 3507, in new_figure_manager
return cls.new_figure_manager_given_figure(num, fig)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "~\.javacpp\cache\cpython-3.12.1-1.5.10-windows-x86_64.jar\org\bytedeco\cpython\windows-x86_64\lib\site-packages\matplotlib\backend_bases.py",
line 3512, in new_figure_manager_given_figure
return cls.FigureCanvas.new_manager(figure, num)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "~\.javacpp\cache\cpython-3.12.1-1.5.10-windows-x86_64.jar\org\bytedeco\cpython\windows-x86_64\lib\site-packages\matplotlib\backend_bases.py",
line 1797, in new_manager
return cls.manager_class.create_with_canvas(cls, figure, num)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "~\.javacpp\cache\cpython-3.12.1-1.5.10-windows-x86_64.jar\org\bytedeco\cpython\windows-x86_64\lib\site-packages\matplotlib\backends\_backend_tk.py",
line 483, in create_with_canvas
window = tk.Tk(className="matplotlib")
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "~\.javacpp\cache\cpython-3.12.1-1.5.10-windows-x86_64.jar\org\bytedeco\cpython\windows-x86_64\lib\tkinter\__init__.py",
line 2340, in __init__
self.tk = _tkinter.create(screenName, baseName, className,
interactive, wantobjects, useTk, sync, use)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
_tkinter.TclError: Can't find a usable init.tcl in the following
directories:
~/.javacpp/cache/cpython-3.12.1-1.5.10-windows-x86_64.jar/org/bytedeco/cpython/windows-x86_64/lib/tcl8.6
This probably means that Tcl wasn't installed properly.
A workaround is to wrap the tcl folder of a 'classic' Cpython installation and distribute and cache it along with javacpp-cpython and run the following as first steps after the initialization of python (e.g. via Py_Initialize()):
When using Python's tkinter directly or indirectly a local installation of
tcl
andtk
is necessary.And while JavaCPP's cPypthon includes the
tkinter
module it doesn't contain tcl/tk.Installing tcl/tk via
PIP
or alike is not possible. On Windows the CPython can install tcl/tk as part of the python installation and on Linux it can be installed via apt-get and is often already available:https://stackoverflow.com/questions/69603788/how-to-pip-install-tkinter
Therefore I would like to suggest to include tcl/tk into JavaCPP's cpython-preset for Windows.
Without that the following Python program cannot be executed using javacpp-embedded-python:
A workaround is to wrap the tcl folder of a 'classic' Cpython installation and distribute and cache it along with javacpp-cpython and run the following as first steps after the initialization of python (e.g. via
Py_Initialize()
):That's possible, but cumbersome and not easy to get to if one is not deeply familiar with the topic.
Unfortunately I cannot tell yet how including tcl/tk could be achieved, since I haven't fully understood yet how the CPython installer bundle tcl/tk.
The text was updated successfully, but these errors were encountered: