October DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsWindows FixRecommendedWindows errors stealing your time? Find the fix fastScan stability, cleanup and performance issues.Fix NowOctober DealsAmazon USDeal season is back - check today's better picksAmazon US: current deals, useful picks and tech finds.See Picks×
Skip to content
Redmond desk3 min

How to Make a Windows .exe from a Python Script with PyInstaller

Use PyInstaller on Windows to package a Python script as an executable. Learn the basic command, output modes, and common packaging fixes.
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Install PyInstaller in your project’s Python environment, open Command Prompt in the folder containing your script, and run pyinstaller your_program.py. This creates a Windows executable and, by default, places it with its supporting files in a dist folder. Build a Windows app on Windows: PyInstaller does not cross-compile.

Build your first executable

  1. Open the Python environment used by your project, then install or update PyInstaller with pip install -U pyinstaller. The PyInstaller manual documents installation and use.

  2. Open Command Prompt and change to the directory containing your script. For example, if the file is named your_program.py, run:

    pyinstaller your_program.py

  3. When the command finishes, look in dist for the packaged application. The default build is a folder containing the executable and its dependencies.

    Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
  4. Run the executable and test the workflows your script needs, including any files it reads or writes. A successful build command alone does not establish that the packaged program works correctly.

Choose one-folder or one-file output

Get the default one-folder build working first. The PyInstaller manual describes it as easier to debug because the collected files are visible; switch to one-file only if handing off a single executable is more useful than that visibility.

Mode What you distribute Practical trade-off
--onedir (default) An application folder containing the executable and supporting files. Collected files are visible, which makes missing-file problems easier to diagnose.
--onefile A single executable, with support files extracted to a temporary _MEI... directory when it starts. Startup is slower because of extraction. Related items such as a README still need to be distributed separately.

To make the one-file build, use pyinstaller --onefile your_program.py. These layout and startup trade-offs are described in the PyInstaller operating modes documentation.

Package a Windows GUI app

For a GUI program that should not show a console window, use --windowed (also called --noconsole), for example pyinstaller --windowed your_program.py. Keep the console enabled while debugging so errors remain visible. The usage documentation also describes options for Windows version resources and manifests when you need application metadata or a manifest.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Fix missing imports and files

Imports PyInstaller cannot detect

PyInstaller analyzes imports, but runtime-selected imports may not be apparent during analysis. This can happen with calls such as __import__() using variable data, importlib.import_module(), or runtime changes to sys.path. If an import works in your source environment but is missing in the packaged app, investigate hidden imports, additional search paths, hooks, and the generated .spec file. A hook can specify how PyInstaller should collect a package. See the manual’s troubleshooting guidance.

Data files and binaries

Do not assume resources used by your script will automatically be included in the bundle. Add required data files with the data-file command-line option or configure them in the spec file; the spec can also describe binaries that analysis missed. A spec file is executable Python configuration, so build only from one you trust. The spec-file documentation explains how to configure collected files.

Resource paths at runtime

Paths that work in your source tree may not work after freezing. PyInstaller sets sys.frozen and sys._MEIPASS; sys._MEIPASS points inside the one-folder bundle or to the temporary extraction directory in one-file mode. sys.executable identifies the executable the user launched, while sys.argv[0] can be relative or depend on how the app was launched. Use these documented attributes when locating resources or launching subprocesses instead of assuming the current working directory is your source folder. Details are in the manual’s runtime information section.

Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Build for the target operating system

PyInstaller is not a cross-compiler: build a Windows executable on Windows, a Linux application on Linux, and a macOS application on macOS. The manual identifies Windows, macOS, and Linux as tested platforms. It notes successful use on some other operating systems but does not provide CI testing or guarantees for them. See the platform and installation information in the manual.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

PyInstaller bundles the active Python interpreter and detected dependencies, so end users generally do not need to install Python separately. It does not bundle system libraries that the target operating system is expected to provide. When practical, test on a clean machine matching the target system, particularly if the program uses native libraries.

For one-file builds, the manual also notes that file attributes are not preserved. If executable permissions or other metadata matter for files in your package, check those properties in the delivered build.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

Leave a Reply

Your email address will not be published. Required fields are marked *

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

More from the Wire

  1. World desk4 min
    How to Spot an AI Voice Scam Before Sending MoneyDon’t rely on how a caller sounds. Pause, call back through a known number, and verify the emergency with another trusted person before sending money.
  2. Mountain View desk4 min
    Google’s SynthID Detector: How to Check AI-Generated Images, Video and AudioGoogle’s SynthID Detector looks for an embedded watermark in supported images, video and audio. Here is what its results do—and do not—show.
  3. Redmond desk20 min
    How to create a link to File or Folder in Windows 11Windows 11 gives you several ways to point to a file or folder without moving or duplicating it. You can create a desktop shortcut,…
Recommended PC Tool
Recommended PC Tool
Crashes, No Sound, or Screen Glitches?Free driver scan
Windows Errors? Fix Them Before They SpreadFree repair scan

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.