Home » Java » java – How to create .exe file with cx_Freeze along with third party python packages?-Exceptionshub

java – How to create .exe file with cx_Freeze along with third party python packages?-Exceptionshub

Posted by: admin February 25, 2020 Leave a comment

Questions:

I am new to python programming and I want to create an .exe file along with third party python packages. My requirements is that if I give the source code of the project to any developer, he/she will simply run python setup.py build so that .exe file will be created. I have mentioned also install_requires in the setup.py file by mentioning the third party packages, but I am getting the errors. I provide below the code. This requirement is similar to java, maven based application where user runs the pom.xml to create the executable.

import sys
from cx_Freeze import setup, Executable

includefiles = []
includes = []
excludes = ['Tkinter']
packages = ['configparser == 4.0.2', 'colorama == 0.4.3', 'xlsxwriter == 1.2.7']
build_exe_options = {'includes':includes,'packages':packages, 'excludes':excludes, 'include_files':includefiles}

base = None

setup(name = 'Testing',
        version = '0.1',
        author = 'DD Mishra',
        description = 'A simple application',
        install_requires = ['configparser == 4.0.2', 'colorama == 0.4.3', 'xlsxwriter == 1.2.7'],
        options = {'build_exe': build_exe_options},
        executables = [Executable('main.py', base=base)]
)

I am using the command python setup.py build. First of all I want to install all the required packages like configparser, colorama, xlsxwriter and after that the exe should be created. All should happen automatically without manually installing the packages using pip command.

As per my above setup while running the command python setup.py build, I am getting the following error.

running build running build_exe Traceback (most recent call last):
File “setup.py”, line 13, in
setup(name = ‘Testing’, File “C:\devsoftwares\Python38\lib\site-packages\cx_Freeze\dist.py”, line
340, in setup
distutils.core.setup(**attrs) File “C:\devsoftwares\Python38\lib\distutils\core.py”, line 148, in setup
dist.run_commands() File “C:\devsoftwares\Python38\lib\distutils\dist.py”, line 966, in
run_commands
self.run_command(cmd) File “C:\devsoftwares\Python38\lib\distutils\dist.py”, line 985, in
run_command
cmd_obj.run() File “C:\devsoftwares\Python38\lib\distutils\command\build.py”, line 135,
in run
self.run_command(cmd_name) File “C:\devsoftwares\Python38\lib\distutils\cmd.py”, line 313, in
run_command
self.distribution.run_command(command) File “C:\devsoftwares\Python38\lib\distutils\dist.py”, line 985, in
run_command
cmd_obj.run() File “C:\devsoftwares\Python38\lib\site-packages\cx_Freeze\dist.py”, line
211, in run
freezer.Freeze() File “C:\devsoftwares\Python38\lib\site-packages\cx_Freeze\freezer.py”,
line 610, in Freeze
self.finder = self._GetModuleFinder() File “C:\devsoftwares\Python38\lib\site-packages\cx_Freeze\freezer.py”,
line 354, in _GetModuleFinder
finder.IncludeModule(name) File “C:\devsoftwares\Python38\lib\site-packages\cx_Freeze\finder.py”, line
631, in IncludeModule
module = self._ImportModule(name, deferredImports, File “C:\devsoftwares\Python38\lib\site-packages\cx_Freeze\finder.py”, line
348, in _ImportModule
raise ImportError(“No module named %r” % name) ImportError: No module named ‘configparser == 4.

0.2′

How to&Answers: