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'm developing on Windows 10. cx_Freeze version is 5.1. Pandas versions is 0.23.4.
My setup.py looks like this:
import os
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')
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(PYTHON_INSTALL_DIR, 'DLLs', 'tcl86t.dll'),
os.path.join(PYTHON_INSTALL_DIR, 'DLLs', 'sqlite3.dll'),
],
},
}
setup(
name = "MyScript",
options = options,
version = "0.1",
description = 'Placeholder desc',
executables = executables
)
Note that I manually set the env variables because they were not being found during the build process and I had to manually move the DLLs to the virtualenv folder.
And the script looks like this:
import numpy as np
import pandas as pd
import tkinter as tk
root = tk.Tk()
root.mainloop()
If I comment out the import pandas as pd
, everything works fine. If I add the pandas import I get the following error:
C:\path\to\project\build\exe.win-amd64-3.6>MyScript.exe
Traceback (most recent call last):
File "C:\path\to\Envs\MyEnv\lib\site-packages\cx_Freeze\initscripts\__startup__.py", line 14, in run
module.run()
File "C:\path\to\Envs\MyEnv\lib\site-packages\cx_Freeze\initscripts\Console.py", line 26, in run
exec(code, m.__dict__)
File "MyScript.py", line 2, in <module>
File "C:\path\to\Envs\MyEnv\lib\site-packages\pandas\__init__.py", line 23, in <module>
from pandas.compat.numpy import *
File "C:\path\to\Envs\MyEnv\lib\site-packages\pandas\compat\__init__.py", line 32, in <module>
from distutils.version import LooseVersion
File "C:\path\to\Envs\MyEnv\lib\distutils\__init__.py", line 17, in <module>
real_distutils = imp.load_module("_virtualenv_distutils", None, distutils_path, ('', '', imp.PKG_DIRECTORY))
File "C:\path\to\Envs\MyEnv\lib\imp.py", line 245, in load_module
return load_package(name, filename)
File "C:\path\to\Envs\MyEnv\lib\imp.py", line 217, in load_package
return _load(spec)
File "<frozen importlib._bootstrap>", line 683, in _load
AttributeError: 'NoneType' object has no attribute 'name'
I've seen a lot of forum and stack overflow questions online (actually I had to fix a lot of errors to get here) but I can't work out what cx_Freeze is missing.
I've uninstalled and reinstalled pandas, I uninstalled cx_Freeze and tried installing a previous version (install failed but that's a different SO question). I actually tried pyinstaller and py2exe but there were so many errors which were less verbose (so harder to fix) that I gave up on anything but cx_Freeze to create the executable.
Can anybody help?