标签归档:pyqt4

如何使用pip在Windows上安装PyQt4?

问题:如何使用pip在Windows上安装PyQt4?

我在Windows上使用Python 3.4。当我运行脚本时,它抱怨

ImportError: No Module named 'PyQt4'

所以我尝试安装它,但是pip install PyQt4

找不到符合要求PyQt4的下载

尽管我跑步时确实会出现pip search PyQt4。我尝试pip install python-qt安装成功,但这并不能解决问题。

我究竟做错了什么?

I’m using Python 3.4 on Windows. When I run a script, it complains

ImportError: No Module named 'PyQt4'

So I tried to install it, but pip install PyQt4 gives

Could not find any downloads that satisfy the requirement PyQt4

although it does show up when I run pip search PyQt4. I tried to pip install python-qt, which installed successfully but that didn’t solve the problem.

What am I doing wrong?


回答 0

这是Chris Golke构建的Windows wheel软件包-Python Windows Binary软件包 -PyQt

在文件名中cp27表示C-python版本2.7,cp35表示python 3.5等。

由于Qt是一个更复杂的系统,它在python接口的基础上提供了已编译的C ++代码库,因此它的构建可能比仅纯python代码包要复杂得多,这意味着很难从源代码安装它。

确保获取正确的Windows wheel文件(python版本,32/64位),然后使用pip进行安装-例如:

C:\path\where\wheel\is\> pip install PyQt4-4.11.4-cp35-none-win_amd64.whl

如果您运行的是Python 3.5的x64版本,则应正确安装。

Here are Windows wheel packages built by Chris Golke – Python Windows Binary packages – PyQt

In the filenames cp27 means C-python version 2.7, cp35 means python 3.5, etc.

Since Qt is a more complicated system with a compiled C++ codebase underlying the python interface it provides you, it can be more complex to build than just a pure python code package, which means it can be hard to install it from source.

Make sure you grab the correct Windows wheel file (python version, 32/64 bit), and then use pip to install it – e.g:

C:\path\where\wheel\is\> pip install PyQt4-4.11.4-cp35-none-win_amd64.whl

Should properly install if you are running an x64 build of Python 3.5.


回答 1

QT不再支持PyQt4,但是您可以通过pip安装PyQt5:

pip install PyQt5

QT no longer supports PyQt4, but you can install PyQt5 with pip:

pip install PyQt5

回答 2

你不能使用点子。您必须从Riverbank网站下载并运行适用于您的python版本的安装程序。如果您的版本没有安装,则必须为可用的安装程序之一安装Python,或者从源代码进行构建(这涉及到)。其他答案和评论都有链接。

You can’t use pip. You have to download from the Riverbank website and run the installer for your version of python. If there is no install for your version, you will have to install Python for one of the available installers, or build from source (which is rather involved). Other answers and comments have the links.


回答 3

如果您在Windows上安装PyQt4,则默认情况下文件会在此处结束:

C:\ Python27 \ Lib \ site-packages \ PyQt4 *。*

但它还会在此处保留文件:

C:\ Python27 \ Lib \ site-packages \ sip.pyd

如果将sip.pyd和PyQt4文件夹都复制到virtualenv中,则一切正常。

例如:

mkdir c:\code
cd c:\code
virtualenv BACKUP
cd c:\code\BACKUP\scripts
activate

然后使用Windows资源管理器从C:\Python27\Lib\site-packages上述文件(sip.pyd)和文件夹(PyQt4)复制到C:\code\BACKUP\Lib\site-packages\

然后回到CLI:

cd ..                 
(c:\code\BACKUP)
python backup.py

尝试启动从virtualenv内部调用PyQt4的脚本的问题在于virtualenv没有安装PyQt4,并且不知道如何引用上述默认安装。但是,请按照以下步骤将PyQt4复制到您的virtualenv中,并且一切正常。

If you install PyQt4 on Windows, files wind up here by default:

C:\Python27\Lib\site-packages\PyQt4*.*

but it also leaves a file here:

C:\Python27\Lib\site-packages\sip.pyd

If you copy the both the sip.pyd and PyQt4 folder into your virtualenv things will work fine.

For example:

mkdir c:\code
cd c:\code
virtualenv BACKUP
cd c:\code\BACKUP\scripts
activate

Then with windows explorer copy from C:\Python27\Lib\site-packages the file (sip.pyd) and folder (PyQt4) mentioned above to C:\code\BACKUP\Lib\site-packages\

Then back at CLI:

cd ..                 
(c:\code\BACKUP)
python backup.py

The problem with trying to launch a script which calls PyQt4 from within virtualenv is that the virtualenv does not have PyQt4 installed and it doesn’t know how to reference the default installation described above. But follow these steps to copy PyQt4 into your virtualenv and things should work great.


回答 4

可以从网站下载页面直接获得较早的PyQt .exe安装程序。现在,随着PyQt4.12的发布,安装程序已被弃用。您可以通过编译它们使库以某种方式工作,但这意味着要花很多时间。

否则,您可以使用以前的发行版来解决您的目的。可以从以下网站下载.exe Windows安装程序:

https://sourceforge.net/projects/pyqt/files/PyQt4/PyQt-4.11.4/

Earlier PyQt .exe installers were available directly from the website download page. Now with the release of PyQt4.12 , installers have been deprecated. You can make the libraries work somehow by compiling them but that would mean going to great lengths of trouble.

Otherwise you can use the previous distributions to solve your purpose. The .exe windows installers can be downloaded from :

https://sourceforge.net/projects/pyqt/files/PyQt4/PyQt-4.11.4/


回答 5

看来您可能需要对PyQt4进行一些手动安装。

http://pyqt.sourceforge.net/Docs/PyQt4/installation.html

这可能会有所帮助,在教程/逐步设置格式中可能会有所帮助:

http://movingthelamppost.com/blog/html/2013/07/12/installing_pyqt____因为_it_s_too_good_for_pip_or_easy_install_.html

It looks like you may have to do a bit of manual installation for PyQt4.

http://pyqt.sourceforge.net/Docs/PyQt4/installation.html

This might help a bit more, it’s a bit more in a tutorial/set-by-step format:

http://movingthelamppost.com/blog/html/2013/07/12/installing_pyqt____because_it_s_too_good_for_pip_or_easy_install_.html


回答 6

使用当前最新的python 3.6.5

pip3 install PyQt5

工作良好

With current latest python 3.6.5

pip3 install PyQt5

works fine


回答 7

尝试使用PyQt5:

pip install PyQt5

链接上将操作系统用于PyQt4。

或在链接上为您的平台下载支持的车轮。

否则,链接可用于Windows可执行安装程序。希望这可以帮助您安装PyQt4或PyQt5。

Try this for PyQt5:

pip install PyQt5

Use the operating system on this link for PyQt4.

Or download the supported wheel for your platform on this link.

Else use this link for the windows executable installer. Hopefully this helps you to install either PyQt4 or PyQt5.


回答 8

对于Windows:

从此处下载适当版本的PyQt4:

并使用pip进行安装(Python3.6的示例-64位)

 pip install PyQt44.11.4cp36cp36mwin_amd64.whl 

For Windows:

download the appropriate version of the PyQt4 from here:

and install it using pip (example for Python3.6 – 64bit)

 pip install PyQt4‑4.11.4‑cp36‑cp36m‑win_amd64.whl 

回答 9

为Windows 10和python 3.5+安装PyQt5。

点安装PyQt5

install PyQt5 for Windows 10 and python 3.5+.

pip install PyQt5


回答 10

如果在安装PyQt4时出错。

错误:此平台不支持PyQt4-4.11.4-cp27-cp27m-win_amd64.whl。

我的系统类型是64位,但要解决这个错误我已经安装了32位Windows系统的PyQt4的,即PyQt4-4.11.4-cp27-cp27m-win32.whl点击这里查看更多版本

请根据您安装的python版本选择合适的PyQt4版本。

If you have error while installing PyQt4.

Error: PyQt4-4.11.4-cp27-cp27m-win_amd64.whl is not a supported wheel on this platform.

My system type is 64 bit, But to solve this error I have installed PyQt4 of 32 bit windows system, i.e PyQt4-4.11.4-cp27-cp27m-win32.whlclick here to see more versions.

Kindly select appropriate version of PyQt4 according to your installed python version.


回答 11

您也可以使用此命令来安装PyQt5。

pip3 install PyQt5

You can also use this command to install PyQt5.

pip3 install PyQt5

回答 12

我正在使用PyCharm,并且能够安装PyQt5。

PyQt4以及PyQt4Enhanced和windows_whl都无法安装,我猜这是因为不再支持Qt4。

I am using PyCharm, and was able to install PyQt5.

PyQt4, as well as PyQt4Enhanced and windows_whl both failed to install, I’m guessing that’s because Qt4 is no longer supported.