import PyInstaller.__main__ PyInstaller.__main__.run([ 'my_script.py', '--onefile', '--windowed' ]) # is equivalent to # pyinstaller my_script.py --onefile --windowed