pyinstaller onedir option - exe file outside the directory

  • Last Update :
  • Techknowledgy :
import sys
import os
sys.path.append(os.path.join(os.path.dirname(sys.argv[0]), "lib"))
pyinstaller--onedir--windowed--runtime - hook = ".\_pyinstaller_hooks\runtime_hooks\use_lib.py"

Suggestion : 2

Name of scriptfiles to be processed or exactly one .spec file. If a .spec file is specified, most options are unnecessary and are ignored.,Writes the myscript executable folder in the dist folder.,Normally you name one script on the command line. If you name more, all are analyzed and included in the output. However, the first script named supplies the name for the spec file and for the executable folder or file. Its code is the first to execute at run-time.,Additional non-binary files or folders to be added to the executable. The path separator is platform specific, os.pathsep (which is ; on Windows and : on most unix systems) is used. This option can be used multiple times.

pyinstaller myscript.py
pyinstaller--noconfirm--log - level = WARN\
   --onefile--nowindow\
   --add - data = "README:."\
   --add - data = "image1.png:img"\
   --add - binary = "libfoo.so:lib"\
   --hidden -
   import = secret1\
   --hidden -
   import = secret2\
   --upx - dir = /usr/local / share / \
   myscript.spec
pyinstaller--noconfirm--log - level = WARN ^
   --onefile--nowindow ^
   --add - data = "README;." ^
   --add - data = "image1.png;img" ^
   --add - binary = "libfoo.so;lib" ^
   --hidden -
   import = secret1 ^
   --hidden -
   import = secret2 ^
   --icon = ..\MLNMFLCN.ICO ^
   myscript.spec
import PyInstaller.__main__

PyInstaller.__main__.run([
   'my_script.py',
   '--onefile',
   '--windowed'
])
pyinstaller my_script.py--onefile--windowed
pip install pyinstaller[encryption]

Suggestion : 3

I would like to use --onefile option to have a clean result and an easy to distribute file/program.,I'm using Pyinstaller on Windows to make an .exe file of my project.,I've used shutil module and .spec file to add extra data files (in my case a config-sample.ini file) to dist folder using Pyinstaller --onefile option.,Using --onefile option Pyinstaller put all declared "data-file" inside the single .exe file file.

First of all I've create a makespec file with the options I need:

$ pyi - makespec--onefile--windowed--name exefilename scriptname.py

Now I've edited the exefilename.spec adding at the end of the file the following code.

import shutil
shutil.copyfile('config-sample.ini', '{0}/config-sample.ini'.format(DISTPATH))
shutil.copyfile('whateveryouwant.ext', '{0}/whateveryouwant.ext'.format(DISTPATH))

The final step is to run compile process

pyinstaller--clean exefilename.spec