Skip to content

Bessouat40/exe-generation-tutorial

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 

Repository files navigation

Exe generation

Documentation for exe generation.

  1. Virtual environment creation
  2. Setup your virtual environment
    1. Setup environment for a script
    2. Setup environment for a library
      1. With a requirements.txt file
      2. Without requirements.txt file
  3. EXE file generation
    1. EXE generation for a script
    2. EXE generation for a library
  4. Add properties to your EXE file

Virtual environment creation

First we need to create a virtual environment in order to reduce our exe file weight and his generation time.

We will add only necessaries libraries in this environment. For that, we need to create a requirements.txt file listing all our dependencies.

Then :

  • Go in your directory :
python -m venv myEnv

Then you will have a new folder myEnv in your directory.

  • Go to myEnv/Scripts/ and copy activate.bat in your C:\Workspace directory.

  • Finally :

cd /Workspace
activate.bat

Now your virtual environment is running.

venv

Setup your virtual environment

Now we need to create our virtual environment with needed libraries.

Setup environment for a script

Install all your dependencies :

pip install <name of your library>

⚠ WARNING: At least, you need to install pyinstaller :

pip install pyinstaller

Setup environment for a library

With a requirements.txt file

If you have a requirements.txt file with all your dependencies, go to your project directory and run :

python -m pip install -r requirements.txt

⚠ WARNING: Don't forget to add pyinstaller in your requirements.txt file !!!

Without requirements.txt file

Install all your dependencies :

pip install <name of your library>

⚠ WARNING: At least, you need to install pyinstaller :

pip install pyinstaller

EXE file generation

EXE generation for a script

You just need to run :

pyinstaller --onefile <path-to-my-file>

EXE generation for a library

You just need to run :

pyinstaller <path-to-your-main-file> --paths <abslolute-path-to-your-library>

⚠ WARNING: If your library is at /Workspace/dev/Library, you need to specify /Workspace/dev for --paths parameter !

Add properties to your EXE file

If you want to add Properties to your executable file, you need to execute this command line :

pyinstaller --version-file=/Path/to/properties.rc <path-to-your-main-file> --paths <abslolute-path-to-your-library>

properties.rc is the file wich contains all details of your executable file.

You can find an example properties.rc file in this Gitlab repository !

File example :

VSVersionInfo(
  ffi=FixedFileInfo(
    filevers=(1, 0, 0, 0),
    prodvers=(1, 0, 0, 0),
    mask=0x3f,
    flags=0x0,
    OS=0x40004,
    fileType=0x1,
    subtype=0x0,
    date=(0, 0)
    ),
  kids=[
    StringFileInfo(
      [
      StringTable(
        u'040904B0',
        [StringStruct(u'CompanyName', u'Company'),
        StringStruct(u'FileDescription', u'Description of my script'),
        StringStruct(u'FileVersion', u'1.0.0'),
        StringStruct(u'InternalName', u'script'),
        StringStruct(u'LegalCopyright', u'\xa9 MyScript. All rights reserved.'),
        StringStruct(u'OriginalFilename', u'script.exe'),
        StringStruct(u'ProductName', u'Script'),
        StringStruct(u'ProductVersion', u'1.0.0')])
      ]),
    VarFileInfo([VarStruct(u'Translation', [0, 0])])
  ]
)

Releases

No releases published

Packages

No packages published