Podcast Lookup

Course 25 - API Python Hacking | Episode 7: Building Windows Executables from Python Scripts with PyInstaller

CyberCode Academy

  • February 28, 2026
  • 17 min
Episode page
About this episodeIn this lesson, you’ll learn about: Converting Python Scripts into Executables Installing and using PyInstaller to package Python code…
In this lesson, you’ll learn about:
  • Converting Python Scripts into Executables
    • Installing and using PyInstaller to package Python code into standalone .exe files
    • Understanding how executables allow programs to run on systems without Python installed
  • Compilation Process with PyInstaller
    • Using the command pip3 install pyinstaller to install the packaging tool
    • Running PyInstaller on a Python script to generate a Windows Portable Executable (PE) file
    • Observing how PyInstaller bundles dependencies automatically
  • Understanding the Output Structure
    • Locating the compiled executable inside the dist folder
    • Recognizing supporting files and directories generated during compilation
    • Identifying the final executable ready for deployment
  • Deployment and Distribution
    • Packaging the compiled executable into a ZIP archive for sharing
    • Uploading compiled tools to GitHub as part of a professional portfolio
    • Distributing tools to systems without requiring Python installation
  • Key Outcome
    • The ability to convert Python-based security tools into portable Windows executables for real-world deployment and professional use.


You can listen and download our episodes for free on more than 10 different platforms:
https://linktr.ee/cybercode_academy

Get the books of the CyberCode Academy podcast:
📚 The book series: 416 lessons, 12 books, hundreds of original diagrams: security, networking and programming.
https://cybercodeacademy.gumroad.com/

Transcript

From the publisher

This transcript comes from the podcast’s own feed, shown as the publisher wrote it.

Course 25 - API Python Hacking | Episode 7: Building Windows Executables from Python Scripts with PyInstaller

00:00—
  1. Speaker 1

    You know, you know that feeling when you've finally cracked a piece of code, like you've spent hours debugging, the logic is finally flowing and it just runs perfectly on your local setup. It's a really great feeling.

  2. Speaker 2

    Oh yeah, it's the absolute best feeling. The Classic works on my machine.

  3. Speaker 1

    Victory exactly, it works on my machine. But then then comes the reality check. You actually need to get that tool into the hands of someone else. Right, maybe it's a colleague in HR or an IT admin who just needs a quick fix for something, or you know, maybe you're sending it to a client, so you send them the Python script, just the standard dot.

  4. Speaker 2

    PI file and absolutely nothing happens. Nothing happens, Yeah, because they don't have Python installed, or you know, if they do, it's the wrong version entirely, or they're missing as specific library, or their path variables aren't set up. It's just classic dependency.

  5. Speaker 1

    Hell, it stops the project dead in its tracks. And that is exactly what we are deep diving into today. We are looking at the solution that portability problem. We're going to talk about taking that raw code and basically freezing it into a standalone Windows executable.

  6. Speaker 2

    Freezing is really the technical term here too. We aren't just compiling code in the traditional say C plus plus sense. We are bundling an entire.

  7. Speaker 1

    Environment, like the interpreter and everything exactly.

  8. Speaker 2

    The interpreter, all the dependencies, your script, everything, it goes into a frozen package that can run on a machine that has never even heard of Python.

  9. Speaker 1

    It's basically magic for depouring tools and to do this, today's deep dive is a step by step audio guide on using a very specific tool called pinestaller. We're going to walk you through exactly how to turn a script into a dot x file.

  10. Speaker 2

    It's the industry standard for a reason. Pine Installer handles a lot of the heavy lifting that honestly used to be a complete nightmare for developers.

  11. Speaker 1

    So let's just set the stage here. We are assuming you, the listener, are the developer in this scenario. You have your command line open, you have Python installed, and you have a script ready to go. But before we build anything, we actually need the tool itself.

  12. Speaker 2

    Right, and since we are working within the Python ecosystem, we are just grabbing this via PIP.

  13. Speaker 1

    The standard package installer.

  14. Speaker 2

    Specifically PIP three. In most modern environments, the command is super straightforward. It's just PIP three install pinstaller.

  15. Speaker 1

    Now, when you type that in, it's not an instant process. You hit enter and there's a bit of a pause.

  16. Speaker 2

    That pause is actually pretty important to understand. When you run that install command, your computer is reaching out to the Python package index. It's downloading the Pine installer wheel, but it's also checking to see if your system has the prerequisites to run pie installer itself. Oh yeah, it's resolving its own dependencies.

  17. Speaker 1

    So that roughly thirty or forty seconds of thinking time you see on the screen is actually a negotiation between your machine and the repository exactly.

  18. Speaker 2

    And there's a detail here that I think every developer has seen at least once. At the end of the installation, you get this nice success message, but you almost always get a little yellow warning text right below it, saying you should consider upgrading pip man.

  19. Speaker 1

    I feel like I see that message every single time I use the terminal.

  20. Speaker 2

    It is ubiquitous, and honestly, for the purpose of freezing a script today, you can usually just ignore it, but it is a good reminder that the ecosystem moves fast. The version of pipew and sold three months ago is already old by the repository standards.

  21. Speaker 1

    Right, So we ignore the upgrade warning for now and we see the success message pin installers now in our path. We are ready to build.

  22. Speaker 2

    We are, and for this deep dive, we aren't just going to freeze a simple Hello World script. That would be a little too easy. We're going to talk about an example file called modify underscore token underscore.

  23. Speaker 1

    Priv modify token privy that definitely sounds a bit more dangerous than Hello World.

  24. Speaker 2

    It's definitely more functional based on the name. This script is interacting with Windows access tokens. It's designed to enable or disable specific system privileges, which.

  25. Speaker 1

    Makes it a really perfect test case for us, because if you can freeze a script that interacts directly with the Windows kernel and have it still work on a completely different machine, you have really accomplished some.

  26. Speaker 2

    Exactly a print statement is easy. Modifying system tokens requires the executable to correctly handle Windows API calls. If the freezing process messes up the interface between Python and the operating system, this script will just fail.

  27. Speaker 1

    So how do we actually run the build? Because I feel like in the old days this would involve a massive configuration file or some complex makefile.

  28. Speaker 2

    And that is the beauty of pinestaller. For the basic usage, it is incredibly clean. The command is just pinestaller followed by the file name. So in our case, pines floicker, modify, underscore token, underscore.

  29. Speaker 1

    Prep, no flags, no dash, dash target Windows or anything like that.

  30. Speaker 2

    Not for the default behavior.

  31. Speaker 1

    No.

  32. Speaker 2

    Pinestaller is smart enough to look at the machine you are currently running on and build an executable for that specific OS. If you are on Windows, it builds a dot x.

  33. Speaker 1

    Okay, So we run the command and suddenly the console creates a lot of noise. You get all the scrolling texts. It's analyzing hooks, it's looking at imports, what is actually happening under the hood wh that text flies by.

  34. Speaker 2

    This is the analysis face. PI installer scans your entire script. It looks at every single import statement you wrote. If you imported AS or CIS or pandas, it makes a note of that. Then it looks at the detendencies of those libraries. It basically builds a massive graph of everything your script needs to survive.

  35. Speaker 1

    It's basically packing a suitcase for your code. It's making sure you don't forget your toothbrush. Before the trip.

  36. Speaker 2

    That's a great analogy. It's checking the weather, checking the duration of the trip, and packing everything you might possibly need. And while it does this analysis. In packing, you will actually see new folders appearing in your directory.

  37. Speaker 1

    Right, you have to watch your file explorer. You start seeing a build folder appear, and then a distfolder appears, and.

  38. Speaker 2

    A dot spec file usually pops up.

  39. Speaker 1

    Too, right, But the star of the show here is the distfolder.

  40. Speaker 2

    DIST stands for distribution. This is your output. This is the package you're eventually going to give to the end user.

  41. Speaker 1

    So let's open that up. When you open the disfolder, you don't just see a single file sitting there. Immediately you see another folder named after your script, so a folder named modify, token prove.

  42. Speaker 2

    And this is a really crucial distinction that trips up a lot of beginners. By default, pie installer uses what's called one directory mode. It creates a folder containing the executable, yes, but also all the dependencies spread out around it.

  43. Speaker 1

    Why do it that way, though, Why not just make one big file from the start.

  44. Speaker 2

    It comes down to speed and troubleshooting. When you have a folder, the executable is really just a piny launcher. When you double click it, it instantly loads the libraries sitting right next to it in that folder. If you force everything into one single file, which you can do great, Yes you can do it with a specific flag. But if you do, the computer actually have to unpack all those temporary files to a hidden system folder every single time you run the program. It makes the startup time noticeably slower.

  45. Speaker 1

    Ah, So the default one directory method is actually more efficient for the computer, even if it looks a bit messier to the human eye with all those files correct.

  46. Speaker 2

    So inside that modified token prove fall, you're going to see a lot of files things like Python thirty nine, dot DL, various library extensions, some minory data, and of course the executable itself, modified tokenpriv dot XC, the dot XC.

  47. Speaker 1

    The actual prize we were looking for is.

  48. Speaker 2

    The entry point. Think of that dot X as the front door to a house. The other files in that folder are the furniture, the plumbing, the eletricity. You absolutely need all of it for the house to function.

  49. Speaker 1

    That is a vital point and we need to stick a pin in that for later when we talk about deployment. But first we need to verify this thing actually works.

  50. Speaker 2

    Verification is key. Just because it builds successfully doesn't mean it actually runs successfully.

  51. Speaker 1

    Right, So we need a test run. We are double clicking modified tookenpriv dot sc Now, since this is a command line tool we built, does a normal graphical window pop up? No?

  52. Speaker 2

    And this is standard behavior. It opens a console window, just that black command prompt box. It's a text based interface.

  53. Speaker 1

    Okay, the window is open. How do we know it's doing its job? This script is supposed to change system privileges. We can't strictly see a privilege just by looking at the screen.

  54. Speaker 2

    We can if we know where to look. We are going to verify the token manipulation in real time by opening the Windows task manager.

  55. Speaker 1

    I love this approach. We aren't just trusting the script if it prints success, we are trusting the operating system's own monitoring tools.

  56. Speaker 2

    Exactly. We need to look for a specific privilege in the task manager details. It's called SEEDA bug privilege cee.

  57. Speaker 1

    To bug privilege. Let's unpack that for a second. What does that privilege actually do?

  58. Speaker 2

    It is a heavy hitter in the Windows environment. Cedabug privilege allows a process to inspect and even adjust the memory of other processes. It's exactly what a debugger needs to work. If you have this privilege enabled, you basically have the keys to the kingdom for any program running on that computer.

  59. Speaker 1

    So if our frozen script really works, it should be able to toggle this high level permission on and off.

  60. Speaker 2

    Right, So you open task manager, you find your specific process, and you check the status. Maybe starts out listed as disabled. You run your new executable again, effectively flipping the switch, and you watch task manager to see what happened, and it flips.

  61. Speaker 1

    It goes right from disabled to enabled.

  62. Speaker 2

    That is the moment of truth that proves two things for us. One, your logic inside the Python code actually works. But two and way more importantly for this deep dive, the frozen application successfully inherited the ability to make Windows ATI calls. The libraries you used were packed correctly by Pie installer.

  63. Speaker 1

    It works. It is totally alive.

  64. Speaker 2

    It is. But I want to throw in a quick caveat here that listeners really need to know. Sometimes when you double click a console application like this, the window pops up and then vanishes instantly.

  65. Speaker 1

    Oh man, I have had that happen so many times. It's just a quick flash on the screen and it's gone.

  66. Speaker 2

    It is incredibly frustrating. It happens because the script runs, finishes its job, and Windows immediately closes the window because the process is done. If you want to actually see the output, you often have to run the dot excess from an existing command prompt that you already opened.

  67. Speaker 1

    Or couldn't you just add a line of code at the end of your script.

  68. Speaker 2

    Yes, Adding an input statement like press enter to exit right at the very end of your Python script solves it perfectly. It pauses the script before can close.

  69. Speaker 1

    That is a fantastic tip because otherwise you might sit there thinking your brand new executable crashed, when really it just finished successfully at light speed precisely.

  70. Speaker 2

    But assuming it stays open or you verify it and task manager like we did, we now have a working tool. Now comes the part where people always mess up deployment.

  71. Speaker 1

    Yes, deployment. We have this folder sitting on our desktop. We want to give it to our friend or our it admin. Yeah, what do we actually do?

  72. Speaker 2

    The instinct, and it's a really bad instinct, is to just grab that shiny dot exit file, drag it onto a USB drive or attach it to an email and send it off.

  73. Speaker 1

    Because that's what we are used to doing. You download an installer from the internet, it's one file. You download an app, it's one icon.

  74. Speaker 2

    But remember the house analogy from earlier. If you drag just the dot X out of that folder, you are basically ripping the front door off the hinges and mailing it to your friend. When they try to open it, there is no house behind it. It will crash instantly because it can't find Python thirty nine, dot dl or any of those other dependency files.

  75. Speaker 1

    Right, So the golden rule is keep the family together always.

  76. Speaker 2

    You need to take the entire folder, the modified token prive folder that is inside the discfolder and deploy that whole thing.

  77. Speaker 1

    And the cleanest way to do that is just zipping it.

  78. Speaker 2

    Yes, creating a zip archive is standard practice. You just right click the folder and select compress to zip, or use a tool like seven zip. This bundles the executable and all its furniture into a single, highly transportable.

  79. Speaker 1

    File, and that preserves the internal structure. So when your friend downloads and unzips it, the dot aggles is still sitting right next to its required dependencies exactly.

  80. Speaker 2

    It assures all the relative paths remain perfectly intact.

  81. Speaker 1

    Now, if you want to share this publicly. Putting this zip file on GitHub is a really great move.

  82. Speaker 2

    It is excellent advice for portfolio building. Don't just upload your dot pi source code and call it a day. Upload the zipped release in the releases section of your repository.

  83. Speaker 1

    It really levels up your profile. It tells people looking at your work, I don't just write code, I build ready to use tools, and it.

  84. Speaker 2

    Creates a proper version history. You can release one point zero with the basic functionality and then later or release two point zero with new features. It shows you understand a professional software life cycle.

  85. Speaker 1

    Plus it gives people options. If I'm a fellow developer, I might want to read your Python code to see exactly how you handle the token privileges. But if I am just an IT admin who needs to fix a server right now, I just want the executable. I don't care about the code.

  86. Speaker 2

    You are serving both audiences beautifully. You're transparent with the source code for those who want it, but incredibly convenient with the binary for those who just need the tool.

  87. Speaker 1

    Now, I want to circle back to the why of this entire process. We talked about the works on my machine problem, but there's a specific scenario where this shines the locked down Windows environment.

  88. Speaker 2

    This is perhaps the most common core scenario you'll face. Imagine you are working in a highly secure environment, maybe a bank or a hospital or government contractor the computers there are locked down tight. You cannot just install Python three point DENZERI because you feel like it. You need admin rights that you simply do not have.

  89. Speaker 1

    But you can usually run a standalone executable.

  90. Speaker 2

    Often yes, or at the very least, it is significantly easier to get security approval for a single standalone tool that it is for a widespread system level installation of an interpreted language and its package manager. By freezing the code, you are completely bypassing the need for the end user to configure an environment. You are delivering the solution itself, not the prerequisites for the solution.

  91. Speaker 1

    That is a really powerful way to frame it. You are removing friction from the process.

  92. Speaker 2

    That is the core job of a developer. We solve problems. If using my solution requires you to read a ten page manual on how to install PIP and configure system path variables, I haven't really solved your problem. I have just given you a completely new set of chores to do.

  93. Speaker 1

    Freezing the code makes the solution plug and play exactly. Before we wrap up, I want to quickly ask about older systems. Is there a tool called Pie two XI that people might still run into.

  94. Speaker 2

    It's definitely a blast from the past.

  95. Speaker 1

    Yeah.

  96. Speaker 2

    If you were reading documentation from over a decade ago, or if you are unfortunate enough to be working with Python two, which has been end of life for years now, you might see references to Pie two XI.

  97. Speaker 1

    But for us living in the present day, stick.

  98. Speaker 2

    Entirely with Pie Installer. It is actively maintained. It supports all the newer versions of Python, and as we saw today, it works out of the box with zero configuration for the vast majority of scripts. There are other modern tools out there, like Nuika or tx freeze, but Pie Installer remains the quick and easy standard for very good reason.

  99. Speaker 1

    It's the path of least resistance.

  100. Speaker 2

    It truly is.

  101. Speaker 1

    So let's recap the workflow here for everyone listening. It really is a simple loop. Once you get the hang of it. Step one you install the tool with pick three, install pint ste. Step two you navigate your command line to wherever your script lives. Step three you run pinestaller followed by your file name Step four, you ignore all the scrolling terminal noise and just go find that distfolder, the most important folder exactly. Step five you verify it works, check those privileges in task manager, and finally step six you zip the entire folder, not just the file to share it.

  102. Speaker 2

    That is the exact recipe for success.

  103. Speaker 1

    It sounds so simple when you lea it out like that, but really understanding what is happening inside that disfolder it changes how you look at software distribution.

  104. Speaker 2

    It shifts your perspective entirely from just writing code to actual deployment.

  105. Speaker 1

    Now, before we sign off, I want to throw a little challenge out to you the listener. We've talked a lot about the dependencies and the DLLs living inside that directory. Here is the review question. If you successfully compile your script, but you wanted to send your friend strictly one file, just the dot x, and you still wanted it to work, Pinestaller actually allows this. We mentioned the flag briefly, but based on what we discussed about how the one directory mode works with the computer unpacking files, what do you think the trade off would be if you squashed everything into a one file mode.

  106. Speaker 2

    That is a great thing to think about. If the computer has to unpack that entire house every single time you ring the doorbell, what happens to the performance?

  107. Speaker 1

    Think about that, Why is that folder structure so important? And if you are feeling adventurous, go check the pie installer documentation for the dash dash one file flag and try it out on your own script. See if you can spot the difference in startup time yourself.

  108. Speaker 2

    It's a really great experiment to see the actual cost of convenience.

  109. Speaker 1

    Absolutely well. That wraps up our deep dive into freezing code. Hopefully this helps you get your tools into a lot more hands with a lot less headache.

  110. Speaker 2

    No more works on my machine, now it works on everyone's machine.

  111. Speaker 1

    I love it. Thanks for listening everyone, go freesome code, zip up those folders, and we will catch you on the next deep dive.

  112. Speaker 2

    Happy coading.