英文:
Can't find a usable init.tcl in the following directories This probably means that Tcl wasn't installed properly
问题
我在运行Python代码时遇到了这个错误:
PS C:\Codes> 'C:\Python311\python.exe' 'c:\Users\Administrator\.vscode\extensions\ms-python.python-2023.14.0\pythonFiles\lib\python\debugpy\adapter/../../debugpy/launcher' '50412' '--' 'C:\Codes\Python Scripts\py snake.py'
Could not find platform independent libraries <prefix>
Could not find platform independent libraries <prefix>
Traceback (most recent call last):
File "C:\Users\Administrator\AppData\Local\Programs\Python\Python311\Lib\runpy.py", line 198, in _run_module_as_main
return _run_code(code, main_globals, None,
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\Administrator\AppData\Local\Programs\Python\Python311\Lib\runpy.py", line 88, in _run_code
exec(code, run_globals)
File "c:\Users\Administrator\.vscode\extensions\ms-python.python-2023.14.0\pythonFiles\lib\python\debugpy\adapter/../../debugpy/launcher/../../debugpy/__main__.py", line 39, in <module>
cli.main()
File "c:\Users\Administrator\.vscode\extensions\ms-python.python-2023.14.0\pythonFiles\lib\python\debugpy\adapter/../../debugpy/launcher/../../debugpy/../../debugpy/server/cli.py", line 430, in main
run()
File "c:\Users\Administrator\.vscode\extensions\ms-python.python-2023.14.0\pythonFiles\lib\python\debugpy\adapter/../../debugpy/launcher/../../debugpy/../../debugpy/server/cli.py", line 284, in run_file
runpy.run_path(target, run_name="__main__")
File "c:\Users\Administrator\.vscode\extensions\ms-python.python-2023.14.0\pythonFiles\lib\python\debugpy\_vendored\pydevd\_pydevd_bundle\pydevd_runpy.py", line 321, in run_path
return _run_module_code(code, init_globals, run_name,
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "c:\Users\Administrator\.vscode\extensions\ms-python.python-2023.14.0\pythonFiles\lib\python\debugpy\_vendored\pydevd\_pydevd_bundle\pydevd_runpy.py", line 135, in _run_module_code
_run_code(code, mod_globals, init_globals,
File "c:\Users\Administrator\.vscode\extensions\ms-python.python-2023.14.0\pythonFiles\lib\python\debugpy\_vendored\pydevd\_pydevd_bundle\pydevd_runpy.py", line 124, in _run_code
exec(code, run_globals)
File "C:\Codes\Python Scripts\py snake.py", line 131, in <module>
window = Tk()
^^^^
File "C:\Users\Administrator\AppData\Local\Programs\Python\Python311\Lib\tkinter\__init__.py", line 2326, 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:
C:/Users/Administrator/AppData/Local/Programs/Python/Python311/lib/tcl8.6 C:/lib/tcl8.6 C:/lib/tcl8.6 C:/library C:/library C:/tcl8.6.12/library C:/tcl8.6.12/library
这可能意味着Tcl没有正确安装。
我检查了我的文件管理器,发现在C:\Users\Administrator\AppData\Local\Programs\Python\Python311\tcl\tix8.4.3
中有一个tcl.init
文件。
我还重新安装了tcl,以为可能是版本的问题(tcl.8.6.11),它在我的下载文件夹中。我需要将它移动到另一个文件夹吗?正确的文件夹是哪个?
我希望能够运行和调试我的Python代码。
编辑:JS代码也有同样的问题。可能与与Tcl相关的所有编程语言有关?
英文:
I got this error whilst trying to run my Python code:
PS C:\Codes> & 'C:\Python311\python.exe' 'c:\Users\Administrator\.vscode\extensions\ms-python.python-2023.14.0\pythonFiles\lib\python\debugpy\adapter/../..\debugpy\launcher' '50412' '--' 'C:\Codes\Python Scripts\py snake.py'
Could not find platform independent libraries <prefix>
Could not find platform independent libraries <prefix>
Traceback (most recent call last):
File "C:\Users\Administrator\AppData\Local\Programs\Python\Python311\Lib\runpy.py", line 198, in _run_module_as_main
return _run_code(code, main_globals, None,
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\Administrator\AppData\Local\Programs\Python\Python311\Lib\runpy.py", line 88, in _run_code
exec(code, run_globals)
File "c:\Users\Administrator\.vscode\extensions\ms-python.python-2023.14.0\pythonFiles\lib\python\debugpy\adapter/../..\debugpy\launcher/../..\debugpy\__main__.py", line 39, in <module>
cli.main()
File "c:\Users\Administrator\.vscode\extensions\ms-python.python-2023.14.0\pythonFiles\lib\python\debugpy\adapter/../..\debugpy\launcher/../..\debugpy/..\debugpy\server\cli.py", line 430, in main
run()
File "c:\Users\Administrator\.vscode\extensions\ms-python.python-2023.14.0\pythonFiles\lib\python\debugpy\adapter/../..\debugpy\launcher/../..\debugpy/..\debugpy\server\cli.py", line 284, in run_file
runpy.run_path(target, run_name="__main__")
File "c:\Users\Administrator\.vscode\extensions\ms-python.python-2023.14.0\pythonFiles\lib\python\debugpy\_vendored\pydevd\_pydevd_bundle\pydevd_runpy.py", line 321, in run_path
return _run_module_code(code, init_globals, run_name,
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "c:\Users\Administrator\.vscode\extensions\ms-python.python-2023.14.0\pythonFiles\lib\python\debugpy\_vendored\pydevd\_pydevd_bundle\pydevd_runpy.py", line 135, in _run_module_code
_run_code(code, mod_globals, init_globals,
File "c:\Users\Administrator\.vscode\extensions\ms-python.python-2023.14.0\pythonFiles\lib\python\debugpy\_vendored\pydevd\_pydevd_bundle\pydevd_runpy.py", line 124, in _run_code
exec(code, run_globals)
File "C:\Codes\Python Scripts\py snake.py", line 131, in <module>
window = Tk()
^^^^
File "C:\Users\Administrator\AppData\Local\Programs\Python\Python311\Lib\tkinter\__init__.py", line 2326, 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:
C:/Users/Administrator/AppData/Local/Programs/Python/Python311/lib/tcl8.6 C:/lib/tcl8.6 C:/lib/tcl8.6 C:/library C:/library C:/tcl8.6.12/library C:/tcl8.6.12/library
This probably means that Tcl wasn't installed properly.
I checked my file manager, and I'm seeing tcl.init
in C:\Users\Administrator\AppData\Local\Programs\Python\Python311\tcl\tix8.4.3
I also installed tcl again thinking that it might be a problem with the version (tcl.8.6.11) and it's in my downloads folder. Do I need to move it to another folder? What is the right folder?
I'm expecting to be able to run and debug my Python codes.
EDIT: JS code has the same issue too. Probably all of the programming languages related to Tcl?
答案1
得分: 2
Tkinter需要拥有(或找到)一个完整的Tcl+Tk安装,而不仅仅是C库部分;其中有一些关键的部分是用脚本实现的。当脚本部分缺失时,就会出现如所示的错误。如果你使用的是没有用Python编写的部分,也会出现严重的错误!Tcl(和Tk)在8.6版本之前对此非常严格(除非你执行一些打包步骤,这些步骤从未成为Python处理此集成的一部分)。
请注意,缺失的init.tcl
只是一个警告信号(也是第一个被搜索到的);其他必要的脚本部分可能也缺失。
此时的选项取决于你是否已经安装了Tkinter但无法找到它,或者根本没有安装。无论哪种情况,你都需要让代码使用你已经安装的Tkinter,或者提供一个可用的安装。让代码使用已安装的Tkinter可以通过设置TCL_LIBRARY
和TK_LIBRARY
环境变量来实现,但要注意匹配必须精确;通常不建议使用这些环境变量(除了内部测试之外),因为版本绑定问题,安装通常已经准确知道脚本应该在哪里(错误消息告诉你它搜索的位置,对于你的情况是C:/Users/Administrator/AppData/Local/Programs/Python/Python311/lib/tcl8.6
)。提供一个安装就是字面意思;我不知道如何配置你的Python安装以使用你在其他位置进行的Tcl和Tk安装的详细信息。
来自Tix的init.tcl
可能不是正确的文件。那是Tcl/Tk的一个包的一部分,而不是Tcl的主要初始化代码。(该包提供了一些额外的小部件组件,主要用于旧代码。)
英文:
Tkinter needs to have (or find) a full Tcl+Tk installation somewhere, not just the C library part; there are critical pieces implemented in scripts. When the script pieces aren't there, things break exactly as shown. If you were using a Python build without the bits written in Python, it would also break nastily! Tcl (and Tk) up through 8.6 versions is quite particular about this (unless you do some packaging steps that have never been part of how Python handles this integration).
Note that the missing init.tcl
is just a canary in the coal-mine (and the first one searched for); the other essential scripted parts are probably also missing.
The options at this point depend on whether you've got an installation and just aren't finding it, or simply haven't got an installation at all. Either way, you end up having to either persuade the code to use the installation you've got or to provide an installation it can use. Persuading the code to use the installation is something you'd do by setting the TCL_LIBRARY
and TK_LIBRARY
environment variables, but be aware that the matching must be exact; those environment variables are usually not recommended (outside of internal testing) because of the version binding problems, as an installation typically knows exactly where its scripts should be anyway (the error message tells you exactly where it looked; C:/Users/Administrator/AppData/Local/Programs/Python/Python311/lib/tcl8.6
in your case). Providing an installation is exactly what it says; I don't know the details of how to configure your Python installation to use a Tcl and Tk installation you've done in an alternate location.
The init.tcl
from Tix is probably not the right one. That's (part of) a package for Tcl/Tk, not the main initialisation code for Tcl. (The package provides some extra widget components that are mainly used by old code.)
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论