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},
Related
I know there have been a bunch of questions already asked regarding this but none of them really helped me. Let me explain the whole project scenario so that I provide a better clarity to my problem. The directory structure is somewhat like this shown below:
Project Directory Layout
I need to convert this whole GUI based project (The main file is using Tkinter module to create GUI) into main.exe which I can share with others while making sure that all the additional files work exactly the same way it is working now when I run this main.py via Command Prompt. When I use this command with pyinstaller -
"pyinstaller --onefile --noconsole main.py"
It creates main.exe which shows "Failed to execute script" on running. Please provide me a detailed explanation on what should I do to achieve what I have stated above. Thank you in advance.
pyinstaller uses a few dirty tricks to compress a bunch of files into one
I recommend using cx_Freeze instead along with inno setup installer maker
do pip install cx_Freeze to install that and go here for inno setup
then copy the following into a file named setup.py in the same folder as your project
from cx_Freeze import setup, Executable
setup(name = "YOUR APP NAME" ,
version = "1.0.0" ,
description = "DESCRIPTION" ,
executables = [Executable("PYTHON FILE", base = "Win32GUI")]
)
lastly run python setup.py build
if you want as onefile download this file here
just edit the file a bit and use inno compiler to make into installer
Suppose our project has the following structure.
MyApp
|-models
| |-login.kv
|-data
| |-words.json
| |-audio.tar.gz
|-fonts
| |-FredokaOne.ttf
|-images
| |-gb.pngsound.png
| |-icon.ico
|-main.py
|-main.kv
|-draw.py
|-image.py
and depends on the following packages:
- kivy
- kivymd
- ffpyplayer
- gtts
First things first is to install cx_Freeze.
pip install cx_Freeze
Copy the following into a file named setup.py in the same folder as your project.
# https://cx-freeze.readthedocs.io/en/latest/distutils.html
import sys
from cx_Freeze import setup, Executable
includes = []
# Include your files and folders
includefiles = ['models/','data/','fonts/','images/','main.kv','draw.py','image.py']
# Exclude unnecessary packages
excludes = ['cx_Freeze','pydoc_data','setuptools','distutils','tkinter']
# Dependencies are automatically detected, but some modules need help.
packages = ['kivy','kivymd', 'ffpyplayer','gtts']
base = None
shortcutName = None
shortcutDir = None
if sys.platform == "win32":
base = "Win32GUI"
shortcutName='My App'
shortcutDir="DesktopFolder"
setup(
name = 'MyApp',
version = '0.1',
description = 'Sample python app',
author = 'your name',
author_email = '',
options = {'build_exe': {
'includes': includes,
'excludes': excludes,
'packages': packages,
'include_files': includefiles}
},
executables = [Executable('main.py',
base = base, # "Console", base, # None
icon='images/icon.ico',
shortcutName = shortcutName,
shortcutDir = shortcutDir)]
)
Lastly run.
python setup.py build
This command will create a subdirectory called build with a further subdirectory starting with the letters exe. and ending with the typical identifier for the platform that distutils uses. This allows for multiple platforms to be built without conflicts.
On Windows, you can build a simple installer containing all the files cx_Freeze includes for your application, by running the setup script as:
python setup.py bdist_msi
Cx_freeze references
Doc
Git Hub
I'm trying to create an executable python program that runs on windows without python being installed, for this I'm using cx_Freeze. But I get the following error: "Cannot load mkl_intel_thread.dll"
On my PC, which has python installed (miniconda3), I built the executable using cx_Freeze, and when I ran the executable I also would get "Cannot load mkl_intel_thread.dll". I fixed this by going to my python folder, Library\bin, and copied the mkl_intel_thread.dll file to where the executable is placed. The problem is, when moving the whole folder to another PC (without python installed), this error reappears, even though the mkl_intel_thread.dll is in the folder.
File that I want to distribute (plot.py):
import matplotlib.pyplot as plt
a = [0, 1, 2]
b = [0, 2, 0]
plt.fill(a, b, 'b')
plt.show()
cx_Freeze setup file (setup.py):
import cx_Freeze
import sys
import matplotlib
import numpy
import os
os.environ['TCL_LIBRARY'] = "C:\\Miniconda3\\tcl\\tcl8.6"
os.environ['TK_LIBRARY'] = "C:\\Miniconda3\\tcl\\tk8.6"
executables = [cx_Freeze.Executable("plot.py")]
build_exe_options = {"includes":['numpy.core._methods',
'numpy.lib.format', 'matplotlib.backends.backend_tkagg']}
cx_Freeze.setup(
name = "script",
options = {"build_exe": build_exe_options},
version = "0.0",
description = "A basic example",
executables = executables)
EDIT:
Try to copy all files starting with mkl you find under Library\bin or numpy\core into the build folder, as well as libiomp5md.dll, see Python Pyinstaller 3.1 Intel MKL FATAL ERROR: Cannot load mkl_intel_thread.dll and cx_freeze converted GUI-app (tkinter) crashes after pressing plot-Button.
Once you have found out which file(s) need(s) to be manually copied, you can let cx_Freeze include the necessary file(s) by using the include_files list of the build_exe options (see code snippet below). If necessary, you can use a tuple (source, destination) as item in the include_files list to let cx_Freeze copy a file from source to a specific destination into the build directory, see the cx_Freezedocumentation.
I see further potential problems in the setup script you've posted in your question:
include the whole numpy packages using the packages list of the build_exe options, it is easier and maybe safer
it is safer to dynamically find out the location of the TCL/TK DLLs
for cx_Freeze 5.1.1, the TCL/TK DLLs need to be included in a lib subdirectory of the build directory
In summary, try t o use
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')
build_exe_options = {'packages': ['numpy'],
'includes': ['matplotlib.backends.backend_tkagg'],
'include_files': [(os.path.join(PYTHON_INSTALL_DIR, 'DLLs', 'tcl86t.dll'),
os.path.join('lib', 'tcl86t.dll')),
(os.path.join(PYTHON_INSTALL_DIR, 'DLLs', 'tk86t.dll'),
os.path.join('lib', 'tk86t.dll'))
# add here further files which need to be included as described in 1.
]}
in your setup script.
A similar issue affects cx_Freeze 6.1 or 6.2: the executable does not launch, either without error message or with
INTEL MKL ERROR: The specified module could not be found. mkl_intel_thread.dll.
Intel MKL FATAL ERROR: Cannot load mkl_intel_thread.dll.
Configuration:
Windows 10
Python 3.8.5 installed from https://www.python.org/
numpy 1.19.1+mkl installed with pip using wheel from https://www.lfd.uci.edu/~gohlke/pythonlibs/
various python modules installed using pip
This is also observed with Python 3.6.8 or earlier versions of numpy such as e.g. 1.18.4+mkl or 1.19.0+mkl.
I've observed that cx_Freeze includes 3 DLLs mkl_rt.dll, python38.dll, and vcruntime140.dll in the subdirectory lib\numpy\core of the build directory, whereas the original installation does not contain any DLL in the subdirectory site-packages\numpy\core (all DLLs are in site-packages\numpy\DLLs). If I manually remove mkl_rt.dll from the subdirectory lib\numpy\core of the build directory after building the application with cx_Freeze, the issue disappears and the application works.
This solution can be implemented by adding the following code at the end of the setup.py script:
numpy_core_dir = os.path.join(dist_dir, 'lib', 'numpy', 'core')
for file_name in os.listdir(numpy_core_dir):
if file_name.lower().endswith('.dll'):
file_path = os.path.join(numpy_core_dir, file_name)
os.remove(file_path)
where dist_dir is the build directory generated by cx_Freeze (passed to the build_exe option).
Just copy these four files in cx_freeze generated build folder
mkl_core.dll
mkl_def.dll
mkl_intel_thread.dll
mkl_mc3.dll
Manage to find a solution to this by downgrading numpy==1.18.2 from numpy==1.19.1 when using cx_Freeze==6.5.3.
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.
I choose to try using cx_freeze which converts my simple python 3.x keylogger to an exe. I choose cx_freeze because py2exe is only python 2.x I am compiling my code using this setup.py script.
from cx_Freeze import setup, Executable
# Dependencies are automatically detected, but it might need
# fine tuning.
buildOptions = dict(packages = [], excludes = [])
base = 'Console'
executables = [
Executable('logger.py', base=base, targetName = 'logger.exe')
]
setup(name='PyLogger',
version = '0.1',
description = 'A Simple Keylogger',
options = dict(build_exe = buildOptions),
executables = executables)
and I when I compile my code which is
try:
import pythoncom
except ImportError:
input("Import Error, pywin32 is not installed")
try:
import pyHook
except ImportError:
input("Import Error, pyHook is not installed")
I get the import error saying both pywin32 and pyHook is not installed. How do you import external modules into cx_freeze.
EDIT - I have tried changing the setup.py to add the includes option but it made no difference.
from cx_Freeze import setup, Executable
# Dependencies are automatically detected, but it might need
# fine tuning.
buildOptions = dict(packages = ['pyHook','pythoncom'],includes = ['pyHook','pythoncom'], excludes = [])
base = 'Console'
executables = [
Executable('logger.py', base=base, targetName = 'logger.exe')
]
setup(name='PyLogger',
version = '0.1',
description = 'A Simple Keylogger',
options = dict(build_exe = buildOptions),
executables = executables)
Find the .pyd file of the external module. Copy and paste that into the build file. So, for example, if it was looking for _cpyHook (I had the same problem as you and it said that module was missing), go to C:\Python33\Lib\site-packages\pyHook and copy and paste the file into C:\Python33\build\exe.win-amd64-3.3.
Try listing the missing packages explicitly in the build options like so:
buildOptions = dict(packages = ['pyHook', 'pywin32'], excludes = [])
And see the accepted answer to this question if you need to include other (non-Python) files in your build.
EDIT: I finally had time to look at this a little more, and it seems to be a tricky problem. I'll keeping poking at it as time permits, but I thought I'd post my findings in case they're useful to the OP. I suspect that the pyHook module doesn't play nice when 'frozen', i.e., when it's included in a zip file. If I use this setup.py:
from cx_Freeze import setup, Executable
buildOptions = dict(
includes=['pythoncom'],
packages=['pyHook']
)
executables = [
Executable('logger.py', base='Console', targetName = 'logger.exe')
]
setup(
name='PyLogger',
version = '0.1',
description = 'A Simple Keylogger',
options = dict(build_exe = buildOptions),
executables = executables
)
the generated logger.exe does not—initially, at least—run correctly, and generates the error:
Import Error, pyHook is not installed
However, if I run the following command from the directory containing the EXE:
unzip library.zip
and re-run logger.exe, then everything seems to work fine. It's just not able to load pyHook from the library.zip file that cx_Freeze generates. I've seen this kind of problem before in the past, and worked around it by munging sys.path in my top-level script prior to loading any modules. I'll see if I can dig up one of those examples. In the meantime, perhaps this advice will help the OP: try unzipping the zip file and see if it makes a difference. A couple things to note:
I'm not having any problems importing pywin32, only pyHook
I did try setting create_shared_zip=False and include_in_shared_zip=False in the build options, but this just resulted in a file named logger.zip instead of library.zip. (Weird. I can't believe that's not a bug.)
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