PyInstaller 在 Windows 7 上失败:"Can't find a usable init.tcl"
PyInstaller fails on Windows 7: "Can't find a usable init.tcl"
我有一个使用 Tkinter 的基本 Python 脚本。
from Tkinter import Tk
from tkFileDialog import askdirectory
Tk().withdraw()
print askdirectory()
用 PyInstaller 编译我的脚本后,我尝试 运行 我的程序在 Windows 7(64 位)计算机上 Python 安装。
它引发了这个错误:
Can't find a usable init.tcl in the following directories: [list of directories]
This probably means that Tcl wasn't installed properly
为什么我的脚本在使用 PyInstaller 编译后找不到 init.tcl
?
这是 Windows 7 64 位机器上 PyInstaller 和 Tkinter 的已知问题。 PyInstaller 的 GitHub 存储库中有一个 issue report。
一直在底部这个问题是从另一个问题中引用的,即 this one 说降级到 PyInstaller 3.1.0 可以帮助其他人解决问题。
pip install pyinstaller==3.1.0
我自己已经能够使用虚拟机确认这一点。
, PyInstaller has a known issue 在 Windows 7 和 Windows XP 上使用 Tkinter 应用程序。
由于这个问题已经两年没有解决,所以我继续 started a bounty on Bountysource。在问题得到解决之前,您可以尝试一些解决方法:
解决方法 1 - 手动复制丢失的文件
如 a related issue 中所述,您可以从本地 Python 安装中手动复制丢失的文件。
- 找到您本地的 Python 安装。 (
%LocalAppData%\Programs\Python
)
- 复制丢失的文件夹(
...\Python36-32\tcl\<missing_folder>
)
- 将副本移动到应用程序的
tcl
文件夹 (...\dist\<app_name>\tcl\<missing_folder>
)
解决方法 2 - 运行 和 --onefile
运行在 --onefile
模式下使用 PyInstaller 似乎可以避免这个问题。
但是,请注意 运行 在单文件模式下会增加启动时间。
解决方法 3 - 降级到 PyInstaller 3.1.0
pip install pyinstaller==3.1.0
According to ugoertz,降级到 PyInstaller 3.1.0 解决了这个问题。
Downgrading to 3.1.0 (and also downgrading setuptools to 19.2 because of the problem described in #1941) fixed the issue for me.
在您的情况下,您会发现 python 目录中有 Tcl8.X 文件夹,它位于您在问题中提到的 [目录列表] 中未提及的位置。只需从这些目录列表中选择任何路径(最好是 /lib )。
这将允许 python 找到 Tcl 库文件并且它会起作用。
注意:不要移动文件,只需复制它们。
我有一个使用 Tkinter 的基本 Python 脚本。
from Tkinter import Tk
from tkFileDialog import askdirectory
Tk().withdraw()
print askdirectory()
用 PyInstaller 编译我的脚本后,我尝试 运行 我的程序在 Windows 7(64 位)计算机上 Python 安装。
它引发了这个错误:
Can't find a usable init.tcl in the following directories: [list of directories]
This probably means that Tcl wasn't installed properly
为什么我的脚本在使用 PyInstaller 编译后找不到 init.tcl
?
这是 Windows 7 64 位机器上 PyInstaller 和 Tkinter 的已知问题。 PyInstaller 的 GitHub 存储库中有一个 issue report。
一直在底部这个问题是从另一个问题中引用的,即 this one 说降级到 PyInstaller 3.1.0 可以帮助其他人解决问题。
pip install pyinstaller==3.1.0
我自己已经能够使用虚拟机确认这一点。
由于这个问题已经两年没有解决,所以我继续 started a bounty on Bountysource。在问题得到解决之前,您可以尝试一些解决方法:
解决方法 1 - 手动复制丢失的文件
如 a related issue 中所述,您可以从本地 Python 安装中手动复制丢失的文件。
- 找到您本地的 Python 安装。 (
%LocalAppData%\Programs\Python
) - 复制丢失的文件夹(
...\Python36-32\tcl\<missing_folder>
) - 将副本移动到应用程序的
tcl
文件夹 (...\dist\<app_name>\tcl\<missing_folder>
)
解决方法 2 - 运行 和 --onefile
运行在 --onefile
模式下使用 PyInstaller 似乎可以避免这个问题。
但是,请注意 运行 在单文件模式下会增加启动时间。
解决方法 3 - 降级到 PyInstaller 3.1.0
pip install pyinstaller==3.1.0
According to ugoertz,降级到 PyInstaller 3.1.0 解决了这个问题。
Downgrading to 3.1.0 (and also downgrading setuptools to 19.2 because of the problem described in #1941) fixed the issue for me.
在您的情况下,您会发现 python 目录中有 Tcl8.X 文件夹,它位于您在问题中提到的 [目录列表] 中未提及的位置。只需从这些目录列表中选择任何路径(最好是 /lib )。
这将允许 python 找到 Tcl 库文件并且它会起作用。
注意:不要移动文件,只需复制它们。