简体   繁体   English

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

[英]How to install PyQt4 on Windows using pip?

I'm using Python 3.4 on Windows.我在 Windows 上使用 Python 3.4。 When I run a script, it complains当我运行脚本时,它会抱怨

ImportError: No Module named 'PyQt4'

So I tried to install it, but pip install PyQt4 gives所以我尝试安装它,但是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 .尽管当我运行pip search PyQt4时它确实出现了。 I tried to pip install python-qt , which installed successfully but that didn't solve the problem.我尝试pip install python-qt ,它安装成功,但没有解决问题。

What am I doing wrong?我究竟做错了什么?

Here are Windows wheel packages built by Chris Golke - Python Windows Binary packages - PyQt这是 Chris Golke 构建的 Windows 轮包 - Python Windows 二进制包 - PyQt

In the filenames cp27 means C-python version 2.7, cp35 means 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 pip to install it - eg:确保获取正确的 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 版本,则应该正确安装。

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

pip install PyQt5

You can't use pip.你不能使用点子。 You have to download from the Riverbank website and run the installer for your version of python.您必须从 Riverbank 网站下载并运行适用于您的 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).如果您的版本没有安装,则必须为可用的安装程序之一安装 Python,或者从源代码构建(这相当复杂)。 Other answers and comments have the links.其他答案和评论有链接。

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-packages the 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.尝试启动从 virtualenv 中调用 PyQt4 的脚本的问题在于,virtualenv 没有安装 PyQt4,并且它不知道如何引用上述默认安装。 But follow these steps to copy PyQt4 into your virtualenv and things should work great.但是按照以下步骤将 PyQt4 复制到您的 virtualenv 中,一切都会很好。

Earlier PyQt .exe installers were available directly from the website download page.早期的 PyQt .exe 安装程序可直接从网站下载页面获得。 Now with the release of PyQt4.12 , installers have been deprecated.现在随着 PyQt4.12 的发布,安装程序已被弃用。 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 :可以从以下位置下载 .exe Windows 安装程序:

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

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

With current latest python 3.6.5使用当前最新的 python 3.6.5

pip3 install PyQt5

works fine工作正常

Try this for PyQt5:试试这个 PyQt5:

pip install PyQt5

Use the operating system on this link for PyQt4.将此链接上的操作系统用于 PyQt4。

Or download the supported wheel for your platform on this link.或在链接上下载适用于您的平台的支持的轮子。

Else use this link for the windows executable installer.否则, 将此链接用于 Windows 可执行安装程序。 Hopefully this helps you to install either PyQt4 or PyQt5.希望这可以帮助您安装 PyQt4 或 PyQt5。

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 

install PyQt5 for Windows 10 and python 3.5+.为 Windows 10 和 python 3.5+ 安装 PyQt5。

pip install PyQt5 pip 安装 PyQt5

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, ie 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 -点击这里查看更多版本

在此处输入图片说明

Kindly select appropriate version of PyQt4 according to your installed python version.请根据您安装的python版本选择合适的PyQt4版本。

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

pip3 install PyQt5

I am using PyCharm, and was able to install PyQt5.我正在使用 PyCharm,并且能够安装 PyQt5。

PyQt4, as well as PyQt4Enhanced and windows_whl both failed to install, I'm guessing that's because Qt4 is no longer supported. PyQt4,以及 PyQt4Enhanced 和 windows_whl 都无法安装,我猜这是因为不再支持 Qt4。

Try using python 3.6,尝试使用 python 3.6,

then install sip然后安装sip

pip install sip then follow the steps mentioned by @Jay https://stackoverflow.com/a/48078369/8352081 pip install sip然后按照@Jay 提到的步骤https://stackoverflow.com/a/48078369/8352081

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM