Lane Lee
Lane Lee

Reputation: 87

Pyinstaller-generated exe cannot run on another computer

My computer's OS is 64-bit win 10. Python 2.7, 32-bit.

My code is plot.py, simple as below:

import matplotlib.pyplot as plt
import FileDialog
plt.plot([1,2,3,4])
plt.ylabel('some numbers')
plt.show()

When I execute pyinstaller -F plot.py, the generated plot.exe works as expected on my current computer. However, I get an error if I try to run it on a different 32-bit Windows 7 computer:

Traceback (most recent call last):
  File "site-packages\GUI_tempCtrl\plot.py", line 3, in <module>
  File "lib\site-packages\matplotlib\pyplot.py", line 3147, in plot
  File "lib\site-packages\matplotlib\pyplot.py", line 928, in gca
  File "lib\site-packages\matplotlib\pyplot.py", line 578, in gcf
  File "lib\site-packages\matplotlib\pyplot.py", line 527, in figure
  File "lib\site-packages\matplotlib\backends\backend_tkagg.py", line 84, in new
_figure_manager
  File "lib\site-packages\matplotlib\backends\backend_tkagg.py", line 92, in new
_figure_manager_given_figure
  File "lib\lib-tk\Tkinter.py", line 1814, in __init__
_tkinter.TclError: Can't find a usable init.tcl in the following directories:
    C:/Users/ADMINI~1/AppData/Local/Temp/lib/tcl8.5 C:/Users/Administrator/lib/t
cl8.5 C:/Users/lib/tcl8.5 C:/Users/Administrator/library C:/Users/library C:/Use
rs/tcl8.5.15/library C:/tcl8.5.15/library



This probably means that Tcl wasn't installed properly.

Failed to execute script plot

Upvotes: 4

Views: 5779

Answers (2)

Stevoisiak
Stevoisiak

Reputation: 26782

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. 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.

Upvotes: 2

Dmitriy Zabranskiy
Dmitriy Zabranskiy

Reputation: 26

You can try downgrading pyinstaller to v3.1 and rebuilding your exe file on your first computer to solve this issue.

Alternatively, you can fix it on your second computer by setting the TCL_LIBRARY environment variable to C:\Python27\tcl\tcl8.5\ (or wherever tcl8.5 is located)

Upvotes: 1

Related Questions