I\'m trying to create a Python 3.6 executable using cx_Freeze which includes pandas and numpy. I\'m using Python 3.6.5 and a virtual env created using virtualenvwrapper. I\'
In cx_Freeze version 5.1.1, the included modules are in a subdirectory lib of the build directory. The manually added DLLs apparently need to be moved there as well.
You can do this with the following modification of your setup.py script:
options = {
'build_exe': {
'packages': packages,
'include_files': [
(os.path.join(PYTHON_INSTALL_DIR, 'DLLs', 'tk86t.dll'), os.path.join('lib', 'tk86t.dll')),
(os.path.join(PYTHON_INSTALL_DIR, 'DLLs', 'tcl86t.dll'), os.path.join('lib', 'tcl86t.dll')),
(os.path.join(PYTHON_INSTALL_DIR, 'DLLs', 'sqlite3.dll'), os.path.join('lib', 'sqlite3.dll'))
],
},
}
I'm actually not sure whether sqlite3.dll also needs to be moved to lib.
Your question is interesting in view of the fact that it seems to indicate an import conflict between pandas and tkinter. That's presumably why you get a different error message than reported in this question:
Getting "ImportError: DLL load failed: The specified module could not be found" when using cx_Freeze even with tcl86t.dll and tk86t.dll added in
EDIT: I manage to freeze and run the OP's example script main.py without errors using Python 3.6.5 on Windows 7 with the following configuration
idna 2.7 (installed with pip)
numpy 1.14.3+mkl (installed using Gohlke's binaries)
pandas 0.23.4 (installed with pip)
cx_Freeze 5.1.1 (installed with pip)
I use the following setup.py script:
import os
import sys
from cx_Freeze import setup, Executable
PYTHON_INSTALL_DIR = os.path.dirname(os.path.dirname(os.__file__))
os.environ['TCL_LIBRARY'] = os.path.join(PYTHON_INSTALL_DIR, 'tcl', 'tcl8.6')
os.environ['TK_LIBRARY'] = os.path.join(PYTHON_INSTALL_DIR, 'tcl', 'tk8.6')
base = None
if sys.platform == "win32":
base = "Win32GUI"
executables = [Executable("main.py", base=base)]
packages = ["idna", "os", "numpy", "importlib", "pandas"]
options = {
'build_exe': {
'packages': packages,
'include_files': [
(os.path.join(PYTHON_INSTALL_DIR, 'DLLs', 'tk86t.dll'), os.path.join('lib', 'tk86t.dll')),
(os.path.join(PYTHON_INSTALL_DIR, 'DLLs', 'tcl86t.dll'), os.path.join('lib', 'tcl86t.dll')),
(os.path.join(PYTHON_INSTALL_DIR, 'DLLs', 'sqlite3.dll'), os.path.join('lib', 'sqlite3.dll'))
],
},
}
setup(
name="MyScript",
options=options,
version="0.1",
description='Placeholder desc',
executables=executables
)