Create a Python project with GUI on Mac

with PySide2

Make your Python projects a little bit more presentable and user-friendly by adding GUI.

Please note that this tutorial is created on top os OSX and might not work with other operating systems.

Step 1. Install all library dependencies

7zip

Install 7zip using homebrew. Run the following code in your terminal. For this part, I don’t think the version of 7zip matters.

LibClang

Download, and extractlibclang. Run the following code in your terminal. Make sure that the version of libclang you are installing is 3.9 or 4.0.

Add libclang to your Mac environment by editing your ~/.bash_profile (or ~/.bash_rc) Then source it by running source ~/.bash_profile (or source ~/.bash_rc) in your terminal.

Used vi to edit ~/.bash_profile

Xcode

Download, and install XCode via AppStore

Download Xcode via Appstore

CMake

Download cmake from here. The version I used is cmake 3.12.1. You can check the version that you have by running cmake --version in your terminal.

Make sure to drag the installer inside the Applications folder.

Continue the installation with default settings until you reach the window below, then close.

Open your terminal and run

Step 2. Create a Python virtual environment

This step is not really needed but it is really good practice to create a Python virtual environment for each of your Python projects. Check here for a step by step tutorial on how to manage different versions of Python, and create a virtual on your OSX using pyenv, virtualenv, andvirtualenv-wrapper.

Step 3. Install Qt framework using Homebrew

Run the following steps in your terminal.

Step 4. Build PySide2 from source

Clone the PySide2 repository. Git must be installed for this step.

Go inside the main project folder, and switch to your preferred PySide2 version. I will be using version 5.11

Take note of the qmakethat comes with theQt installation.

Sample qmake directory

Build, and installPySide2 from source by running the codes below. The following steps might take time to finish.

Building PySide from source

Step 5. Test if the setup is successful

Run the above code, and come up with the sample tetrix application.

Stay tuned for the Part 2 of this tutorial where I will make my own Python application with GUI.

Thanks for reading!

Sources

Python Pandemonium

A place to read and write about all things Python. If you want to become a writer for this publication then let me know.

Vivienne Encarnacion

Written by

Insights Analyst / Data Scientist

Python Pandemonium

A place to read and write about all things Python. If you want to become a writer for this publication then let me know.

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade