Pycharm+qt5+python3 Installation and Environment configuration

Source: Internet
Author: User
Tags virtualenv

Development Environment:

MAC OS 10.12.3 版本
Pycharm 2016.3.2 版本
Python 3.6.0 版本
PyQt5 5.8.1 版本
pyinstaller: Package python code as an executable EXE file.

EXE file for Windows, but this chapter does not install, but do not rule out the post-update article, because Bo Master has not been started, have not considered so much!!! "embarrassing")

Why write this blog?

The data is too little (almost complete), spent 1 full-time to configure, do not want to waste, time is money can not buy .

What do I need to install?
    • Sip
    • PyQt5
    • Qt
    • Python

Python is not installed can refer to Python version management: Pyenv and Pyenv-virtualenv

Pycharm installs itself Baidu, very simple, all the way click Next .

Sip

It means to say:
Before you build PyQt5 from source code, you must have already built and installed SIP, that is, you have to install this thing, then what is this thing?

What is SIP?

SIP is a python/c++ hybrid programming solution for PYQT developed by Riverbank (also known as the developer of PYQT). Due to the complexity of the QT framework, PYQT does not use the hybrid programming scheme of Cython and Swig, but does a separate framework for itself. SIP includes a SIP tool, SDK, and Python Module.

Similar to Swig, using SIP also requires writing a "configuration file", then "compiling" the C + + source file using the SIP tool, and finally compiling the PYQT for Python with the QT library.

Unlike Swig, sip exists as a Python module, meaning that pyqt as a Python module relies on SIP as a Python module. For Swig, once the auto-generated C + + generation is complete, the entire process is no longer dependent on swig.

Need to note:

If you have PYQT4 and PyQt5 installed, then PYQT4 and PYQT5 cannot share the SIP.
Just as Python2 and Python3 are strictly unable to share Pip, because of the difference, the solution is to configure a separate Python environment (VIRTUALENV) for each directory, which can be referenced in Python version management: Pyenv and pyenv-virtualenv.

Install SIP mode one: Pip installation

With the supported Python version, you can install SIP from PyPI by running:

pip3 install SIP

like hands-on can try the following way four , currently found online tutorials are compiled with their own way.
If the Mac can be used by the user three , but also very simple, but the Python environment is not easy to separate, not recommended.

Mode two: Pycharm installation

For patients with lazy cancer, you can use Pycharm



Method Three: Use homebrew
brew install sip

Do not know brew self-Baidu ha.

Mode four: Manually compile the installation

The choice of this way is the great God.??
When you start compiling, the next steps are best to "manually compile".


Https://sourceforge.net/projects/pyqt/files/sip/sip-4.19.1/sip-4.19.1.tar.gz
Python v3.5 and later versions for 64-bit Linux,os x and 32-bit and 64-bit Windows.

Compiling the installation steps

Tar xvf sip-4.19.1.tar.gz
CD sip-4.19.1
python3.5 configure.py-d/library/frameworks/python.framework/versions/3.5/lib/python3.5/site-packages
Make
sudo make install

Manual compilation Reference: http://www.cnblogs.com/tkinter/p/5632231.html

Install PYQT5 mode one: Pip installation

With the supported Python version, you can install SIP from PyPI by running:

pip3 install PyQt5

like hands-on can try the following way four, the current online find tutorials are compiled with their own way, haha.
If the Mac can be used by the user three , but also very simple, but the Python environment is not easy to separate, not recommended.

Mode Two: Pycharm installation method Three: Use homebrew
brew install pyqt
Mode four: Manually compile the installation


Https://www.riverbankcomputing.com/software/pyqt/download5
Https://sourceforge.net/projects/pyqt/files/PyQt5/PyQt-5.8.1/PyQt5_gpl-5.8.1.tar.gz
Binary Package
Python v3.5 and later versions are available for 64-bit Linux,os x and 32-bit and 64-bit Windows.

Manual compilation Reference: http://www.cnblogs.com/tkinter/p/5632231.html

Attention:

So far you can actually develop it, but we want a more cool development, you can drag the control directly, so you need Qtdesigner,qtdesigner is a module of QT.


Installing QT

Installation is very simple, the next step , do not configure what, the default configuration can be, we just use QT Qtdesigner executable program, and finally do not start, directly off the line.

Method One: Local installation

Http://download.qt.io/official_releases/qt/5.8/5.8.0/qt-opensource-mac-x64-clang-5.8.0.dmg
Http://download.qt.io/official_releases/qt/5.8/5.8.0/qt-opensource-linux-x64-5.8.0.run
Http://download.qt.io/official_releases/qt/5.8/5.8.0/qt-opensource-windows-x86-msvc2015_64-5.8.0.exe

This is my installation after the path, in fact, the end is to Qtdesigner

Mode two: Use homebrew
brew install qt

Installation is a command line, not a visual Click Next, I did not use this way.

Attention:

The installation needs to be installed here, the following needs to be installed in the configuration of things.

Configure Qtdesigner

Visual Drag control write UI, a word cool!

    1. Open your pycharm.


Configuration of Windows:


Image.png Configuration Pyuic

Used to convert the UI file created by Qtdesigner into a py file.



Contents of paramters Inside:

-m PyQt5.uic.pyuic  $FileName$ -o $FileNameWithoutExtension$.py
Configuration is complete.

You can see two more external tools:


How to use:

Mac do gif can only play once, do not know how, can only bitter force of a picture of the??。

Create the first PYQT project:

Open our Qtdesigner and we can write the layout.


When the designer program is started, we can drag the control.
We create window programs, select Man Window , and let click After create .

createwhen clicked, the canvas and controls appear

Drag a text-write-point content:

Save the layout file.

Select Save Path

At this point, you can see this file under the project.


But this file python does not run directly ah, what to do?
Another tool we have configured above is needed at this point PyUIC .

Select the file Right button and choose thePyUIC

This command-line tool will turn the UI file into a py file.


To start this Python file, we need to call it:

Write main.py:


The code is as follows:

import sysimport HelloWorldfrom PyQt5.QtWidgets import QApplication, QMainWindowif __name__ == ‘__main__‘: app = QApplication(sys.argv) MainWindow = QMainWindow() ui = HelloWorld.Ui_MainWindow() ui.setupUi(MainWindow) MainWindow.show() sys.exit(app.exec_())

How to run:


Operation Result:


Oh also, finally write out the first Python GUI program!



Inke
Links: https://www.jianshu.com/p/094928ac0b73
Source: Pinterest
The copyright of the book is owned by the author, and any form of reprint should be contacted by the author for authorization and attribution.

Pycharm+qt5+python3 installation and environment configuration

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.