当前位置:首页 » 行情解析 » pyqt股票分析
扩展阅读
惠丰钻石股票代码 2025-06-16 15:39:43
湖南电化科技股票多少钱 2025-06-16 15:30:08

pyqt股票分析

发布时间: 2021-04-30 09:58:43

⑴ 怎么利用python代码绘制k线图

现在几乎所有的大网站都在主要的栏目 做了防爬行的处理。 象这样的还算是简单的。 大不了你分析一下JS。 如果不想分析JS。就麻烦 些。 你安装一个pyqt,里面有一个qtbrowser, 你可以驱动这个浏览器去爬行。要几百行代码才能搞定。

⑵ 谁会在linux下编译安装pyqt4

两种方法。
第一种: 你已安装setuptools
然后easy_install pyqt4

第二种:下载pyqt4 然后解压,进入pyqt4的目录 python setup.py install

⑶ 学python可以做什么

从入门级选手到专业级选手都在做的——爬虫
用 Python 写爬虫的教程网上一抓一大把,据我所知很多初学 Python 的人都是使用它编写爬虫程序。小到抓取一个小黄图网站,大到一个互联网公司的商业应用。通过 Python 入门爬虫比较简单易学,不需要在一开始掌握太多太基础太底层的知识就可以很快上手,而且很快可以做出成果,非常适合小白一开始想做出点看得见的东西的成就感。
除了入门,爬虫也被广泛应用到一些需要数据的公司、平台和组织,通过抓取互联网上的公开数据,来实现一些商业价值是非常常见的做法。当然这些选手的爬虫就要厉害的多了,需要处理包括路由、存储、分布式计算等很多问题,与小白的抓黄图小程序,复杂度差了很多倍。
Web 程序
除了爬虫,Python 也广泛应用到了 Web 端程序,比如你现在正在使用的知乎,主站后台就是基于 Python 的 tornado 框架,豆瓣的后台也是基于 Python。除了 tornado (Tornado Web Server),Python 常用的 Web 框架还有 Flask(Welcome | Flask (A Python Microframework)),Django (The Web framework for perfectionists with deadlines) 等等。通过上述框架,你可以很方便实现一个 Web 程序,比如我认识的一些朋友,就通过 Python 自己编写了自己的博客程序,包括之前的 hu.photo,我就是通过 Flask 实现的后台(出于版权等原因,我已经停掉了这个网站)。除了上述框架,你也可以尝试自己实现一个 Web 框架。
桌面程序
Python 也有很多 UI 库,你可以很方便地完成一个 GUI 程序(话说我最开始接触编程的时候,就觉得写 GUI 好炫酷,不过搞了好久才在 VC6 搞出一个小程序,后来又辗转 Delphi、Java等,最后接触到 Python 的时候,我对 GUI 已经不感兴趣了)。Python 实现 GUI 的实例也不少,包括大名鼎鼎的 Dropbox,就是 Python 实现的服务器端和客户端程序。
人工智能(AI)与机器学习
人工智能是现在非常火的一个方向,AI热潮让Python语言的未来充满了无限的潜力。现在释放出来的几个非常有影响力的AI框架,大多是Python的实现,为什么呢?因为Python足够动态、具有足够性能,这是AI技术所需要的技术特点。比如基于Python的深度学习库、深度学习方向、机器学习方向、自然语言处理方向的一些网站基本都是通过Python来实现的。
机器学习,尤其是现在火爆的深度学习,其工具框架大都提供了Python接口。Python在科学计算领域一直有着较好的声誉,其简洁清晰的语法以及丰富的计算工具,深受此领域开发者喜爱。
早在深度学习以及Tensorflow等框架流行之前,Python中即有scikit-learn,能够很方便地完成几乎所有机器学习模型,从经典数据集下载到构建模型只需要简单的几行代码。配合Pandas、matplotlib等工具,能很简单地进行调整。
而Tensorflow、PyTorch、MXNet、Keras等深度学习框架更是极大地拓展了机器学习的可能。使用Keras编写一个手写数字识别的深度学习网络仅仅需要寥寥数十行代码,即可借助底层实现,方便地调用包括GPU在内的大量资源完成工作。
值得一提的是,无论什么框架,Python只是作为前端描述用的语言,实际计算则是通过底层的C/C++实现。由于Python能很方便地引入和使用C/C++项目和库,从而实现功能和性能上的扩展,这样的大规模计算中,让开发者更关注逻辑于数据本身,而从内存分配等繁杂工作中解放出来,是Python被广泛应用到机器学习领域的重要原因。
科学计算
Python 的开发效率很高,性能要求较高的模块可以用 C 改写,Python 调用。同时,Python 可以更高层次的抽象问题,所以在科学计算领域也非常热门。包括 scipy、numpy 等用于科学计算的第三方库的出现,更是方便了又一定数学基础,但是计算机基础一般的朋友。

⑷ mac pyqt5和pyqt4可以同时安装吗

安装PtQt4前你需准备:

Xcode (10.6.1 自带Xcode)
Qt - 我使用的是qt-mac-cocoa-opensource-4.6.2.dmg
SIP - 我使用的是sip-4.12.1.tar.gz
PyQt4 - 我使用的是PyQt-mac-gpl-snapshot-4.8.4.tar.gz
创建了一个pyqt文件夹在硬盘根目录下,并将sip-4.12.1.tar.gz和PyQt-mac-gpl-snapshot-4.8.4.tar.gz
放到其中并解压。
1。先安装qt,默认安装,这一步大部分人不会有问题,跳过。
2。接下来,打开终端(Terminal,在 Applications(应用程序)/Utilities(实用工具)/ 下),在终端输入:export VERSIONER_PYTHON_PREFER_32_BIT=yes。
3.
使用"cd 路径"命令将当前目录设为sip-4.12.1,如: cd /pyqt/sip-4.12.1/, 然后进行配置(configure)【Re-build SIP in 32bit 】在终端中执行
python configure.py --arch i386
配置(configure)完成后就开始编译,在终端中执行引用make clean(清除以前的安装信息)make
编译完成后就安装,在终端中执行引用sudo make install

在这个过程中没出现错误就是安装成功了

编译安装PyQt4,过程和上面的一样。 【Build PyQt4 in 32bit 】
在终端中使用"cd 路径"命令将当前目录设为PyQt-mac-gpl-snapshot-4.8.4,如
引用cd /Users/schi/pyqt/PyQt-mac-gpl-snapshot-4.8.4

然后进行配置(configure),在终端中执行引用python configure.py --use-arch i386
配置时会遇到引用Determining the layout of your Qt installation...
This is the GPL version of PyQt 4.6 (licensed under the GNU General Public
License) for Python 2.6.2 on darwin.

Type '2' to view the GPL v2 license.
Type '3' to view the GPL v3 license.
Type 'yes' to accept the terms of the license.
Type 'no' to decline the terms of the license.

Do you accept the terms of the license?

输入yes,再按回车就行

配置(configure)完成后就开始编译,在终端中执行
引用make cleanmake

编译比较花时间,请耐心等待。
编译完成后就安装,在终端中执行
引用sudo make install

在这个过程中没出现错误就是安装成功了

也可以在IDLE中导入PyQt4的模块,能成功导入就说明安装成功
Python代码
from PyQt4 import QtCore, QtGui
下面分析一下安装过程中可能遇到的问题:
1.问题如下
##############
ld: warning: in /Library/Frameworks/Python.framework/Python, missing required architecture x86_64 in file
Undefined symbols:
"_Py_Initialize", referenced from:
PyCustomWidgets::PyCustomWidgets(QObject*)in pluginloader.o
"_PyLong_AsVoidPtr", referenced from:
PyCustomWidgets::PyCustomWidgets(QObject*)in pluginloader.o
"_PyErr_Print", referenced from:
PyCustomWidgets::getMoleAttr(char const*, char const*)in pluginloader.o
PyCustomWidgets::getMoleAttr(char const*, char const*)in pluginloader.o
PyCustomWidgets::PyCustomWidgets(QObject*)in pluginloader.o
PyCustomWidgets::PyCustomWidgets(QObject*)in pluginloader.o
PyCustomWidgets::PyCustomWidgets(QObject*)in pluginloader.o
PyCustomWidgets::PyCustomWidgets(QObject*)in pluginloader.o
"_PyString_FromString", referenced from:
PyCustomWidgets::PyCustomWidgets(QObject*)in pluginloader.o
"_PyType_IsSubtype", referenced from:
PyCustomWidgets::PyCustomWidgets(QObject*)in pluginloader.o
"_PyMole_GetDict", referenced from:
PyCustomWidgets::PyCustomWidgets(QObject*)in pluginloader.o
"_PyObject_CallObject", referenced from:
PyCustomWidgets::PyCustomWidgets(QObject*)in pluginloader.o
"_PyObject_CallFunctionObjArgs", referenced from:
PyCustomWidgets::PyCustomWidgets(QObject*)in pluginloader.o
"_PyList_Append", referenced from:
PyCustomWidgets::PyCustomWidgets(QObject*)in pluginloader.o
"_Py_IsInitialized", referenced from:
PyCustomWidgets::PyCustomWidgets(QObject*)in pluginloader.o
"_PyDict_Next", referenced from:
PyCustomWidgets::PyCustomWidgets(QObject*)in pluginloader.o
"_PyImport_ImportMole", referenced from:
PyCustomWidgets::getMoleAttr(char const*, char const*)in pluginloader.o
PyCustomWidgets::PyCustomWidgets(QObject*)in pluginloader.o
"_PyObject_GetAttrString", referenced from:
PyCustomWidgets::getMoleAttr(char const*, char const*)in pluginloader.o
ld: symbol(s) not found
collect2: ld returned 1 exit status
make[1]: *** [libpythonplugin.dylib] Error 1
make: *** [all] Error 2
这个问题的原因就是:qt是在32位mac上编译的,但pyqt默认是在64位机子上编译的,所以我们在编译的时候要制定编译环境:是i386 还是x86_64.
请参考如下的信息:
The problem is that the Qt library is 32bit while, by default, python builds PyQt4 in 64bit. That caused problem when it tried to link 64bit object files with 32bit Qt library. To fix this issue, we need to force python to build PyQt4 in 32bit, and we also need to re-build SIP in 32bit mode. If you use the python version that comes with Mac OS (2.5 for Snow Leopard), make sure that it runs in 32bit mode by issuing the command

2.个问题如下:

>>> from PyQt4 import QtGui
Traceback (most recent call last):
File "<stdin>", line 1, in <mole>
ImportError: dlopen(/Library/Python/2.6/site-packages/PyQt4/QtGui.so, 2): Symbol not found: __
Referenced from: /Library/Python/2.6/site-packages/PyQt4/QtGui.so
Expected in: flat namespace
in /Library/Python/2.6/site-packages/PyQt4/QtGui.so

这个问题是所有的包安装都没有问题但是当导入QtGui或其他包时,总报这个问题,这个问题的原因是,当前pyqt release的包本身带的一个bug,PyQt-mac-gpl-snapshot-4.8.3, 所以你下载下个要release的包就可以了。如我下的是:PyQt-mac-gpl-snapshot-4.8.4。
下面给大家介绍一下我写的自动安装这些程序的python源码:
#!/usr/bin/env python
"""
Automated installer for Python 2.6 (final)
This installer is able to handle any previous
versions of Python.
NOTE: This file *must* be copied to
//nssgsvr/tools/pyInstall_OSX when modified!
"""
import os
import sys
import re
import shutil
import platform
import tarfile
# Constants
PYTHON_PKGS = {"dmgFile" : "python-2.6.1-macosx2008-12-06.dmg",
"mpkgList": ["MacPython.mpkg"] }
#WXPYTHON_PKGS = {"dmgFile" : "wxPython2.8-osx-unicode-2.8.9.2-universal-py2.6.dmg",
# "mpkgList": ["wxPython2.8-osx-unicode-universal-py2.6.pkg"] }
#ANGELIA
XCODE_PKGS = {"dmgFile" : None, "mpkgList": ["Xcode.mpkg"]}
QT_PKGS = {"dmgFile" : "qt-mac-cocoa-opensource-4.6.2.dmg",
"mpkgList": ["Qt.mpkg"] }
THIRD_PARTY_INSTALL = ["sip-4.12.1", "PyQt-mac-gpl-snapshot-4.8.4","Pyro-3.9.1", "pyserial-2.4"]
# Environment constants
TCSH_ENV_FILE = '/etc/csh.login'
BASH_ENV_FILE = '/etc/profile'
SCRIPTS_ROOT_ENV = "TEST_SCRIPTS_ROOT"
TARGET_VER = "2.6"
IS_POSIX = (os.name == 'posix')
IS_MAC = (sys.version.find('Apple') != -1)
IS_OSX = (IS_MAC and IS_POSIX)
IS_OSX_LEOPARD = (IS_OSX and platform.mac_ver()[0].startswith('10.5'))
IS_OSX_SNOWLEOPARD = (IS_OSX and platform.mac_ver()[0].startswith('10.6'))
# NSSGSVR Constants
MOUNT_POINT = "/Volumes/Test"
HOSTSERVER = "NSSGSVR.global.avidww.com" # Server that contains SQA scripts
SHARE = "TEST" # NSSGSVR share that contains the Python scripts directory
USER = "qatest"
PASSWD = "Cmqat/$/$/$" # slashes needed to escape special character '$'

⑸ Quant 应该学习哪些 Python 知识

1. 如果还需要Deep Learning方面的东西的话,可以考虑Theano或者Keras。这两个东西可能会用在分析新闻数据方面。不过不是很推荐使用这类方法去做量化模型,因为计算量实在是太大,成本很高。
2. 交易框架方面,除了vn.py,还推荐PyAlgoTrade框架,github上可以搜到。私以为这个框架比vn.py牛逼太多了,毕竟是一个在金融IT领域混迹近20年的老妖的作品,架构设计不是一般的优秀。
3. 国内的话,ricequant是个不错的选择,虽然使用的是Java,但是团队我见过,都是做金融IT出身的,基本上都有7、8年以上经验,底层功底非常扎实,做事情都很靠谱。现在他们也在考虑把SDK扩展到Python这边。
4. 国内的行情和交易接口,使用的是自己的协议(比如CTP接口使用的是FTD协议),而不是国际上广泛使用的FIX协议,并且都不开源。如果需要连接行情,还需要考虑将接口SDK为python封装一下。(修改:评论中有人提到很多券商也开放了FIX接口,不过似乎是在内网使用)
5. 有人谈到数据库了,这里我也说一下,对于高频tick级别的数据,其量级可以达到每天TB级别,普通的关系数据库是扛不住的。如果试图使用传统的关系数据库,比如Oracle之类的可以省省了。对付这种级别的数据,采用文件系统+内存索引会更好。不过这种场景,一般也就是机构里面能碰到了,个人quant可以不用考虑。

⑹ Python培训哪里最好

相信在IT领域发展的同学对Java很熟悉。Python编程语言排行中一直处于领先地位,这可以直接体现Python的重要。因此很多同学准备参加Python培训机构系统学习。那么,Python培训机构哪家比较好?下面我们介绍一下。

随着Python普及,越来越多的人了解py,企业也会对求职者提出更高的要求,他们想招聘一些能马上开始工作的人,所以往往会招聘一些有项目开发经验的人。这就是为什么那么多计算机专业的大学生找不到工作,所以越来越多的大学生会选择在毕业前后参加一些专业的Python培训课程,以增加他们的实践经验。只有增强自己的力量,才能立于不败之地。

Python培训机构哪家比较好?判断Python培训机构好与坏主要看以下几个方面

1.看教学课程内容

学习Java技术,最主要是与时俱进,掌握的技术点能够满足时下企业的用人需求。而想要了解一家培训机构所提供的课程是否新颖,也可以去机构的官网上看看,了解自己想学习的学科的课程大纲。看看学习路线图是如何安排的,有没有从零到一的系统搭建,是不是有强化实训、实操的比重,有尽量多的项目实战。因为企业对Java从业者的技术能力和动手实战能力要求较高。

2.看师资力量

因为Java开发技术知识的专业性很强,如果盲目去学很容易走进误区。相反,有讲师带领,站在巨人的肩膀上,往往事半功倍。毕竟现在这个时代只要多跟别人交流才能获得更多更有价值的信息,初学者千万不能闭门造车。

3.看口碑

行业内口碑比较好,学生对培训机构比较认可,这种机构把精力放在了学生身上的机构,才是做教育的应有态度。

4.看就业情况

以学生就业为目标的培训机构现在才是最主要的。要知道就业也是教学成果的体现,没有好的教学保证是做不到好的就业的。

5.上门免费试听

试听是为了更好的去感受培训机构的课程内容、讲课风格、班级氛围等,同时也能通过和班上在读同学进行交流,更进一步去了解这家培训机构各个方面是否符合自己的需要。

⑺ Python String和PyQt QString的区别

以下在python2.5和PyQt4.4.6 for python2.5环境下讨论。

在python中有两种与字符有关的类型:string object和Unicode object。

平时进行输入输出的一般都用string
object,当需要显示一些特殊字符或者中文等文字时候,需要转换为Unicode编码。在PyQt中也有两种字符类型与上面两者对应:QByteArray和QString,主要是使用QString操作数据。

1) python string
object可以理解为一个接一个字节的字节组,至于表示什么编码,与表示文字有关,比如“python
string”,“中文”。注意它是有不同编码区分的。

PyQt中与之对应的是QbyteArray,而不是Qstring。

A built-in string object (plain or Unicode) is a sequence of
characters used to store and represent text-based information
(plain strings are also sometimes used to store and represent
arbitrary sequences of binary bytes). (摘自《Python in a
NutShell》)

QByteArray can be used to store both raw bytes (including '"0's)
and traditional 8-bit '"0'-terminated.(摘自《PyQt手册》)

2)Python Unicode
object可以理解为固定使用utf-16编码的字节组,其中英文和中文都使用两个字节(16位)来表示,如:u"Python
Unicode object"、u"中文"。
PyQt中与之对应的就是QString了。

Unicode string literals have the same syntax as other string
literals, with a u or U immediately before the leading quote.
(摘自《Python in a NutShell》)

Qt also provides the QString class to store string data. It stores
16-bit Unicode characters, making it easy to store
non-ASCII/non-Latin-1 characters in your
application.(摘自《PyQt手册》)
QString stores a string of 16-bit QChars, where each QChar
corresponds one Unicode 4.0 character.(摘自《PyQt手册》)

2 PyQt内部类型转换

QString有
toAscii()、toUtf8()函数转换为QByteArray类型,(这个基本不用,因为很少直接用QByteArray类型)有__init__
(self, QByteArray a)函数将QByteArray类型转为QString。

3. Python string object和Python Unicode object相互转换

1)Python string object是原始编码是有区分的,通过 decode('原始编码')
函数解码得到通用utf16编码即Python Unicode object。
>>>"python
string".decode('ascii')
或者
>>>"python
string".decode()
得到 u"python string"
因为默认按ascii解码。
>>>"中文".decode('gbk')
得到 u""u4e2d"u6587" ,打印出来就是 中文 二字。(注意结果是2字节一组,共两组,对应两个汉字)
又:"python string".decode('gkb') ,即按汉字来解码,也可以得到 u"python
string",因为gbk编码也支持英文字母;
但是"中文".decode('ascii') 即按ascii解码是错误的,因为ascii编码不支持汉字!

>>>
"dfdf".decode()
u'dfdf'
>>>
"dfdf".decode("ascii")
u'dfdf'
>>>
"dfdf".decode("gbk")
u'dfdf'
>>>
"中文".decode("gbk")
u'"u4e2d"u6587'
>>>print
"中文".decode("gbk")
中文
>>>
"中文".decode("gb2312")
u'"u4e2d"u6587'
>>>
"中文".decode("ascii")
Traceback (most recent call last):
File "<interactive input>", line 1,
in <mole>
UnicodeDecodeError: 'ascii' codec can't decode byte 0xd6 in
position 0: ordinal not in range(128)

2)Python Unicode object原始编码固定是utf16,通过 encode('目的编码') 编码来得到Python
string object。
>>>u"unicode
string".encode()
或者
>>>u"unicode
string".encode('ascii')
得到
'unicode string',默认目的编码为ascii。
>>>u"中文".encode("gbk")
得到'"xd4"xd0"xce"xc4',打印出来就是 中文。(注意结果是1字节一组,共4组)

>>>
u"sdff".encode()
'sdff'
>>>
u"sdff".encode('ascii')
'sdff'
>>>
u"sdff".encode('gbk')
'sdff'
>>>
u"sdff".encode('gb2312')
'sdff'
>>>
u"中文".encode('gbk')
'"xd6"xd0"xce"xc4'
>>> print
u"中文".encode('gbk')
中文
>>>
u"中文".encode('ascii')
Traceback (most recent call last):
File "<stdin>", line 1, in
<mole>
UnicodeEncodeError: 'ascii' codec can't encode characters in
position 0-1: ordin
al not in range(128)
注意:执行>>>
u"中文".encode('gbk')命令需要你的IDE支持gbk编码,在官方shell下执行肯定没问题,但如果你的IDE比如PyWin中文输入异常,则可能报错。

4. Python string object和Python Unicode object向QString的转换。

Qt一般不直接操作QByteArray,只需关注Python string object和Python Unicode
object向QString的转换。
很多关于PyQt4的英文书籍说:PyQt函数需要QString参数的地方都可以直接用Python string
object或者Python Unicode object,如果非要转换可以直接用QtCore.QString()构造。比如《GUI
Programming with PyQt》,再如《PyQt手册》:

Whenever PyQt expects a QString as a function argument, a Python
string object or a Python Unicode object can be provided instead,
and PyQt will do the necessary conversion automatically.

You may also manually convert Python string and Unicode objects to
QString instances by using the QString constructor as demonstrated
in the following code fragment:

qs1 = QtCore.QString("Converted Python string object")
qs2 = QtCore.QString(u"Converted Python Unicode object")

但可惜这只适用于英文即ascii编码,对于中文则行不通!

直接的QString:
>>>
QtCore.QString('中文')
PyQt4.QtCore.QString(u'"xd6"xd0"xce"xc4')
>>> print
QtCore.QString('中文')
Traceback (most recent call last):
File "<stdin>", line 1, in
<mole>
UnicodeEncodeError: 'ascii' codec can't encode characters in
position 0-3: ordin
al not in range(128)
>>>
>>>
QtCore.QString(u'中文')
PyQt4.QtCore.QString(u'"u4e2d"u6587')
>>> print
QtCore.QString(u'中文')
Traceback (most recent call last):
File "<stdin>", line 1, in
<mole>
UnicodeEncodeError: 'ascii' codec can't encode characters in
position 0-1: ordin
al not in range(128)
>>>
因为它们都是默认按ascii编码转换!

GUI编程:
可以创建一个QTextEdit对象myTextEdit, 检验:
myTextEdit.append("中文")
或者
myTextEdit.append(u"中文")
或者
myTextEdit.append(QtCore.QString('中文'))
或者
myTextEdit.append(QtCore.QString(u'中文'))
你会发现显示都是乱码...因为它们都是默认按ascii编码进行内部转换得到QString相应utf16编码的。

解决方法是:
利用unicode()函数显示指定gb2312编码进行中文编码转换,转换后的Python Unicode
object则是可以直接作为QString参数代入用的:

>>> unicode('中文',
'gb2312', 'ignore')
u'"u4e2d"u6587'
>>> print
unicode('中文', 'gb2312', 'ignore')
中文
>>>

myTextEdit.append(unicode('中文', 'gb2312', 'ignore'))
#用以替代myTextEdit.append(u"中文")
或者多此一举下:
myTextEdit.append(QtCore.QString(unicode('中文', 'gb2312',
'ignore')))
#用以替代myTextEdit.append(QtCore.QString(u'中文'))

5. QString向Python string object和Python Unicode object的转换。

Python中需要用Python string object和Python Unicode
object的地方可就不一定可以直接用QString了!!!
QString向Python string object转换可以理解,因为编码不同。
QString向Python Unicode object的转换?需要转换吗?不都是utf16编码吗?
QString是tuf16编码,但是它的实现并非Python Unicode
object那样直接的utf16码,而实际是一个QChar串,每个QChar才对应unicode符,所以地位相当但并不相同。
许多英文书籍写到:可以使用str()函数直接将QString转换为Python string
object,可以使用unicode()直接将QString转换为Python Unicode
object。如《PyQt手册》:

In order to convert a QString to a Python string object use the
Python str() builtin. Applying str() to a null QString and an empty
QString both result in an empty Python string object.

In order to convert a QString to a Python Unicode object use the
Python unicode() builtin. Applying unicode() to a null QString and
an empty QString both result in an empty Python Unicode
object.

但同样只适用于英文,具体见下面分别分析。
1)QString向Python Unicode object的转换。
>>> from PyQt4 import
QtGui, QtCore
>>>
unicode(QtCore.QString('def'))
u'def'
>>> print
unicode(QtCore.QString('def'))
def

对于中文,unicode()必须要指定编码后有效。(这样也只针对直接的QString有效?对于Qt
GUI编程中,从QWidget取得的QString无效?)

>>> from PyQt4 import
QtGui, QtCore
>>>
unicode(QtCore.QString('中文'))
u'"xd6"xd0"xce"xc4'
>>> print
unicode(QtCore.QString('中文'))
Traceback (most recent call last):
File "<stdin>", line 1, in
<mole>
UnicodeEncodeError: 'gbk' codec can't encode character u'"xd6' in
position 0: il
legal multibyte sequence

指定原始编码后:
>>>
unicode(QtCore.QString('中文'),'gbk','ignore')
u'"u4e2d"u6587'
>>> print
unicode(QtCore.QString('中文'),'gbk','ignore')
中文 TEST

⑻ pyqt4支持python2.7吗

支持的
首先安装python-2.7.6.amd64.msi,具体的配置步骤这里就不细说了,网络一下就解决了。
紧接着就是安装pycharm-professional-4.0.4.exe,这是一个python编辑器,比官方的编辑器好用得多,可以自动代码补全,还能调试运行,功能非常丰富!
再跟着就是安装PyQt4-4.11.2-gpl-Py2.7-Qt4.8.6-x64.exe,其实pyqt与C++的qt差不多的,用法都非常相似!
接着安装cx_Freeze-4.3.3.win-amd64-py2.7.msi,这个是用来打包Python程序为exe运行文件来用的,当然你也可以用其他的打包工具,但是我极力推荐这个。
最后要安装chardet-1.0.1-py2.5.egg.rar,这个是跟Python对文件的编码检测的一个开发包,网络一下就有地方下载了,python对文本处理非常强大,有它非常方便!
磨刀不误砍柴工,正式开工:
用pyqt4的界面设计工具–qt设计师,进行界面开发如下图:

pyqt4的界面设计工具非常简单易用,只要你用别的软件进行过控件开发,那么这个自然就会了!

如果还不明白就可以看“PyQt4 精彩实例分析(语法高亮带书签).pdf”,里面包含了很多示例。

界面设计完成后,保存得到以ui为后缀的文件,我的为“mainText.ui”,“configText.ui”两个文件,有了界面文件就要转换成Python能调用的包,具体转换的方法看“PyQt4

精彩实例分析(语法高亮带书签).pdf”中的示例。我的是分别转换成两个文件“ConfigText.py”,“SuperProcessText.py”。
至此开始正式编码的工作,主窗口运行文件是superTextProcessTool.py,配置窗口的运行文件是ConfigTextTool.py。
对于文件编码转换,控件之间如何调用,如何处理消息,都有了完整的示例,界面是仿照网上的一个软件做出来的-“超级文本处理工具”做出来的。如果碰到不懂的函数,那么可以查看“PyQt4.chm”,它包含了Pytqt4所有的函数说明!

⑼ 能同时安装pyqt4和pyqt5吗

安装PtQt4前你需准备:

Xcode (10.6.1 自带Xcode)
Qt - 我使用的是qt-mac-cocoa-opensource-4.6.2.dmg
SIP - 我使用的是sip-4.12.1.tar.gz
PyQt4 - 我使用的是PyQt-mac-gpl-snapshot-4.8.4.tar.gz
创建了一个pyqt文件夹在硬盘根目录下,并将sip-4.12.1.tar.gz和PyQt-mac-gpl-snapshot-4.8.4.tar.gz
放到其中并解压。
1。先安装qt,默认安装,这一步大部分人不会有问题,跳过。
2。接下来,打开终端(Terminal,在 Applications(应用程序)/Utilities(实用工具)/ 下),在终端输入:export VERSIONER_PYTHON_PREFER_32_BIT=yes。
3.
使用"cd 路径"命令将当前目录设为sip-4.12.1,如: cd /pyqt/sip-4.12.1/, 然后进行配置(configure)【Re-build SIP in 32bit 】在终端中执行
python configure.py --arch i386
配置(configure)完成后就开始编译,在终端中执行引用make clean(清除以前的安装信息)make
编译完成后就安装,在终端中执行引用sudo make install

在这个过程中没出现错误就是安装成功了

编译安装PyQt4,过程和上面的一样。 【Build PyQt4 in 32bit 】
在终端中使用"cd 路径"命令将当前目录设为PyQt-mac-gpl-snapshot-4.8.4,如
引用cd /Users/schi/pyqt/PyQt-mac-gpl-snapshot-4.8.4

然后进行配置(configure),在终端中执行引用python configure.py --use-arch i386
配置时会遇到引用Determining the layout of your Qt installation...
This is the GPL version of PyQt 4.6 (licensed under the GNU General Public
License) for Python 2.6.2 on darwin.

Type '2' to view the GPL v2 license.
Type '3' to view the GPL v3 license.
Type 'yes' to accept the terms of the license.
Type 'no' to decline the terms of the license.

Do you accept the terms of the license?

输入yes,再按回车就行

配置(configure)完成后就开始编译,在终端中执行
引用make cleanmake

编译比较花时间,请耐心等待。
编译完成后就安装,在终端中执行
引用sudo make install

在这个过程中没出现错误就是安装成功了

也可以在IDLE中导入PyQt4的模块,能成功导入就说明安装成功
Python代码
from PyQt4 import QtCore, QtGui
下面分析一下安装过程中可能遇到的问题:
1.问题如下
##############
ld: warning: in /Library/Frameworks/Python.framework/Python, missing required architecture x86_64 in file
Undefined symbols:
"_Py_Initialize", referenced from:
PyCustomWidgets::PyCustomWidgets(QObject*)in pluginloader.o
"_PyLong_AsVoidPtr", referenced from:
PyCustomWidgets::PyCustomWidgets(QObject*)in pluginloader.o
"_PyErr_Print", referenced from:
PyCustomWidgets::getMoleAttr(char const*, char const*)in pluginloader.o
PyCustomWidgets::getMoleAttr(char const*, char const*)in pluginloader.o
PyCustomWidgets::PyCustomWidgets(QObject*)in pluginloader.o
PyCustomWidgets::PyCustomWidgets(QObject*)in pluginloader.o
PyCustomWidgets::PyCustomWidgets(QObject*)in pluginloader.o
PyCustomWidgets::PyCustomWidgets(QObject*)in pluginloader.o
"_PyString_FromString", referenced from:
PyCustomWidgets::PyCustomWidgets(QObject*)in pluginloader.o
"_PyType_IsSubtype", referenced from:
PyCustomWidgets::PyCustomWidgets(QObject*)in pluginloader.o
"_PyMole_GetDict", referenced from:
PyCustomWidgets::PyCustomWidgets(QObject*)in pluginloader.o
"_PyObject_CallObject", referenced from:
PyCustomWidgets::PyCustomWidgets(QObject*)in pluginloader.o
"_PyObject_CallFunctionObjArgs", referenced from:
PyCustomWidgets::PyCustomWidgets(QObject*)in pluginloader.o
"_PyList_Append", referenced from:
PyCustomWidgets::PyCustomWidgets(QObject*)in pluginloader.o
"_Py_IsInitialized", referenced from:
PyCustomWidgets::PyCustomWidgets(QObject*)in pluginloader.o
"_PyDict_Next", referenced from:
PyCustomWidgets::PyCustomWidgets(QObject*)in pluginloader.o
"_PyImport_ImportMole", referenced from:
PyCustomWidgets::getMoleAttr(char const*, char const*)in pluginloader.o
PyCustomWidgets::PyCustomWidgets(QObject*)in pluginloader.o
"_PyObject_GetAttrString", referenced from:
PyCustomWidgets::getMoleAttr(char const*, char const*)in pluginloader.o
ld: symbol(s) not found
collect2: ld returned 1 exit status
make[1]: *** [libpythonplugin.dylib] Error 1
make: *** [all] Error 2
这个问题的原因就是:qt是在32位mac上编译的,但pyqt默认是在64位机子上编译的,所以我们在编译的时候要制定编译环境:是i386 还是x86_64.
请参考如下的信息:
The problem is that the Qt library is 32bit while, by default, python builds PyQt4 in 64bit. That caused problem when it tried to link 64bit object files with 32bit Qt library. To fix this issue, we need to force python to build PyQt4 in 32bit, and we also need to re-build SIP in 32bit mode. If you use the python version that comes with Mac OS (2.5 for Snow Leopard), make sure that it runs in 32bit mode by issuing the command

2.个问题如下:

>>> from PyQt4 import QtGui
Traceback (most recent call last):
File "<stdin>", line 1, in <mole>
ImportError: dlopen(/Library/Python/2.6/site-packages/PyQt4/QtGui.so, 2): Symbol not found: __
Referenced from: /Library/Python/2.6/site-packages/PyQt4/QtGui.so
Expected in: flat namespace
in /Library/Python/2.6/site-packages/PyQt4/QtGui.so

这个问题是所有的包安装都没有问题但是当导入QtGui或其他包时,总报这个问题,这个问题的原因是,当前pyqt release的包本身带的一个bug,PyQt-mac-gpl-snapshot-4.8.3, 所以你下载下个要release的包就可以了。如我下的是:PyQt-mac-gpl-snapshot-4.8.4。
下面给大家介绍一下我写的自动安装这些程序的python源码:
#!/usr/bin/env python
"""
Automated installer for Python 2.6 (final)
This installer is able to handle any previous
versions of Python.
NOTE: This file *must* be copied to
//nssgsvr/tools/pyInstall_OSX when modified!
"""
import os
import sys
import re
import shutil
import platform
import tarfile
# Constants
PYTHON_PKGS = {"dmgFile" : "python-2.6.1-macosx2008-12-06.dmg",
"mpkgList": ["MacPython.mpkg"] }
#WXPYTHON_PKGS = {"dmgFile" : "wxPython2.8-osx-unicode-2.8.9.2-universal-py2.6.dmg",
# "mpkgList": ["wxPython2.8-osx-unicode-universal-py2.6.pkg"] }
#ANGELIA
XCODE_PKGS = {"dmgFile" : None, "mpkgList": ["Xcode.mpkg"]}
QT_PKGS = {"dmgFile" : "qt-mac-cocoa-opensource-4.6.2.dmg",
"mpkgList": ["Qt.mpkg"] }
THIRD_PARTY_INSTALL = ["sip-4.12.1", "PyQt-mac-gpl-snapshot-4.8.4","Pyro-3.9.1", "pyserial-2.4"]
# Environment constants
TCSH_ENV_FILE = '/etc/csh.login'
BASH_ENV_FILE = '/etc/profile'
SCRIPTS_ROOT_ENV = "TEST_SCRIPTS_ROOT"
TARGET_VER = "2.6"
IS_POSIX = (os.name == 'posix')
IS_MAC = (sys.version.find('Apple') != -1)
IS_OSX = (IS_MAC and IS_POSIX)
IS_OSX_LEOPARD = (IS_OSX and platform.mac_ver()[0].startswith('10.5'))
IS_OSX_SNOWLEOPARD = (IS_OSX and platform.mac_ver()[0].startswith('10.6'))
# NSSGSVR Constants
MOUNT_POINT = "/Volumes/Test"
HOSTSERVER = "NSSGSVR.global.avidww.com" # Server that contains SQA scripts
SHARE = "TEST" # NSSGSVR share that contains the Python scripts directory
USER = "qatest"
PASSWD = "Cmqat/$/$/$" # slashes needed to escape special character '$'