How to create an executable from python

8

I'm doing a service where I have to do a program that reads and creates 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 the only program that can help make 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 do not have some dlls (they are not always the same)

The executable is coming with VARIOUS folders with MANY files. This does not seem feasible, I wanted some way to "package" the files inside my executable.

The program is not so great, and does not use as many libraries, OS only and DATETIME.

I've tried using Pyinstaller and INNO setup, but none of them gives me any 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)])
    
asked by anonymous 10.02.2017 / 18:06

1 answer

2

You can use cx_Freeze.

  • pip install cx_Freeze
  • Create a file called setup.py in the same directory as your file (example test.py)
  • Inside the setup.py file you play the code that I'll leave in the end of the response
  • Run the command python setup.py build
  • 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
    )
    

    Aboutyourproblemwithmultiplefilesbesidesexecutable

    cx_Freezedoesnotonlycompilethe.exe,butinitsowndocumentation,itisrecommendedtouseIExpress,tocompacttheentiredirectorygeneratedbycx_Freezeinasingle.EXE

      

    YoucanuseIExpresstocompressthebuilddirectoryfromcx_Freezeintoaself-extractingarchive:anexewhichunpacksyourapplicationintoatemporarydirectoryandrunsit.IExpressisautilitythat'sincludedwithWindows,intendedformakinginstallers,butitworksequallywellifyoutellittorunthecx_Freeze-builtexeafterextraction.

    Source: link

        
    18.08.2017 / 23:05