0

I have made a GUI using PySimpleGui, the compiled (.exe) file works fine when I run on my own computer. I've compiled the file with Pyinstaller, through the command "pyinstaller -F -w myfile.py". I have one colleague which it also works for when he runs it on his computer, but my second colleague has issues when he tries to run the .exe file.

He gets error "_tkinter.TclError: Can't find a usable init.tcl in the following directories: ... This probably means that Tcl wasn't installed properly". I've been searching for quite some time, but cant seem to solve the issue, have tried adding "--hidden-import tkinter" when I compile the file, but nothing seems to help. Is there somebody who knows a solution to this issue?

fejz1234
  • 5
  • 6
  • What version of Python are you using and what version of Pyinstaller are you using? I'm guessing your one colleague may not have the c++ redist package installed or maybe you are dynamically linking tcl/tk and they don't have it installed. Also, you must be using the same version of windows... – sytech Nov 10 '21 at 13:42
  • @sytech I'm using Python 3.8.8, and version 4.7 of Pyinstaller. – fejz1234 Nov 10 '21 at 13:46
  • What is c++ redist package? I'm not linking any other files/folders apart from the .exe file, which he fails to run. – fejz1234 Nov 10 '21 at 13:47
  • `Tcl` is separated program/language created in `C/C++` - it is not Python script - and sometimes Pyinstaller has problem to find libraries which are not created in Python and you have to manually find it (probably `libtcl.dll`) and add manually to file `.spec` which `Pyintaller` uses to generate `.exe`. You should check Pyinstaller documentation - there is page `how to use file .spec` and `what to do when something goes wrong.` – furas Nov 10 '21 at 14:31
  • if someone has already installed Python then it has also installed `Tcl` and .exe may find it even if it doesn't have it in `.exe` – furas Nov 10 '21 at 14:36
  • Ok I see! So I should add libtcl.dll file to the .spec? – fejz1234 Nov 10 '21 at 14:42
  • I'm not sure if its name is `libtcl.dll` but you have to find it and add to `.spec`. It may need also `libtk.dll`. I think this problem was many times on Stackoverflow and you could find questions with more details - even on current page in right collumn `Related` I see some links. – furas Nov 10 '21 at 14:46
  • I thought nothing else was needed to be included when you compile to an exe with pyinstaller, but I guess that wasnt the case. How do I decide which dll file is the one that needs to be included? I have no clue on how you add a dll file to the .spec, would you mind explain? – fejz1234 Nov 10 '21 at 14:54
  • Is there someone who could help me? Would really appreciate any help. I'm still stuck. – fejz1234 Nov 11 '21 at 06:58
  • Have you tried compiling with https://pypi.org/project/pysimplegui-exemaker/? – ferdy Nov 12 '21 at 14:53
  • @ferdy No I haven't, but isnt that just a GUI font end of Pyinstaller? – fejz1234 Nov 12 '21 at 15:14
  • @fejz1234 indeed it is. Perhaps there might be options used here that could be different from what you were using. I used this before and so far I have not received any issues with my users. – ferdy Nov 12 '21 at 18:54
  • @ferdy I tried it out now, compiled it with pysimplegi-exemaker. Sent the .exe file to my colleague, but he wasn't able to run it on his computer. It's the same error as is stated in the title (tcl-related). – fejz1234 Nov 15 '21 at 08:53
  • You can add dll's via the command line. After the -F in your original command line, try --add-data "msvcr100.dll;." You can add other necessary files with additional --add-data switches. – Frank Nov 15 '21 at 21:07
  • @fejz1234 thanks for the feedback, do you have info of your colleague's PC specs, OS, version, 32/64bit? – ferdy Nov 15 '21 at 22:55

1 Answers1

1

according to answers here you need to copy tcl into the lib folder...

Python Tkinter throwing Tcl error

Your .spec file may also need the lib?

datas=[
             ('c:\\pathtoyour\\python\\3.8.10\\x64\\lib\\site-packages', '.'),

maybe also try with/without the --onefile flag

byteface
  • 152
  • 2
  • 7
  • But I want to distribute my python program by just a single file (.exe), so would copying tcl into the lib folder solve this issue? – fejz1234 Nov 17 '21 at 08:19
  • It should bundle it. If it doesn't you can wrap it in ANOTHER exe. called an 'installer'. Which has all the files in it including your app exe. i.e. this is how program folders with deps get installed. There's lots of 'installers' so you will have to google around. One i've heard of is 'Inno Setup' – byteface Nov 17 '21 at 09:16
  • Sorry but I have a hard time following what to do. Should I copy the line you wrote into the .spec file, and then compile my program with Pyinstaller? – fejz1234 Nov 19 '21 at 09:47
  • I believe any paths in datas will be copied to the distribution. use the path to your venv. – byteface Nov 19 '21 at 18:36
  • Is there a way to contact you? I'm having trouble with this.. – fejz1234 Dec 02 '21 at 11:22
  • ye im on discord but then the answer wont be on here. – byteface Dec 03 '21 at 01:17
  • I'll post the answer and steps needed here once everything is working to run on my colleagues computer. It is hard to communicate when the chat extends. What is your username# on discord? – fejz1234 Dec 03 '21 at 08:09
  • in this repo. the example appears to collect tcl. a github workflow triggers 3 builds, 1 for each OS then puts them on this package release page. the windows one has an exe with also all the gubbins. https://github.com/byteface/package/releases as I said you'd then need to wrap that in an installer. see the windows spec file. and the command passed to pyinstaller in the workflow yml . it might point you in right dir. I changed the dir paths from local to github in the workflow around commit 8. you will see it was just to my venv before i shifted it to github – byteface Dec 03 '21 at 16:22