I started with using cx-freeze with the source file contain only print("hello from cx-freeze")
. It worked just fine.
Then, I tried https://gist.github.com/joferkington/9214844 I got the error message. I change my source file to be very simple. I still get TCL_LIBRARY error. I followed suggestion from KeyError: 'TCL_Library' when I use cx_Freeze (Martin Tournoij)
The error is gone. The exe files are created (like 500+ mb). When I run the file, I get the error message.
I check other people question Creating exe file with cx_Freeze, PyQt4, matplotlib and multiple .py files does not work (no answer provided there)
other questions like cx_Freeze help. ImportError
cx-freeze fails to include modules even when included specifically or cx-freeze doesn't find all dependencies
I checked them, but does not seem to apply to my case (at least I don't know how to make it work with what I am doing, if you can please explain more thank you)
This one is similar ImportError: No module named 'queue' while running my app freezed with cx_freeze but the solution was to import multiprocessing (I also tried that too it does not work)
I tried the full option for the setup.py
from cx_Freeze import setup, Executable
import sys
import os.path
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 = 'Console'
options = {
'build_exe': {'packages': ["pandas","numpy","scipy","matplotlib"],
'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, 'Library', 'plugins', 'platforms')
],
},
}
executables = [
Executable('plot2.py', base = base)
]
setup(name = "plot2" ,
version = "0.1" ,
description = "" ,
executables = executables,
options = options
)
I also try less option
from cx_Freeze import setup, Executable
import sys
import os.path
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 = 'Console'
options = {
'build_exe': {'packages': ["matplotlib"],
'include_files':[
os.path.join(PYTHON_INSTALL_DIR, 'DLLs', 'tcl86t.dll'),
os.path.join(PYTHON_INSTALL_DIR, 'DLLs', 'tk86t.dll')]
}
}
executables = [
Executable('plot2.py', base = base)
]
setup(name = "plot2" ,
version = "0.1" ,
description = "" ,
executables = executables,
options = options
)
Both are fine. I even have tcl86t.dll
and tk86t.dll
in my target folder.
Yet both fail when I try to run it. The setup with "less option" give the following error message
Traceback (most recent call last):
File "C:\ProgramData\Anaconda3\lib\site-packages\cx_Freeze\initscripts\__start
up__.py", line 14, in run
module.run()
File "C:\ProgramData\Anaconda3\lib\site-packages\cx_Freeze\initscripts\Console
.py", line 26, in run
exec(code, m.__dict__)
File "plot2.py", line 1, in <module>
File "C:\ProgramData\Anaconda3\lib\site-packages\matplotlib\__init__.py", line
127, in <module>
from . import cbook
File "C:\ProgramData\Anaconda3\lib\site-packages\matplotlib\cbook\__init__.py"
, line 35, in <module>
import numpy as np
File "C:\ProgramData\Anaconda3\lib\site-packages\numpy\__init__.py", line 158,
in <module>
from . import add_newdocs
File "C:\ProgramData\Anaconda3\lib\site-packages\numpy\add_newdocs.py", line 1
3, in <module>
from numpy.lib import add_newdoc
File "C:\ProgramData\Anaconda3\lib\site-packages\numpy\lib\__init__.py", line
8, in <module>
from .type_check import *
File "C:\ProgramData\Anaconda3\lib\site-packages\numpy\lib\type_check.py", lin
e 11, in <module>
import numpy.core.numeric as _nx
File "C:\ProgramData\Anaconda3\lib\site-packages\numpy\core\__init__.py", line
38, in <module>
from . import numeric
File "C:\ProgramData\Anaconda3\lib\site-packages\numpy\core\numeric.py", line
2896, in <module>
from . import fromnumeric
File "C:\ProgramData\Anaconda3\lib\site-packages\numpy\core\fromnumeric.py", l
ine 15, in <module>
from . import _methods
ImportError: cannot import name '_methods'
Even with https://github.com/anthony-tuininga/cx_Freeze/blob/master/cx_Freeze/samples/matplotlib/setup.py
base = 'Console'
if sys.platform == 'win32':
base = 'Win32GUI'
It still does not work (python setup.py build
work, but the program does not run when I double click .exe
file).
My code of plot2.py is just reduced to creating jpg file (it run when I did just python plot2.py
import matplotlib.pyplot as plt
x = [1,2,3,4,5.5]
y = [3,4,5,6,7.7]
plt.figure()
plt.plot(x,y,'o')
plt.savefig("test.jpg",dpi = 200)
I install python via anaconda. python --version
gives
Python 3.6.5 :: Anaconda, Inc.
result. conda list
show that my cx-Freeze
version is 5.1.1
with
if sys.platform == 'win32':
base = 'Win32GUI'
and add multiprocessor in the packages list it does not work (I think it is not relevant but see other people did (on other application) and it work so I tried, probably wrong). The best I can do is getting this error (picture below) at run time.
error report when click on the exe file
Is there a way to fix this? I have python on ubuntu system too, but did not try yet. I can uninstall python or use other version of python/cx-Freeze if this help. If I need to install other version of python/cx-Freeze please tell me how to do it, too.
Another question here is that is there a way to make the exe file that is smaller. Just create a graph should not be 500+ mb program. Maybe I include the package/file that should be excluded. Please help. Thank you.