惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

K
Kaspersky official blog
Martin Fowler
Martin Fowler
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
V
Visual Studio Blog
博客园_首页
Engineering at Meta
Engineering at Meta
The Cloudflare Blog
MongoDB | Blog
MongoDB | Blog
Blog — PlanetScale
Blog — PlanetScale
T
The Blog of Author Tim Ferriss
雷峰网
雷峰网
D
Docker
博客园 - 司徒正美
S
SegmentFault 最新的问题
M
MIT News - Artificial intelligence
博客园 - 叶小钗
博客园 - 三生石上(FineUI控件)
U
Unit 42
J
Java Code Geeks
A
About on SuperTechFans
N
Netflix TechBlog - Medium
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
S
Security Affairs
I
Intezer
Cisco Talos Blog
Cisco Talos Blog
C
Cyber Attacks, Cyber Crime and Cyber Security
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
B
Blog RSS Feed
P
Privacy & Cybersecurity Law Blog
T
Tenable Blog
T
Threatpost
H
Hacker News: Front Page
G
Google Developers Blog
博客园 - 【当耐特】
Hugging Face - Blog
Hugging Face - Blog
Apple Machine Learning Research
Apple Machine Learning Research
L
Lohrmann on Cybersecurity
大猫的无限游戏
大猫的无限游戏
Google DeepMind News
Google DeepMind News
A
Arctic Wolf
S
Secure Thoughts
GbyAI
GbyAI
NISL@THU
NISL@THU
S
Security @ Cisco Blogs
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
Webroot Blog
Webroot Blog
C
CXSECURITY Database RSS Feed - CXSecurity.com
O
OpenAI News
Spread Privacy
Spread Privacy
Application and Cybersecurity Blog
Application and Cybersecurity Blog

老鱼的博客

DOS 内存粗解 - 老鱼的博客 Qt Quick 编译器简介 - 老鱼的博客 在 openSUSE 底下跨平台编译 mingw64 程序 激活 Python 虚拟环境 - 老鱼的博客 安装与编译最简 windows qt - 老鱼的博客 如何存储密码(KDF) - 老鱼的博客 静态编译 Qt 简单教程 - 老鱼的博客 bcache 的使用 - 老鱼的博客 Linux 下超频 Ryzen 1700 - 老鱼的博客
怎么样在 virtualenv 里面使用 PyQt - 老鱼的博客
2017-05-05 · via 老鱼的博客

怎么样在 virtualenv 里面使用 PyQt


类型:Python,C++ & Qt4,创建时间:May 5, 2017, 10:23 a.m.

标题无“转载”即原创文章,版权所有。转载请注明来源:http://hgoldfish.com/blogs/article/104/。

PyQt 现在还不支持从pip下载安装,习惯virtualenv开发的时候会比较麻烦,总不能为了一个 PyQt 就放弃了virtualenv吧。

有两种方案,一是在系统里面安装 PyQt,然后每次创建virtualenv以后,把系统的 PyQt 链接到环境的site-packages里面。这个办法 stackoverflow 里面有描述:

Is it possible to add PyQt4/PySide packages on a Virtualenv sandbox?

我这里还有一种麻烦一点的方法,就是从源代码安装 PyQt。其实 stackoverflow 上面也有讲,不过我做了一些改动。

How to install SIP and PyQt on a virtual environment?

Qt 是编译与安装是另外一个事情,本文就不再详述了。Linux 用户一般用包管理器安装即可,Windows用户下载 Qt 安装包搞定。

首先生成一个virtualenv,这里注意了,sip会向 python 的pysp/include/python3.5m/目录里面写入sip.h文件,所以要求 include 目录是可以写入的,默认的virtualenv做了软链接。所以命令行是这样的:

$ virtualenv -p /usr/local/bin/python3.5 --always-copy pysp
$ . pysp/bin/activate
$ pip install -r requirements.txt  # 这里安装项目的其它依赖包

第二步要安装 sip

(pysp) $ mkdir build
(pysp) $ cd build
(pysp) $ tar -xvf ~/downloads/sip-4.19.2.tar.xz
(pysp) $ cd sip-4.19.2
(pysp) $ python configure.py
(pysp) $ make -j8
(pysp) $ make install

第三步就是编译安装 PyQt 了,这里是我改动的地方。一般说来,使用 PyQt 的人只会使用QtCore,QtGui,QtWidgets几个模块,QtNetwork,QtSql,QtQuick之类的在 python 领域都有更好用的替代品,所以我们不打算编译那些不用的模块——当然,如果想用 Eric6 IDE 的话,所有的 Qt 模块都是需要编译的。编译过程大概是这样的:

(pysp) $ cd ..
(pysp) $ tar -xvf ~/downloads/PyQt_gpl-5.8.2.tar.xz
(pysp) $ cd PyQt_gpl-5.8.2
(pysp) $ python configure.py --qmake /usr/bin/qmake-qt5 --no-qsci-api  -e QtCore -e QtGui -e QtWidgets
(pysp) $ make -j8
(pysp) $ make install

其中关键的步骤在于执行configure.py的时候指定--no-qsci-api,告诉 pyqt 不要往系统公共目录安装 qsci 文档,反正也没啥用,使用多个-e告诉 PyQt 只安装三个模块。

好了,现在在 python 里面使用 PyQt 了。

写个简单的测试脚本看看:

import sys
from PyQt5.QtGui import *
app = QApplication(sys.argv)
w = QWidget()
w.show()
app.exec()

标题无“转载”即原创文章,版权所有。转载请注明来源:http://hgoldfish.com/blogs/article/104/。


暂时还没有任何评论。