All you need to do is run a simple command (for this tutorial I will be using Python 3)
pip3 install pyinstaller Just head over to this link: https://developer.microsoft.com/en-us/windows/downloads/windows-10-sdk
And click the big 'Download Installer' button!
This part is pretty simple. Just running a few commands (kind of)
To start off with, you need to open a command prompt in your project directory.
Now we run the 'pyi-makespec' command. This makes a' pyinstaller' specification file which we can customize to our liking.
Assume your project structure is like this:
code_directory
|---resources
| |---project_dependencies
|---script.py
Mine is like this:
pyi-makespec script.py -n my_specfile --onefile
Open up the my_specfile.spec in a text editor of your choice.
It should look like this
Now just add this:
a = Analysis(['script.py'],
pathex=['C:\PythonProgram'],
binaries=[],
datas=get_resources(),
The datas=get_resources() is what needs to be added
Also add (just under block_cipher = none) this:
def get_resources():
data_files = []
for file_name in os.listdir('resources'):
data_files.append((os.path.join('resources', file_name), 'resources'))
return data_files
That is all we need to do for the my_specfile.spec so you can go ahead and close that.
Now run this command in the terminal:
pyinstaller my_specfile.spec
That should produce a whole lot of code
Now you might be able to run this EXE file on your computer, but if you try to run it on another it will tell you 'Unknown Publisher' and it won't run.
(during these next few commands, if any one of them asks for a password just select NONE)
To fix this we need to sign the EXE file. First (in the same directory) run this command (EXACTLY, IT IS CASE SENSITIVE):
"C:\Program Files (x86)\Windows Kits\10\bin\x64\makecert.exe" /r /h 0 /eku "1.3.6.1.5.5.7.3.3,1.3.6.1.4.1.311.10.3.13" /e 12/12/2050 /sv MyKey.pvk MyKey.cer
You just created a certificate for yourself! Now we need to convert these files to a .PFX.
Run this command EXACTLY:
"C:\Program Files (x86)\Windows Kits\10\bin\x64\pvk2pfx.exe" /pvk MyKey.pvk /spc MyKey.cer /pfx MyKey.pfx
PHEW! The hard part out of the way!!!
Now, all we need to do is run one simple command:
"C:\Program Files (x86)\Windows Kits\10\bin\x64\signtool.exe" sign /a /f MyKey.pfx PythonProgram.exe