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

推荐订阅源

N
News | PayPal Newsroom
Security Archives - TechRepublic
Security Archives - TechRepublic
Hacker News: Ask HN
Hacker News: Ask HN
H
Hacker News: Front Page
Apple Machine Learning Research
Apple Machine Learning Research
TaoSecurity Blog
TaoSecurity Blog
Help Net Security
Help Net Security
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
V
V2EX
Hugging Face - Blog
Hugging Face - Blog
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
人人都是产品经理
人人都是产品经理
博客园 - 三生石上(FineUI控件)
Security Latest
Security Latest
Cloudbric
Cloudbric
WordPress大学
WordPress大学
S
SegmentFault 最新的问题
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
www.infosecurity-magazine.com
www.infosecurity-magazine.com
Know Your Adversary
Know Your Adversary
A
Arctic Wolf
L
LangChain Blog
Application and Cybersecurity Blog
Application and Cybersecurity Blog
The GitHub Blog
The GitHub Blog
P
Proofpoint News Feed
W
WeLiveSecurity
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
M
MIT News - Artificial intelligence
Google DeepMind News
Google DeepMind News
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
The Cloudflare Blog
小众软件
小众软件
NISL@THU
NISL@THU
云风的 BLOG
云风的 BLOG
P
Privacy & Cybersecurity Law Blog
S
Security @ Cisco Blogs
博客园 - 【当耐特】
I
InfoQ
Vercel News
Vercel News
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
P
Proofpoint News Feed
O
OpenAI News
Google DeepMind News
Google DeepMind News
N
News and Events Feed by Topic
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
K
Kaspersky official blog
T
Threat Research - Cisco Blogs
量子位
宝玉的分享
宝玉的分享

老鱼的博客

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/。


暂时还没有任何评论。