Documentation for exe generation.
- Virtual environment creation
- Setup your virtual environment
- EXE file generation
- Add properties to your EXE file
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 copyactivate.bat
in yourC:\Workspace
directory. -
Finally :
cd /Workspace
activate.bat
Now your virtual environment is running.
Now we need to create our virtual environment with needed libraries.
Install all your dependencies :
pip install <name of your library>
⚠ WARNING: At least, you need to install pyinstaller :
pip install pyinstaller
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 !!!
Install all your dependencies :
pip install <name of your library>
⚠ WARNING: At least, you need to install pyinstaller :
pip install pyinstaller
You just need to run :
pyinstaller --onefile <path-to-my-file>
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 !
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])])
]
)