package python project within an .exe

1

Good morning, I want to package a python project within 1 exe I know that with pyinstaller and py2exe it can be done but I need that only generates 1 exe and not the other libraries that generate these programs thank you very much in advance

    
asked by logancale2016 22.02.2017 в 17:10
source

2 answers

1

Both py2exe as PyInstaller allow you to create fully packaged executables in exe without external dependencies. To do this, you just have to specify it with the appropriate parameters.

In the case of PyInstaller you must specify the option --onefile or -f .

The basic use of PyInstaller is:

  • We install it, for this we can use pip , in my case since I have several versions of Python I open the console (CMD in Windows) and:

    py -3.5 -m pip install pyinstaller
    

    (This installs PyInstaller in Python 3.5)

  • We are located in the directory where our python module is and create the exe writing in the console (CMD in Windows):

    pyinstaller nombreDelScript.py --onefile
    

PyInstaller brings many more options (encryption, change of the icon and name of the exe, version, etc), you can see the official documentation to see all the possibilities. If you use external packages to the standard Python library I advise you to look at the supported packages by PyInstaller.

If everything goes well, the executable will be created in the same directory where you are located. The exe is inside the folder dist , the rest of files created outside this folder are used by PyInstaller in the packaging process but you only need the content of the folder dist , which in this case as we specify is a single executable that you can use anywhere you want without other external dependencies.

If you do not use the option --onefile you will see that you create a directory within dist that contains the exe but you will also find other files as files pyd or dll since if you do not specify anything PyInstaller works in mode onedir.

    
answered by 22.02.2017 в 19:02
1

If your program has dependencies or files external to Python you can use Inno Setup and select the option of "single EXE" .

Although as FJSevilla comments, you can configure P2exe and PyInstaller directly.

    
answered by 22.02.2017 в 17:41