Intro to PyQT (The Clean Way) : Installation

PyQt is a Python wrapper for Qt Library which is used to build cross-platform GUIs.

 

There are many tutorials which help in getting started with PyQt, but they tend to make the code less clean when the project is complete. There may not be many differences in how the tutorial is.

Our priority is to keep UI development and Python logic decoupled.

I will be using Anaconda 4.4.0 and Python3.6 for this tutorial. I assume that these are already installed.

 

Let’s start by creating a Virtual environment named pyqt by using command

conda create -n pyqt anaconda python=3.6

This will create a virtual environment with all base anaconda packages installed including PyQt5

If you do not want all the base anaconda packages, create the virtual environment using

conda create -n pyqt python=3.6

Now activate the virtual environment and install PyQt by using the commands below

source activate pyqt
pip install PyQt5

This will install PyQt5 on your machine. Now check if PyQt is properly installed by using following commands inside your virtual environment.

(pyqt) :~/$ python
Python 3.6.1 | packaged by conda-forge | (default, May 23 2017, 14:16:20) 
[GCC 4.8.2 20140120 (Red Hat 4.8.2-15)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from PyQt5.QtCore import QT_VERSION_STR
>>> print(QT_VERSION_STR)
5.9.1

That’s it PyQt5 is installed in your virtual environment and we can start developing GUIs using PyQt.

In the next post we will create a basic directory structure for the project and create a simple window.

Leave a Reply

Your email address will not be published.