How to create an executable from python

I'm doing a service where I have to make a program that does reading and creating files with numeric data. The problem I have is that the computers on which the program will be used are not accessible to me.

Because of this, I needed to convert my file .py to .exe The program is ready in Python 3.5 and it seems that the only program that can help do the conversion is CX_FREEZE. I used it and formed a file...

I have 2 problems:

The file does not work on computers that are windows 7 (depending on the version), and that do not have some dlls (they are not always the same)

The executable is accompanied by several folders with many files. This doesn't seem feasible to me, I wanted some way to "package" the files inside my executable.

The program is not that big, and does not use as many libraries, only OS and DATETIME.

I've tried using Pyinstaller and INNO setup, but none gives me some light.

I would like to know if anyone has any alternatives or tips that I can use.

import sys
from cx_Freeze import setup, Executable


build_exe_options = {"packages": ["os", "datetime"], "excludes": []}

base = None
if sys.platform == "win32":
    base = "Console"  # para execuções em terminal

setup(name="GetSpecJoin",
      version="0.1",
      description="My GUI application!",
      options={"build_exe": build_exe_options},
      executables=[Executable("240117.py", base=base)])
Author: Erlon Charles, 2017-02-10

1 answers

You can use cx_Freeze.

  1. pip install cx_Freeze
  2. create a file named setup.py in the same directory as your file (example teste.py)
  3. inside the file setup.py you throw the code that I will leave in the end of response
  4. run the command python setup.py build
  5. inside the build folder will have its executable.

Setup.py

from cx_Freeze import setup, Executable
import sys

base = None

if sys.platform == 'win32':
    base = None


executables = [Executable("teste.py", base=base)]

packages = ["idna"]
options = {
    'build_exe': {

        'packages':packages,
    },

}

setup(
    name = "Nome Executavel",
    options = options,
    version = "1.0",
    description = 'Descricao do seu arquivo',
    executables = executables
)

insert the description of the image here

About your problem with multiple files in addition to executable

Cx_Freeze does not just compile the .exe, but in his own documentation, it is indicated the use of IExpress, for you to compress all the directory generated by cx_Freeze into a single.EXE

You can use IExpress to compress the build directory from cx_Freeze into a self-extracting archive: an exe which unpacks your application into a temporary directory and runs it. IExpress is a utility that's included with Windows, intended for making installers, but it works equally well if you tell it to run the cx_Freeze-built exe after extraction.

Source: http://cx-freeze.readthedocs.io/en/latest/faq.html

 3
Author: Guilherme IA, 2017-08-18 21:21:16