at the moment I am facing a problem regarding scipy and cx-Freeze.
Windows 7 Enterprise (64-Bit);
Python 3.5.2|Anaconda 4.2.0 (64-bit);
scipy 0.18.1;
cx-Freeze 5.0.1;
I want to freeze a python script into an executable. Below you find the source code and the freeze script.
main.py
import scipy
if __name__ == '__main__':
print('Test dirstribution methods!')
That's the main.py file.
setup.py
import sys
from cx_Freeze import *
packages = ['numpy']
excludes = ['tkinter']
distTest_Target = Executable(
script = "main.py",
base = "Console",
shortcutName="distTest",
targetName = "distTest.exe"
)
build_exe_options = {
"packages": packages,
"excludes":excludes
}
setup(name='distTest',
version='1.0.0',
description='distTest (64-bit)',
options = {"build_exe": build_exe_options},
executables=[distTest_Target]
)
The build process executes without errors, but if I try to start the exe I get the following Error:
Figure: Error during execution of exe
If I try to add 'scipy' to the package list like packages = ['numpy','scipy'] I get another error during the build process: Figure: scipy ImportError.
Has anybody an idea what is wrong there? Thank you in advance for your help!
Installing the latest version of Anaconda (4.3.1) and editing hooks.py in the cx_freeze package:
finder.IncludePackage("scipy.lib")
replaced by:
finder.IncludePackage("scipy._lib")
solved the problem.
Related
Hi I have following cx_Freeze setup.py file for an application that uses
pandas module. When I generate msi I am facing issues. I looked all over the google for this but none of them are working for me.
include-files = ['aardvark.dll']
includes = []
excludes = []
base = "Win32GUI"
exe = Executable(
script="test.py",
initScript=None,
base=base,
targetName="test.exe",
copyDependentFiles=True,
compress=False,
appendScriptToExe=False,
appendScriptToLibrary=False,
shortcutDir="MyProgramMenu",
shortcutName=APP_NAME)
bdist_msi_options = {
"upgrade_code": UPGRADE_CODE,
"add_to_path" : False}
setup(
name=APP_NAME,
version=VERSION,
author="sri",
description='test Tool',
options={"build_exe": {"excludes":excludes,
"includes":includes,
"include_files":includefiles},
"bdist_msi" : bdist_msi_option},
executables=[exe])
When I build msi with cx_Freeze==4.3.4 it gives
this error:
cx_Freeze.freezer.ConfigError: no file named sys (for module collections.sys)
and when I use cx_Freeze >= 5.0.0 the msi is created but after installing this gives
ImportError: Missing required dependencies['numpy']
I tried all the available stack overflow work around but none of them is working any suggestion will be a great help thanks in advance.
pandas depends on numpy and you need to explicitly add numpy to the packages list of the build_exe options in order that cx_Freezeincludes numpycorrectly, see Creating cx_Freeze exe with Numpy for Python
Try to add the following to your setup script
packages = ['numpy']
and to modify the options according to
options={"build_exe": {"excludes":excludes,
"includes":includes,
"include_files":includefiles,
"packages":packages},
"bdist_msi" : bdist_msi_option},
I'm using cx_freeze to pack my Python script as a standalone executable.
The exe is running fine on the machine it was packed (with python 3.5 and all the relevant packages).
But when I copied the folder cx_freeze created to another machine the I got this error:
My cx_freeze script:
import sys
import numpy
import os.path
from cx_Freeze import setup, Executable
os.environ['TCL_LIBRARY'] = r'C:\Users\Administrator\AppData\Local\Programs\Python\Python36-32\tcl\tcl8.6'
os.environ['TK_LIBRARY'] = r'C:\Users\Administrator\AppData\Local\Programs\Python\Python36-32\tcl\tk8.6'
setup(
name = "DocSum",
version = "1.0",
options = {"build_exe": {"packages":["idna","asyncio", "encodings","numpy", "jinja2.ext"]}},
description = "DocSumRESTfulServer",
executables = [Executable("DocSumRESTfulServer.py", base = None)]
)
Any idea what could be the reason? I thought that the exe should be a standalone (run on machines without python). Am I wrong?
It seems that not all dependencies were compiled successfully.
If you want to have a standalone executable, I recommend pyinstaller.
Just pip install it then:
pyinstaller.exe --onefile yourFile.py
The --onefile flag is used to package everything into a single executable. Your executable file would be found on the dist folder.
You could also try this site.
I had the same problem. At the end I discovered that I need to copy also my python37.dll and the lib directory.
If the exe, dll and the directory are on the same directory, it works.
I would like to have a single exe too.
I recently wrote a library (in Python 3.6) and built a GUI for it using tkinter on Windows 10. The GUI is now finished, and I'm trying to freeze it using cx_Freeze.
The setup script runs perfectly fine (or at least I couldn't spot any error message or warning) and I can get my executable out of it. The problem is, when I run it, I get the following error message:
File "C:\Program Files\Python36\lib\site-packages\tensorflow\python\profiler\profiler.py", line 22 in <module>
from tensorflow.core.profiler.tfprof_log_pb2 import OpLogProto
ModuleNotFoundError: No module named 'tensorflow.core.profiler.tfprof_log_pb2'
The reason why TensorFlow is mentioned here is that my library uses TensorFlow, and of course, so does my GUI. What the entire error message says is that when I'm importing tensorflow (import tensorflow as tf), the program tries to do from tensorflow.python import * and the profiler.py in tensorflow.python.profiler then tried to do the import that causes the error.
I found the file that causes the error, and when I do on IDLE from tensorflow.core.profiler.tfprof_log_pb2 import OpLogProto, it works perfectly fine.
Before reaching to that point, I encountered several similar problems (the cx_Freeze building without displaying any warning or error, but the .exe having some import errors), but I could so far fix them all by myself, mostly by adding them to the list of include_files in the setup script. I tried to do the same for this TensorFlow file, but it didn't work. I also tried including TensorFlow as a package in the setup script, or directly importing it all in my main.py, without success.
My setup.pyis the following (there might be some unnecessary includes with it, since I tried lots of things):
from cx_Freeze import setup, Executable
import os
import sys
os.environ['TCL_LIBRARY'] = "C:\\Program Files\\Python36\\tcl\\tcl8.6"
os.environ['TK_LIBRARY'] = "C:\\Program Files\\Python36\\tcl\\tk8.6"
base = None
if sys.platform == "win32":
base = "Win32GUI"
includes = ["tkinter", "_tkinter", "numpy.core._methods", "numpy.lib.format", "tensorflow"]
include_files = ["C:\\Program Files\\Python36\\DLLs\\tcl86t.dll",
"C:\\Program Files\\Python36\\DLLs\\tk86t.dll",
"C:\\Program Files\\Python36\\DLLs\\_tkinter.pyd",
"C:\\Program Files\\Python36\\Lib\\site-packages\\tensorflow\\core\\profiler\\tfprof_log_pb2.py",
"C:\\Program Files\\Python36\\Lib\\site-packages\\tensorflow\\python\\profiler\\profiler.py",
"C:\\Program Files\\Python36\\Lib\\site-packages\\tensorflow\\include\\tensorflow\\core\\profiler\\tfprof_log.pb.h"]
packages = []
setup(name = "Ap'Pear",
version = "0.1",
description = "Test executable",
options = {"build_exe": { "includes": includes, "include_files": include_files, "packages": packages}},
executables = [Executable(script = "main.py", targetName = "Ap'Pear.exe", base = base, icon = "images/icon.ico")],
)
I tried rebuilding TensorFlow and its dependencies from scratch, but it didn't solve anything either.
Thanks in advance!
I was able to resolve this problem by creating a blank __init__.py file in \path\to\python\Lib\site-packages\tensorflow\core\profiler. I am running python 3.5.2 and TensorFlow 1.5.0 so this solution may be specific to my installations.
I have a .py file that I am trying to convert into an exe. I have tried numerous tries to build this file using cx_Freeze, but I keep getting the same error every time.
I've heard that it's got something to do with cx_Freeze, so I uninstalled cx_Freeze and reinstalled it using pip install cx_freezexxxx.whl wheel, but that still didn't work. I build my exe by writing python setup.py build in command line. Here's my setup .py code.
import cx_Freeze
import sys
import os
os.environ['TCL_LIBRARY'] = "C:\\Users\\louisa\\tcl\\tcl8.6"
os.environ['TK_LIBRARY'] = "C:\\Users\\louisa\\tcl\\tk8.6"
base = None
if sys.platform == 'win32':
base = "Win32GUI"
executables = [cx_Freeze.Executable("filemakergui.py", base=base, icon="Treetog-I-Documents.ico")]
cx_Freeze.setup(
name = "ALT File Maker",
options = {"build_exe": {"packages":["tkinter"], "include_files":["Treetog-I-Documents.ico", "Hopstarter-Sleek-Xp-Basic-Help.ico", "Custom-Icon-Design-Flatastic-2-Success.ico"]}},
version = "0.01",
description = "ALT File Maker",
executables = executables
)
Is there anything wrong with what I've written in my setup.py file? I've been stuck on this problem for several days now. Any tips on resolving an issue like this?
I'm a newbie to cx_Freeze and I need some help. I'm writing an application with python 3.3, pyqt4 and some more libraries (scipy, numpy, matplotlib, dxfwrite). Now I'm trying to freeze the application with cx_Freeze under windows7. I'm using cx_Freeze-4.3.2.win-amd64-py3.3 and the following setup.py for cx_Freeze:
import sys
from cx_Freeze import setup, Executable
build_exe_options = {"packages": ["os"], "excludes": ["tkinter"] }
setup(
name = "Barrel Cam Editor",
version = "0.2.0",
description = "An editor for Barrel Cams",
options = {"build_exe": build_exe_options},
executables = [Executable("barrelcameditor.py", base = "Win32GUI")])
I run the command python setup.py build and it seems to work but when I launch the obtained exe I get an Importerror: DLL load failed.
I really do not know how to solve this problem. any help?
Tnx
PS:
Thank you for your help, it was a problem with scipy.linalg. I switched to numpy.linalg and it seems to work. Now I've another little problem: I was importing a custom package:
from barrelcam import camdata, camdlg, camwidget
but in this way it is not working.
I found a workaround: I moved the files to the barrelcameditor folder and it seems to work, changing the import to
import camdata, camdlg, camwidget
There is a way to keep the original position of files?
Thank you