Join us and get access to thousands of tutorials and a community of expert Pythonistas.

Unlock This Lesson

This lesson is for members only. Join us and get access to thousands of tutorials and a community of expert Pythonistas.

Unlock This Lesson

Hint: You can adjust the default video playback speed in your account settings.
Hint: You can set the default subtitles language in your account settings.
Sorry! Looks like there’s an issue with video playback 🙁 This might be due to a temporary outage or because of a configuration issue with your browser. Please see our video player troubleshooting guide to resolve the issue.

Package Your App for Windows

To learn more about the programs and imports in this lesson, check out:

00:00 You can use PyInstaller to create a Windows executable, just like you did for macOS and Linux. The only requirement is that you run the command on Windows.

00:11 First, you need to install PyInstaller.

00:35 The following command will package your application. This command will create a Windows executable and several other files.

01:14 In the folder, you’ll find another folder named after the project file—in this case, calculator. In there, you’ll see in large number of files—including an executable file, again called calculator. In this case, however, you may well find that the default build by PyInstaller doesn’t work correctly, and you’ll have an application which opens and closes instantly.

01:39 The logs are located in a .kivy\ folder in your Windows user folder, which is typically on your C drive. If you take a look at the log of the failing application, you may see a warning about an inability to find a valid Window provider.

01:54 This is because there’s some tweaking needed of the PyInstaller spec file which is created when you make a project. This allows fine tuning of PyInstaller’s operation, allowing you to customize the files which are included with the distributed application.

02:10 You’ll need to edit the calculator.spec file. On-screen, you’ll see this done using nano in Windows Terminal. You need to add the needed imports at the top of the file … followed by the code that will allow these imports to be collected into the completed PyInstaller version of the application.

02:47 Once you’ve finished editing, if you’re using nano, you can save the file with Control and O and exit with Control and X. You can now rerun PyInstaller, but this time, you direct it to the spec file, not the Python file you used earlier.

03:04 Note that you no longer need to use the -w switch, as the spec file already has details of how you configured the output of PyInstaller. You’ll need to confirm that you want to delete the original files with Y and Enter.

03:20 You can now run the calculator.exe file again, and this time it should work as seen on-screen. If you’d rather have PyInstaller create a single executable file, then you can pass in the --onefile argument in addition to -w, as seen on-screen.

04:21 You’ll need to perform similar edits to the ones previously seen to enable the import of SDL2 and GLEW.

04:54 Once you’ve made the needed changes, run PyInstaller again, once more pointing it at the spec file rather than the Python file.

05:20 As you can see on-screen, there’s now a single file which is the entire application, which can easily be distributed. In the next section of the course, you’ll take a look at packaging your app for Android.

Become a Member to join the conversation.