9

Some initial information: I have windows 10 on my computer and all programs are 64-bit versions.

I'm writting a game in python (3.6.1) using tkinter and now I would like to convert it to .exe. I have used cx_freeze (5.0.1) and it made the build, but when I try to open the game a window opens and then closes immediately. Therefore I tried to open it via cmd and the following error pops up:

File "sliks.py", line 1, in <module>
File "C:\Users\Tinka\AppData\Local\Programs\Python\Python36\lib\tkinter\__init__.py", line 36, in <module>
import _tkinter # If this fails your Python may not be configured for Tk
ImportError: DLL load failed: The specified module could not be found.

I have checked tkinter support as it says here: https://wiki.python.org/moin/TkInter and no error occurs.

Also I have tried to install tk-dev with pip as it says in some answers on this subject but nothing happens as I get this message:

C:\WINDOWS\system32>pip install tk-dev
Collecting tk-dev
Could not find a version that satisfies the requirement tk-dev (from versions: )
No matching distribution found for tk-dev

I never had any python 2.x on my computer so there are no mixed up libraries as in this case: ImportError DLL load failed importing _tkinter

Here is my setup.py file I have used for cx_freeze in case there is something wrong with that:

from cx_Freeze import setup, Executable
import os

os.environ['TCL_LIBRARY'] = r'C:\Users\Tinka\AppData\Local\Programs\Python\Python36\tcl\tcl8.6'
os.environ['TK_LIBRARY'] = r'C:\Users\Tinka\AppData\Local\Programs\Python\Python36\tcl\tk8.6'

base = None

setup(
    name = "Six",
    version = "0.1",
    options = {"build_exe": {"packages": ["tkinter"]}},
    executables = [Executable("sliks.py", base=base)]
    )

Any ideas what could be the problem? I know there are many opened questions on this subject, but I have tried most of the solutions and had no luck.

Community
  • 1
  • 1
PircK
  • 93
  • 1
  • 1
  • 6
  • Im having the same problem too. Did you get it figured out?? – Joe Jun 12 '17 at 20:08
  • No, sorry. I stopped trying after I spent way too many hours on it. – PircK Jun 14 '17 at 20:55
  • I managed to figure it. It actually isn't that bad really just comes down to identifying what is missing and manually pointing at it. – Joe Jun 15 '17 at 00:38

1 Answers1

13

I had to scour pretty hard to figure this one out for myself. Not sure if this helps anyone but it worked for me. From what I understand these errors are generated when cx_freeze either cannot find all the dependencies or is grabbing incorrect ones.

First thing I did was to drill down into my python directory. Be VERY careful here and ensure you are looking where your python code is executing. Your IDE may give you this path if you do not know it. In cases of multiple installations or environments you may be off.

Once in there I identified which file was causing the error. For my situation it was a tkinter dependency. tcl86.dll and tk86.dll were the problem. You can see the lines I added. Then my logo actually started doing it so I had to add that. Now it works great. Here is a sample of my setup.py file (cx_freeze config).

from cx_Freeze import setup, Executable
import sys
import os

includes = []
include_files = [r"C:\Users\Ace\AppData\Local\Programs\Python\Python36\DLLs\tcl86t.dll",
                 r"C:\Users\Ace\AppData\Local\Programs\Python\Python36\DLLs\tk86t.dll",
                 r"C:\Users\Ace\Desktop\IPNV\KP_App\FML\logo1.gif"]
os.environ['TCL_LIBRARY'] = r'C:\Users\Ace\AppData\Local\Programs\Python\Python36\tcl\tcl8.6'
os.environ['TK_LIBRARY'] = r'C:\Users\Ace\AppData\Local\Programs\Python\Python36\tcl\tk8.6'
base = 'Win32GUI' if sys.platform == 'win32' else None


setup(name='KpApp', version='0.9', description='KP Report App',
      options={"build_exe": {"includes": includes, "include_files": include_files}},
      executables=[Executable(r'C:\Users\Ace\Desktop\IPNV\KP_App\FML\firstapp.py', base=base)])
Joe
  • 2,641
  • 5
  • 22
  • 43
  • please have a look at [this](https://stackoverflow.com/questions/51627184/error-while-trying-to-build-a-py-code-via-cx-freeze), I hope you can help – bit_scientist Aug 01 '18 at 07:08
  • @voo_doo I looked at your post - It is hard to tell what is going on without either the code or the traceback. It does look like a UAC error. Have you tried running the code as Administrator? – Joe Aug 02 '18 at 11:34
  • yes I remember doing that too. But I ended up using `pyinstaller` and got what I wanted. Thank you – bit_scientist Aug 02 '18 at 11:37
  • this is duplicate answer from another question. i need different one!. I've already past this dll problem which ain't event make changes – greendino Jun 12 '20 at 20:49
  • @AbdullahSaid There May be a similar one now but when I posted this I couldn’t find others. And based on the upvotes neither could others. You need to check capitalization in your path and verify you have it exact. – Joe Jun 12 '20 at 21:55