Apparently this is an open request for pyinstaller
, but hasn't happened in the past two years.
My workaround for this one was to create a shortcut one folder higher than the .exe
folder with all the files.
The difficult part here is to set up the shortcut to work in all PCs. I did two things in the shortcut properties.
- Delete the "Starts in:" path
- Set as the "Target":
"%windir%\system32\cmd.exe" /c start "" "%CD%\YourFolder\YourEXE.exe"
The second one calls a command line and launches your exe with a relative path. I have only tested it with windows 7. The downside is that this becomes a shortcut to the command line and you get a console window.
A different option is to create a batch file in the one folder higher than the .exe
and call it. This shows only briefly the console window, but won't allow you to set your own icon. A sample code that launches your code:
@echo off
setlocal enabledelayedexpansion enableextensions
set CDir=%~dp0
set EXEF=%CDir%MyEXEFolder\
cd %EXEF%
start "MyCode" "MyCode.exe"
exit
Just open a notepad, add the code and save it as a .bat
file.
This answer also describes a workaround with py2exe
, but a similar approach can be used in pyinstaller
. However, I find this quite "ugly" and I am not sure if it's that easy to collect all dependencies in one folder.
There is also Relative, but I didn't want to use another program.