PyInstaller fails on Windows 7: “Can't find a usable init.tcl”

无人久伴 提交于 2019-12-29 01:51:11

问题


I have a basic Python script which uses Tkinter.

from Tkinter import Tk
from tkFileDialog import askdirectory
Tk().withdraw()
print askdirectory()

After compiling my script with PyInstaller, I tried to run my program on Windows 7 (64-bit) computer which didn't have Python installed.

It raised this error:

Can't find a usable init.tcl in the following directories: [list of directories]
This probably means that Tcl wasn't installed properly

Why does my script fail to find init.tcl after compiling with PyInstaller?


回答1:


This is a known issue with PyInstaller and Tkinter on Windows 7 64-bit machines. There is an issue report in the GitHub repository of PyInstaller.

All the way at the bottom this issue was referenced from another issue, namely this one which says that downgrading to PyInstaller 3.1.0 helps other people solve the issue.

pip install pyinstaller==3.1.0

I myself have been able to confirm this using a Virtual Machine.




回答2:


As RedPhantom mentioned, PyInstaller has a known issue with Tkinter applications on Windows 7 and Windows XP.

Since this issue has gone unfixed for two years, I've gone ahead and started a bounty on Bountysource. Until the issue is fixed, there are a few workarounds you can try:

Workaround 1 - Manually copy missing files

As mentioned in a related issue, you can manually copy the missing files from your local Python installation.

  1. Find your local Python installation. (%LocalAppData%\Programs\Python)
  2. Make a copy of the missing folder (...\Python36-32\tcl\<missing_folder>)
  3. Move the copy to your application's tcl folder (...\dist\<app_name>\tcl\<missing_folder>)

Workaround 2 - Run with --onefile

Running PyInstaller in --onefile mode seems to avoid this issue.

However, note that running in single file mode will increase startup time.

Workaround 3 - Downgrade to PyInstaller 3.1.0

pip install pyinstaller==3.1.0

According to ugoertz, downgrading to PyInstaller 3.1.0 resolved the issue.

Downgrading to 3.1.0 (and also downgrading setuptools to 19.2 because of the problem described in #1941) fixed the issue for me.




回答3:


In your case you will find that there is Tcl8.X folder in python directory, it is at a place which is not mentioned in [list of directories], you mentioned in your question. Just pick any of the paths from those directory listings (preferably /lib ).

That will allow python to find Tcl library files and it will work.

Note: DO NOT MOVE FILES, JUST COPY THEM.



来源:https://stackoverflow.com/questions/42180492/pyinstaller-fails-on-windows-7-cant-find-a-usable-init-tcl

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!