raise Keyerror(key) from None Keyerror: 'TCL_LIB (.Py to Exe)

Asked

Viewed 330 times

0

I am trying to convert a Python script to exe to run on Windows machines, I have the following code in setup.py

import sys
from cx_Freeze import setup, Executable
import subprocess
import socket
import os



base = None
if sys.platform == "win32":
    base = "Win32GUI"

executables = [
        Executable("lista.py", base=base)
]

buildOptions = dict(
        packages = [],
        includes = ["subprocess","socket","os"],
        include_files = [
            os.path.join('C:\\Users\\Eduardo\\AppData\\Local\\Programs\\Python\\Python36-32', 'DLLs', 'tk86t.dll'),
            os.path.join('C:\\Users\\Eduardo\\AppData\\Local\\Programs\\Python\\Python36-32', 'DLLs', 'tcl86t.dll'),
        ],
        excludes = []
)




os.environ['TCL_LIBRARY'] = "C:\\Users\\Eduardo\\AppData\\Local\\Programs\\Python\\Python36-32\\tcl\\tcl8.6"
os.environ['TK_LIBRARY'] = "C:\\Users\\Eduardo\\AppData\\Local\\Programs\\Python\\Python36-32\\tcl\\tk8.6"

setup(
    name = "ListaConfigs",
    version = "0.0.1",
    description = "Recolhe Informações do Computador",
    options = dict(build_exe = buildOptions),
    executables = executables
 )

Looking for solutions found the links:Solution 1 and Solution 2 The problem is that both are errors. When I try to execute the command:

pyinstaller -F setup.py 

Returns the following error:

 return module_code_object.co_names[co_names_index]
 IndexError: tuple index out of range

The -F builds it with only one executable, without the other many files that are normally generated.

When I try cx_Freeze with the command:

python setup.py build

or python setup.py bdist_msi

Of the error:

 raise KeyError(key) from None
 KeyError: 'TCL_LIBRARY'

There is no python folder in Program Files or in x86. For some reason it was installed in this path that is in the code.

I don’t know what else can be done here.

Thank you for your attention

OBS.: I searched and it seems that pyinstaller is not yet compatible with python 3.6(Link that says so so you shouldn’t use a previous version to work

1 answer

1


Yes, the Stable version of pyinstaller is only compatible with Python 2.7, 3.3-3.5, Python 3.6 is only supported in the Development version of pyinstaller, but it is not yet stable software.

You can even risk and download (and install manually) the non-stable version:

Already the mistake of cx_Freeze is because it was not defined in the environment variables the TCL_LIBRARY, you can run them without setting too, directly on CMD (based on this reply soen, I don’t know if it works in 3.6):

set TCL_LIBRARY=C:\Program Files\Python36-32\tcl\tcl8.6
set TK_LIBRARY=C:\Program Files\Python36-32\tcl\tk8.6

However, I believe it is more practical to define setup.py

os.environ['TCL_LIBRARY'] = r'C:\Program Files\Python36-32\tcl\tcl8.6'
os.environ['TK_LIBRARY'] = r'C:\Program Files\Python36-32\tcl\tk8.6'

Browser other questions tagged

You are not signed in. Login or sign up in order to post.