使用Python Tkinter导致“TclError:无法在以下目录中找到可用的init.tcl时,从matlab调用Python函数”

20次观看(过去30天)
汤姆斯隆
汤姆斯隆 于2020年5月14日
回答: 2021年4月21日
我正在尝试用来自Matlab的Tkinter致电脚本中的Python函数。
我能够使用Matlab引擎从Python向Matlab发送数据,当Python文件不使用TKinter GUI时,我可以调用Matlab中的Python函数。当我尝试在具有GUI的文件中调用函数时,我只遇到问题。
错误输出我收到:
错误使用__init__(第2023行)
Python错误:TclError:找不到可用的初始化。TCL在以下目录:
C:/Users/TS4804/AppData/local/programs/python/python37/lib/tcl8.6 {c:/ program files / matlab / r2020a / bin / lib / tcl8.6} {c:/ program files / matlab /R2020A / lib / tcl8.6} {c:/ program文件/ matlab / r2020a / bin / library} {c:/ program files / matlab / r2020a / library} {c:/ program files / matlab / r2020a / tcl8.6.9/ library} {c:/ program files / matlab / tcl8.6.9 / library}
这个可能意味着tcl没有正确安装。
错误在test_gui> (第22行)
错误 _call_with_frames_removed(第219行)
错误exec_module(第728行)中
错误 _load_unlocked(第677行)
错误_find_and_load_unlocked(第967行)中
错误 _find_and_load(第983行)
错误 _gcd_import(行1006行)
错误在__init __> import_module(第127行)
异常在Tkinter回调
回溯(最后最新呼叫):
文件“C: \用户\ TS4804 \ AppData \本地Python \程序\ \ Python37 \ lib \ tkinter \ __init__ . py”, 线1705.,在__称呼__
返回self.func (* args)
文件“test_gui.py”, 线62.,在send_to_matlab
print(eng.pythonInterface(1,list_to_send)))
文件“C:\ Users \ TS4804 \ AppData \ Local \ Programs \ Python \ Python37 \ lib \ site-packages \ matlab \ Engine \ Matlabengine.py”, 线71.,在__称呼__
_stderr,函数宏指令= True) .result ()
文件“C:\ Users \ TS4804 \ AppData \ Local \ Programs \ Python \ Python37 \ lib \ site-packages \ matlab \ Engine \ futureresult.py”, 线67.,在结果
返回自己。__未来。结果(超时)
文件“C: \用户\ TS4804 \ AppData \本地Python \ Python37 \ lib \程序\ \网站\ matlab引擎\ \ fevalfuture.py”, 线82.,在结果
自己。_结果= PythonEngine.getFevalResult(自我。_未来,自我。_nargout,, =自我。_出来,错误=自我。_呃)
matlab.engine.matlabexecutionerror:python错误:tclerror:找不到以下目录中的可用init.tcl:
C:/Users/TS4804/AppData/local/programs/python/python37/lib/tcl8.6 {c:/ program files / matlab / r2020a / bin / lib / tcl8.6} {c:/ program files / matlab /R2020A / lib / tcl8.6} {c:/ program文件/ matlab / r2020a / bin / library} {c:/ program files / matlab / r2020a / library} {c:/ program files / matlab / r2020a / tcl8.6.9/ library} {c:/ program files / matlab / tcl8.6.9 / library}
这个可能意味着tcl没有正确安装。
据我所知,因为GUI在没有MATLAB的情况下正常运行,所以正确下载了TCL。它还内置在最近的python安装中。我也试图通过下载tcl文件来修复它 激活 并将文件路径添加到matlab中。
我用:
Matlab R2020A,Python 3.7.7
任何帮助将不胜感激

更多答案(1)

崔
2021年4月21日
你好。
这是一个例子
= = = = = =
pyexec ='c:\ users \ djchoi \ appdata \ local \ programs \ python \ python37 \ pythonw.exe';
pyversion(pyexec);
pystr = pyenv;
pytcl = fullfile(pystr.home,'tcl','tcl8.6');
pyTK = fullfile (pyStr。家,tcl,“tk8.6”);
setenv('tcl_library',pytcl);
setenv('tk_library',pytk);
win = py.tkinter.tk();
win.title('我的gui');
win.mainloop ();
明确的胜利

标签

社区宝藏狩猎

找到Matlab Central中的宝藏,并发现社区如何帮助您!

开始狩猎!