1 Project Description

In order to alleviate the girl’s work in the processing of Excel, written in Python several processing XLSX code, respectively complete some independent tasks, such as judging the future of the day according to the attendance record, late, early leave list, the realization of two complex XLSX file cell comparison, etc.. But the girl is a liberal arts student, so it’s still extremely unfriendly to just provide py code and call it from the command line. So I hope to improve this time, mainly to achieve three goals: function integration, provide GUI, packaging into exe.

Still using Python, after some research I decided to use PyQt for GUI development.

2 the installation

I’m a MAC native and have always felt that MAC (or Linux) is more suitable for development than Windows, so the code work is still on MAC OS.

In order to use PyQt, you need to have these conditions on your MAC:

  • Xcode: If you don’t have it, install IDLE for MAC OS.
  • Qt: UI development tool;
  • SIP: connect C++ and python;
  • PyQt: Connects Python to QT.

2.1 the Xcode

This goes without saying, anyone who has developed with Xcode has probably heard of it, if not, just install one.

2.2 Qt

Go to the Qt website to download and install. If you are not sure which one to use, consider my choice.

2.3 the SIP

Download SIP, this is my choice.

After downloading, unpack and go to the directory on the command line, and execute the following code.

cd sip4.168./
python configure.py
make 
sudo make installCopy the code

2.4 PyQt4

Of course, the latest version of PyQt should be around 5.00 now, but MY needs should be satisfied by PyQT4.

Download PyQT4, which is my choice.

After downloading, unpack and go to the directory on the command line to execute the following code.

cd PyQt-mac-gpl4.114./
python configure.py
make
sudo make installCopy the code

2.5 the reference

Complete the above four steps and you should be ready to use PyQT4 on MAC OS (if you have Python installed, of course). Go into Python and try Import PyQT4. If it works, you’re good.

Additional resources for installing PyQT4 on MAC OS:

Blog.csdn.net/watsy/artic…

www.noktec.be/python/how-…

3 development

My project is hosted on Github. The Example folder contains some pyQT4 tutorial examples. My_dedear. The interface looks something like this (it’s not fun, it’s not a product, you don’t have to worry about design, just function!). The two items in the left list correspond to different tabs.

The main source of pyQT4 tutorial examples is here.

4 pack

If it’s just Python code, you need to configure the same environment to run it on someone else’s computer, so it’s best to package it as a product that someone else can run with a single file.

I use PyInstaller for project packaging and install PyInstaller on MAC OS using PIP.

sudo pip install pyinstallerCopy the code

The first line generates the intermediate file my_dedear. Spec, and the second line processes the file and completes the packaging.

pyinstaller --windowed --onefile --clean --noconfirm My_dear.py
pyinstaller --clean --noconfirm --windowed --onefile My_dear.specCopy the code

Of course, it can also be packaged into PKG or DMG format, refer to here.

But this is not the effect I want, because this is ultimately intended for girls, girls work on the desktop is Windows, so the problem of platform difference then came up, the wrong platform from the beginning, because the program developed on MAC OS can not be packaged as exe = =.

5 Surprisingly simple Windows

So I moved to the lab to develop again on Windows desktops, only to find that the Windows development process was much simpler than MAC OS. On Windows, with Python, if you want to use PyQT4, you can install a single piece of software that contains everything you need!

The download address is here, just choose exe based on your Python version and the number of bits.

The system python installation path will be selected by default during the installation process. After the installation is complete, you can run the My_dear. Py file.

For packaging under Windows, PyInstaller can also be used. Unlike MAC OS, where PyInstaller is a Python package and can be downloaded through PIP, in Windows you need to manually download the source code.

The download link is here. After downloading, unzip it. Enter the directory in CMD and use the following command to complete the packaging (copy my_dedear. Py to the directory for your convenience).

python pyinstaller.py [opts] My_dear.pyCopy the code

Opts is optional and includes:

  • -f, -onefile: package into an exe folder.
  • -d, -onedir: Create a directory containing the exe folder, but depending on many files (default);
  • -c, -console, -nowindowed: Use the console, no interface (default);
  • -w, -windowed, -noconsole: Use Windows without console.

So for my GUI, the option is -fw.

6 summarizes

In this development process, out of personal habit, I chose MAC OS as the development platform, and then I tried again on Windows because of the need to export EXE. All in all, I learned a lot from getting acquainted with the deployment and development of PyQT4 on MAC OS and Windows, and how to package PY programs with PyInstaller.

If you think the article is good, you might as well click on the lower left like ~