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

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/22640640/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-19 01:20:23  来源:igfitidea点击:

How to install PyQt4 on Windows using pip?

pythonpython-3.xpyqtpyqt4pip

提问by Anna

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

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

ImportError: No Module named 'PyQt4'

So I tried to install it, but pip install PyQt4gives

所以我尝试安装它,但pip install PyQt4给出了

Could not find any downloads that satisfy the requirement PyQt4

找不到任何满足 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.

虽然它确实在我运行时出现pip search PyQt4。我试过pip install python-qt,安装成功,但没有解决问题。

What am I doing wrong?

我究竟做错了什么?

采纳答案by Ivo

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

这是 Chris Golke 构建的 Windows 轮包 - Python Windows 二进制包 - PyQt

In the filenames cp27means C-python version 2.7, cp35means python 3.5, etc.

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

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.

由于 Qt 是一个更复杂的系统,在它为您提供的 Python 接口下有一个已编译的 C++ 代码库,因此它的构建可能比纯 Python 代码包更复杂,这意味着从源代码安装它可能很困难。

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

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

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.

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

回答by James Palawaga

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

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

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

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

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

回答by Oliver

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.

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

回答by Dan

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

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

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

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

but it also leaves a file here:

但它也在这里留下了一个文件:

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

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.

如果您将 sip.pyd 和 PyQt4 文件夹都复制到您的 virtualenv 中,事情就会正常工作。

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-packagesthe file (sip.pyd) and folder (PyQt4) mentioned above to C:\code\BACKUP\Lib\site-packages\

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

Then back at CLI:

然后回到 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.

尝试启动从 virtualenv 中调用 PyQt4 的脚本的问题是 virtualenv 没有安装 PyQt4 并且它不知道如何引用上述默认安装。但是按照以下步骤将 PyQt4 复制到您的 virtualenv 中,事情应该会很好。

回答by xeon

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.

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

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

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

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

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

回答by Jay Joshi

For Windows:

对于 Windows:

download the appropriate version of the PyQt4 from here:

从这里下载适当版本的 PyQt4:

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

并使用 pip 安装它(例如 Python3.6 - 64 位)

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

回答by pierce

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

QT 不再支持 PyQt4,但您可以使用 pip 安装 PyQt5:

pip install PyQt5

回答by B-shan

If you have error while installing PyQt4.

如果您在安装 PyQt4 时遇到错误。

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

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

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.whl- click here to see more versions.

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

enter image description here

在此处输入图片说明

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

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

回答by KEYAN TECH

install PyQt5 for Windows 10 and python 3.5+.

为 Windows 10 和 python 3.5+ 安装 PyQt5。

pip install PyQt5

pip 安装 PyQt5

回答by mthecreator

You can also use this command to install PyQt5.

你也可以使用这个命令来安装 PyQt5。

pip3 install PyQt5