Python 如何在 Windows 上安装 PyQt5?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/16846501/
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-18 23:48:10  来源:igfitidea点击:

How to install PyQt5 on Windows?

pythonwindowsqtnmakepyqt5

提问by Victor Lellis

When I try installing the PyQt5 on Windows using the command

当我尝试使用命令在 Windows 上安装 PyQt5 时

python configure.py

I get this error:

我收到此错误:

Error: Make sure you have a working Qt qmake on your PATH.
Error: Make sure you have a working Qt qmake on your PATH.

I got the pyQt5 from PyQt5 Download.

我从PyQt5 Download得到了 pyQt5 。

How can I install PyQt5?

如何安装 PyQt5?



Update:

更新:

I installed Qt 5.0.2 for Windows 64-bit (VS 2012, 500 MB)from the Qt Download pageand now I have this error:

Qt 5.0.2 for Windows 64-bit (VS 2012, 500 MB)Qt 下载页面安装,现在出现此错误:

Querying qmake about your Qt installation...
Determining the details of your Qt installation...
Error: Failed to determine the detail of your Qt installation. Try again using
the --verbose flag to see more detail about the problem.
Querying qmake about your Qt installation...
Determining the details of your Qt installation...
Error: Failed to determine the detail of your Qt installation. Try again using
the --verbose flag to see more detail about the problem.

And when I execute the command python configure.py --verbose:

当我执行命令时python configure.py --verbose

Querying qmake about your Qt installation...
Determining the details of your Qt installation...
C:\Qt\Qt5.0.2.0.2\msvc2012_64\bin\qmake.exe -spec win32-msvc2008 -o qtdetail.m
k qtdetail.pro
nmake -f qtdetail.mk release
'nmake' n?o é reconhecido como um comando interno
ou externo, um programa operável ou um arquivo em lotes.
Error: Failed to determine the detail of your Qt installation. Try again using
the --verbose flag to see more detail about the problem.
Querying qmake about your Qt installation...
Determining the details of your Qt installation...
C:\Qt\Qt5.0.2.0.2\msvc2012_64\bin\qmake.exe -spec win32-msvc2008 -o qtdetail.m
k qtdetail.pro
nmake -f qtdetail.mk release
'nmake' n?o é reconhecido como um comando interno
ou externo, um programa operável ou um arquivo em lotes.
Error: Failed to determine the detail of your Qt installation. Try again using
the --verbose flag to see more detail about the problem.

I added C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\bin(contains nmake.exe) to PATH and I got this error:

我将C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\bin(包含nmake.exe)添加到 PATH 并且出现此错误:

Querying qmake about your Qt installation...
Determining the details of your Qt installation...
C:\Qt\Qt5.0.2.0.2\msvc2012_64\bin\qmake.exe -spec win32-msvc2008 -o qtdetail.mk qtdetail.pro
nmake -f qtdetail.mk release


Microsoft (R) Program Maintenance Utility Version 11.00.50727.1

Copyright (C) Microsoft Corporation.  All rights reserved.


  "C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\bin\nmake.exe" -f qtdetail.mk.Release


Microsoft (R) Program Maintenance Utility Version 11.00.50727.1

Copyright (C) Microsoft Corporation.  All rights reserved.

  cl -c -nologo -Zm200 -Zc:wchar_t -O2 -MD -GR -W3 -w34100 -w34189 -EHsc -DUNICODE -DWIN32 -DQT_NO_DEBUG -DQT_CORE_LIB -I"..\..\..\..\..\..\..\Qt\Qt5.0.2.0.2\msvc2012_64\include" -I"..\..\..\..\..\..\..\Qt\Qt5.0.2.0.2\msvc2012_64\include\QtCore" -I"release" -I"..\..\..\..\..\..\..\Qt\Qt5.0.2.0.2\msvc2012_64\mkspecs\win32-msvc2008" -Forelease\ @C:\Users\Victor\AppData\Local\Temp\nm68EA.tmp

NMAKE : fatal error U1077: '"C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\bin\cl.EXE"' : return code '0xc0000135'

Stop.

NMAKE : fatal error U1077: '"C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\bin\nmake.exe"' : return code '0x2'

Stop.
Querying qmake about your Qt installation...
Determining the details of your Qt installation...
C:\Qt\Qt5.0.2.0.2\msvc2012_64\bin\qmake.exe -spec win32-msvc2008 -o qtdetail.mk qtdetail.pro
nmake -f qtdetail.mk release


Microsoft (R) Program Maintenance Utility Version 11.00.50727.1

Copyright (C) Microsoft Corporation.  All rights reserved.


  "C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\bin\nmake.exe" -f qtdetail.mk.Release


Microsoft (R) Program Maintenance Utility Version 11.00.50727.1

Copyright (C) Microsoft Corporation.  All rights reserved.

  cl -c -nologo -Zm200 -Zc:wchar_t -O2 -MD -GR -W3 -w34100 -w34189 -EHsc -DUNICODE -DWIN32 -DQT_NO_DEBUG -DQT_CORE_LIB -I"..\..\..\..\..\..\..\Qt\Qt5.0.2.0.2\msvc2012_64\include" -I"..\..\..\..\..\..\..\Qt\Qt5.0.2.0.2\msvc2012_64\include\QtCore" -I"release" -I"..\..\..\..\..\..\..\Qt\Qt5.0.2.0.2\msvc2012_64\mkspecs\win32-msvc2008" -Forelease\ @C:\Users\Victor\AppData\Local\Temp\nm68EA.tmp

NMAKE : fatal error U1077: '"C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\bin\cl.EXE"' : return code '0xc0000135'

Stop.

NMAKE : fatal error U1077: '"C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\bin\nmake.exe"' : return code '0x2'

Stop.

采纳答案by Brett Stottlemyer

The easiest way to install PyQt is to just use the installer (Link in your answer, step #5). If you install python 3.3, the installer will add all of the PyQt5 extras to that python installation automatically. You won't need to do any compiling (none of: nmake, nmake install, python configure).

安装 PyQt 的最简单方法是使用安装程序(链接在您的答案中,第 5 步)。如果您安装 python 3.3,安装程序会自动将所有 PyQt5 附加组件添加到该 python 安装中。你不需要做任何编译(没有:nmake、nmake install、python configure)。

All of the build options are available for if you need a custom install (for instance, using a different version of python, where there isn't an installer provided by riverbank computing).

如果您需要自定义安装,则所有构建选项都可用(例如,使用不同版本的 python,其中没有 Riverbank 计算提供的安装程序)。

If you do need to compile your own version of PyQt5, the steps (as you have found) are here, but assume you have python and a compiler installed and in your path. The installed and in your path have been where you have been running into trouble it seems. I'd recommend using the installer version, but you need to install python 3.3first.

如果您确实需要编译自己的 PyQt5 版本,步骤(如您所见)在此处,但假设您已安装 python 和编译器并在您的路径中。安装的和在您的路径中似乎是您遇到麻烦的地方。我建议使用安装程序版本,但您需要先安装python 3.3

回答by Victor Lellis

I found a partial solution...

我找到了部分解决方案...

Steps to install pyQt5 (with VS 2012) on Windows:

在 Windows 上安装 pyQt5(使用 VS 2012)的步骤:

1) Install the binary file Qt 5.0.2 for Windows 64-bit (VS 2012, 500 MB)from here.

1)Qt 5.0.2 for Windows 64-bit (VS 2012, 500 MB)这里安装二进制文件。

2) Get sip-4.14.7(development snapshot) from here.

2)sip-4.14.7这里获取(开发快照)。

3) Extract the file and open the Developer Command Prompt for VS2012.

3) 解压文件并打开Developer Command Prompt for VS2012.

4) Execute these commands (in sip folder):

4)执行这些命令(在sip文件夹中):

python configure.py
nmake
nmake install

5) Get the pyQt5from here.

5)pyQt5这里获取。

6) Extract the file and open the VS2012 x64 Native Tools Command Prompt.

6) 解压文件并打开VS2012 x64 Native Tools Command Prompt.

7) Execute these commands:

7)执行这些命令:

python configure.py

UPDATE:When execute these commands below is not working:

更新:当执行以下这些命令不起作用时:

nmake
nmake install

Solution: I will try use pyQt4 with Qt5... because pyQt5 is in development and doesn't have support/documentation yet.

解决方案:我将尝试将 pyQt4 与 Qt5 一起使用...因为 pyQt5 正在开发中并且还没有支持/文档​​。

回答by Malek B.

Mainly I use the following command under the cmd

主要是我使用下面的命令 cmd

pip install pyqt5

And it works with no problem!

它没有问题!

回答by Jarad

First try this in your Windows cmd window:

首先在您的 Windows cmd 窗口中尝试此操作:

pip3 install pyqt5

If that is successful, it will look something like this:

如果成功,它将看起来像这样:

C:\Windows\System32>pip3 install pyqt5
Collecting pyqt5
  Downloading PyQt5-5.9-5.9.1-cp35.cp36.cp37-none-win_amd64.whl (77.2MB)
    100% |################################| 77.2MB 13kB/s
Collecting sip<4.20,>=4.19.3 (from pyqt5)
  Downloading sip-4.19.3-cp35-none-win_amd64.whl (49kB)
    100% |################################| 51kB 984kB/s
Installing collected packages: sip, pyqt5
Successfully installed pyqt5-5.9 sip-4.19.3

If that did not work, you might try this link from SourceForge.

如果这不起作用,您可以尝试来自 SourceForge 的此链接。

PyQt5 .exe installers for Windows

适用于 Windows 的 PyQt5 .exe 安装程序

How to find the installer that's right for you?

如何找到适合您的安装程序?

First, determine what version of Python you have and whether you have 32-bit or 64-bit Python. Next, open one of the directories. I'm on Python 3.5 64-bit so I'm looking for a .exe with those specs. When you open a directory on SourceForge, you will see some directories with ONLY .zipor .tar.gz. That's not what you're looking for. A good indication of which directory you should click is given by the "Downloads/Week" column. I'll open the PyQt-5.6directory in my case.

首先,确定您使用的是哪个版本的 Python,以及您使用的是 32 位还是 64 位 Python。接下来,打开其中一个目录。我使用的是 Python 3.5 64 位,所以我正在寻找具有这些规格的 .exe。当你在 SourceForge 上打开一个目录时,你会看到一些只有.zip.tar.gz 的目录。那不是你要找的。“下载/周”列很好地表明了您应该单击哪个目录。在我的例子中,我将打开PyQt-5.6目录。

Here we notice some .exe files:

这里我们注意到一些 .exe 文件:

PyQt-5.6
|_PyQt5-5.6-gpl-Py3.5-Qt5.6.0-x32-2.exe
|_PyQt5-5.6-gpl-Py3.5-Qt5.6.0-x64-2.exe
|_PyQt5_gpl-5.6.zip
|_PyQt5_gpl-5.6.tar.gz

I know these are Python 3.5 by Py3.5in the file name. I am also looking for the 64-bit version so I'll download PyQt5-5.6-gpl-Py3.5-Qt5.6.0-x64-2.exe. Final answer!

我知道这些是Py3.5文件名中的 Python 3.5 。我也在寻找 64 位版本,所以我会下载PyQt5-5.6-gpl-Py3.5-Qt5.6.0-x64-2.exe. 最终答案!

Note: if you try to install a version that's not compatible with your system, a dialog box will appear immediately after running the .exe. That's an indication that you've chosen the wrong one. I'm not trying to sound like a dbag... I did that several times!

注意:如果您尝试安装与您的系统不兼容的版本,运行 .exe 后会立即出现一个对话框。这表明你选错了。我不是想听起来像个包包……我做了好几次!

To test a successful install, in your Python interpreter, try to import:

要测试安装是否成功,请在您的 Python 解释器中尝试导入:

from PyQt5 import QtCore, QtGui, QtWidgets

回答by Trigremm

Another command under the cmdis:

下的另一个命令cmd是:

easy_install pyqt5

easy_install pyqt5

回答by cengineer

One of the most (probably the most) easiest way to install site-packages like PyQt5 is installing one of the versions of Anaconda. You can just install many of site-packages by installing it. List of avaliable site-packages with Anaconda versions can be checked here.

安装像 PyQt5 这样的站点包的最(可能是最)最简单的方法之一是安装 Anaconda 的一个版本。您可以通过安装来安装许多站点包。可以在此处检查具有 Anaconda 版本的可用站点包列表。

  1. Dowload Anaconda3or Anaconda2
  2. Install it.
  3. Add PyQt5's path inside Anaconda installation to your System Environment Variables.
  1. 下载 Anaconda3或 Anaconda2
  2. 安装它。
  3. 将 Anaconda 安装中 PyQt5 的路径添加到您的系统环境变量中。

For example:

例如:

PATH: ....; C:\Anaconda3\Lib\site-packages\PyQt5; ...
  1. It is ready to use.
  1. 它可以使用了。

回答by Ivan_ug

If you are using canopy, use the package manager to install qt (and or pyqt)

如果您使用的是 canopy,请使用包管理器安装 qt(和或 pyqt)

回答by Felipe Centeno

I'm new to both Python and PyQt5. I tried to use pip, but I was having problems with it using a Windows machine. If you have a version of Python 3.4 or above, pip is installed and ready to use like so:

我是 Python 和 PyQt5 的新手。我尝试使用 pip,但我在使用 Windows 机器时遇到了问题。如果您有 Python 3.4 或更高版本,pip 已安装并可以使用,如下所示:

python -m pip install pyqt5 

That's of course assuming that the path for Python executable is in your PATH environment variable. Otherwise include the full path to Python executable (you can type where pythonto the Command Window to find it) like:

这当然是假设 Python 可执行文件的路径在您的 PATH 环境变量中。否则,包括 Python 可执行文件的完整路径(您可以where python在命令行窗口中键入以找到它),例如:

C:\users\userName\AppData\Local\Programs\Python\Python34\python.exe -m pip install pyqt5

回答by Ali Mirzaei

You can easily install it using Anaconda. At first install Anacondaor Minicondaon you system (download from here) and then install the pyqt as follow:

您可以使用 Anaconda 轻松安装它。首先在您的系统上安装AnacondaMiniconda(从这里下载),然后按如下方式安装 pyqt:

conda install pyqt

It works for both version of python (2 and 3).

它适用于python的两个版本(2和3)。

回答by MarianD

To install the GPL version of PyQt5, run (see PyQt5 Project):

要安装 PyQt5 的 GPL 版本,请运行(请参阅PyQt5 项目):

pip3 install pyqt5

This will install the Python wheelfor your platform and your version of Python(assuming both are supported).

这将安装Python的车轮所用平台的Python版本(假设两者都支持)。

(The wheel will be automatically downloaded from the Python Package Index.)

(轮子将自动从Python Package Index下载。)

The PyQt5 wheel includes the necessary parts of the LGPL version of Qt. There is no need to install Qt yourself.

PyQt5 轮包括 Qt LGPL 版本的必要部分无需自己安装 Qt

(The required sipis packaged as a separate wheel and will be downloaded and installed automatically.)

(需要sip打包成单独的轮子,会自动下载安装。)



Note:

注意

If you get an error message saying something as

如果您收到一条错误消息,内容如下

No downloads could be found that satisfy the requirement 
No downloads could be found that satisfy the requirement 

then you are probably using an unsupported versionof Python.

那么您可能正在使用不受支持的 Python版本