How to remove clutter from PyInstaller one-folder build?
<p>Alright, so I managed to use PyInstaller to build a homework assignment I made with Pygame. Cool. The executable works fine and everything.</p>

<p>Problem is, alongside the executable, there is so much clutter. So many files, like pyds and dlls accompany the exe in the same directory, making it look so ugly.</p>

<p>Now, I know that these files are important; the modules I used, such as Pygame, need them to work. Still, how do I make PyInstaller build my game, so that it puts the clutter into its own folder? I could just manually make a folder and move the files in there, but it stops the exe from working.</p>

<p>If this info would help any, I used Python 3.4.3 and am on Windows.</p>

<p>Apparently this is an <a href="https://github.com/pyinstaller/pyinstaller/issues/1048" rel="nofollow">open request for <code>pyinstaller</code></a>, but hasn't happened in the past two years.</p>

<p>My workaround for this one was to create a shortcut one folder higher than the <code>.exe</code> folder with all the files.</p>

<p>The difficult part here is to set up the shortcut to work in all PCs. <a href="http://superuser.com/questions/644407/using-relative-paths-for-windows-shortcuts">I did two things in the shortcut properties</a>. </p>

<ol>
<li>Delete the "Starts in:" path</li>
<li>Set as the "Target": <code>"%windir%\system32\cmd.exe" /c start "" "%CD%\YourFolder\YourEXE.exe"</code></li>
</ol>

<p>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.</p>

<p>A different option is to create a batch file in the one folder higher than the <code>.exe</code> 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:</p>

<pre><code>@echo off
setlocal enabledelayedexpansion enableextensions
set CDir=%~dp0
set EXEF=%CDir%MyEXEFolder\
cd %EXEF%
start "MyCode" "MyCode.exe"
exit
</code></pre>

<p>Just open a notepad, add the code and save it as a <code>.bat</code> file.</p>

<p><a href="http://stackoverflow.com/a/36112722/3837382">This answer</a> also describes a workaround with <code>py2exe</code>, but a similar approach can be used in <code>pyinstaller</code>. However, I find this quite "ugly" and I am not sure if it's that easy to collect all dependencies in one folder.</p>

<p>There is also <a href="http://www.csparks.com/Relative/" rel="nofollow">Relative</a>, but I didn't want to use another program.</p>

python build pygame pyinstaller