Modern Python Projects Transcripts
Chapter: Let's build an app
Lecture: Create a Mac app with PyInstaller

Login or purchase this course to watch this video and the rest of the course contents.
0:00 Since I'm using a Mac. Let's use the pyinstaller to
0:03 Create a Mac application first. Later,
0:07 I will switch the windows and we will do the same for a Windows application.
0:12 First, make sure you have created and activated the virtual environment and that you have
0:17 run. python install.
0:21 I have done this in the previous lessons,
0:22 so I don't have to do this,
0:24 but there is no harm in running it again.
0:27 Next, we have to install pyinstaller.
0:29 The safest bet is to Install it in the same virtual environment where we keep
0:34 our application. So inside the virtual environment run pip install pyinstaller.
0:48 If you go to the pyinstaller documentation,
0:51 you will see that the basic usage is quite simple.
0:54 You just run pyinstaller command and you provide the path to your main script.
1:00 So, in our case, it's the file.
1:04 So let's try this. You will see a lot of output and it's probably going
1:18 to fail. That's because we are using pyenv and pyenv by default doesnt
1:24 install some development packages that pyinstaller requires,
1:29 but luckily we have this helpful message saying that we should rebuild our python with enable
1:35 shared on Linux or enable framework option on Mac OS.
1:40 So we have to either install one of the existing python versions or install a new
1:45 one. Using this enable framework option,
1:49 I've decided to install a new one.
1:51 And since I already have the 3.90 and 3.86 I will insult the 3.85, to install
2:15 a python version using pyenv with this enable framework we have to run command like
2:20 that. This will set the python configure options for the current command to also include
2:27 the enable framework command. So let's give it a try.
2:34 Remember, if you're on linux,
2:35 just replace enable framework with enable-shared.
2:41 Now that we have this new python version,
2:43 we have to switch to using it and recreate our virtual environment and reinstall all the
2:49 packages again. Let's run pyinstaller again.
3:16 This time it should work, no errors,
3:22 That's a good sign. So now if we look inside our current folder,
3:27 you will see that we have two new folders.
3:31 We have the build folder where all the building happens and we have the disk folder
3:36 that contains our application. pyinstaller has also created this gui.spec file where
3:43 we can specify some options for building,
3:46 but we're not going to touch it, first
3:49 let's go inside the build folder.
3:55 There is a bunch of files that pyinstaller is using when building your application.
4:00 But one file here is actually quite important.
4:03 There is this warn-gui.txt file that contains all the warnings from the build
4:09 process. In our case, we got a bunch of warnings that some optional dependencies
4:17 are missing. Hopefully, it won't cause any problems.
4:20 But if in the future you run into some problems and you can't build your application
4:24 this is the first file, that you should check before you start debugging.
4:30 Let's go back, inside that dist folder we can find the final product of pyinstaller our
4:44 python application. It's simply called gui.
4:48 Let's try to open it from Finder.
4:56 We can find it on this list because it's one of a few files in this
4:59 folder that contains the terminal icon.
5:10 It takes a few seconds, but it seems to be working.
5:15 Let's test it with some urls. Cool,
5:26 so it seems to be working fine.
5:32 One thing that I don't like by default is that we have all those files here
5:36 in this folder, that we have to include with our application. So we can rerun
5:42 pyinstaller with the --onefile option,
5:45 and it will pack all those files together into one file.
5:52 Let me first remove this dist and build folders.
5:59 And also the gui.spec, wrong folder. dist. Okay.
6:29 And now, inside dist folder,
6:31 we have a single gui binary that contains all the dependencies.
6:36 Let's give it a try. oops without the dot,
6:54 actually, with the .com. Now it's working, so we can run this
7:00 simple program on our computer, But we could actually do this even before,
7:05 So, let's test it on a brand new Mac OS operating system that shouldn't even have latest python installed.