Python 如何在 Windows 7 上安装 SIP 和 PyQT
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/32054021/
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
How to install SIP & PyQT on windows 7
提问by SanVEE
I'm a newbie to Python environment & really struggling to install SIP & PyQt on my Win 7 machine.
我是 Python 环境的新手,在我的 Win 7 机器上安装 SIP 和 PyQt 真的很费劲。
This is what I've done so far,
这是我迄今为止所做的,
- I've downloaded SIP-4.16.9and extracted files from the zip folder
- The extracted folder is then copied to C:\Python34\Lib
- Launched a command prompt(cmd) and changed path to C:\Python34\Lib
- Then when I entered
python configure.py
at C:\Python34\Liband I get the response as below
- 我已经下载了SIP-4.16.9并从 zip 文件夹中提取了文件
- 然后将提取的文件夹复制到C:\Python34\Lib
- 启动命令提示符(cmd)并将路径更改为C:\Python34\Lib
- 然后当我
python configure.py
在C:\Python34\Lib输入时,我得到如下响应
- At this stage I'm not sure whether it's been installed successfully, to verify I looked for SIP.hat
C:\Python34\Include
(according to above response - in red), but I cant find any such header file, so I assume the installation hasn't been successful.
- 在这个阶段我不确定它是否安装成功,为了验证我在(根据上面的响应 - 红色)查找了SIP.h
C:\Python34\Include
,但我找不到任何这样的头文件,所以我假设安装没有成功了。
Could any one help me, what am I missing here?
任何人都可以帮助我,我在这里缺少什么?
Additional System Info:
附加系统信息:
- Windows 7 64 Bit
- Python 3.4
- Environment Variable (Path : C:\Python34;C:\Python34\Lib;C:\Python34\Lib\site-packages)
- 视窗 7 64 位
- 蟒蛇 3.4
- 环境变量(路径:C:\Python34;C:\Python34\Lib;C:\Python34\Lib\site-packages)
Note: There are several questions posted before, but none of them helped so far, I'm sure I must be missing something silly.
注意:之前发布了几个问题,但到目前为止它们都没有帮助,我确定我一定遗漏了一些愚蠢的东西。
Thanks for your time.
谢谢你的时间。
回答by SanVEE
There's a ONE SHOT solution to all your installation problems on Windows. Go to this website. http://www.lfd.uci.edu/~gohlke/pythonlibs/. Navigate to the library you want and download the .whl file for your python version and your computer (32 or 64 bit.) Then run pip install YourWhlFileName.whl
, and you're done! (CAUTION: MAKE SURE NOT TO CHANGE THE NAME OF THE WHL FILE OR IT WON'T WORK.)
Windows 上的所有安装问题都有一个 ONE SHOT 解决方案。去这个网站。http://www.lfd.uci.edu/~gohlke/pythonlibs/。导航到您想要的库并下载适用于您的 Python 版本和计算机(32 位或 64 位)的 .whl 文件。然后运行pip install YourWhlFileName.whl
,您就完成了!(注意:确保不要更改 WHL 文件的名称,否则将不起作用。)
回答by SyedElec
For next users who need to build sip (or pyqt) in windows using sources
对于需要使用源在 Windows 中构建 sip(或 pyqt)的下一个用户
ALL these instructions are for 32-bits, it will work even if you have a 64-bit system.
所有这些指令都是针对 32 位的,即使您使用的是 64 位系统,它也能工作。
For Qt 5.9.x :
对于 Qt 5.9.x :
Since Qt 5.9, there is only one version of Qt downloadable for Windows that includes the pre-built components for MSVC201x and MinGW.
从 Qt 5.9 开始,只有一个适用于 Windows 的 Qt 版本可下载,其中包含 MSVC201x 和 MinGW 的预构建组件。
The instructions follow the same steps as for Qt 5.8
说明遵循与 Qt 5.8 相同的步骤
Since Microsoft Visual Studio 2015 Community Editionis not available to download anymore, next users should use Microsoft Visual Studio 2017 Community Editionwith Qt 5.9 and follow the same instructions below.
由于Microsoft Visual Studio 2015 社区版不再可供下载,下一个用户应该使用带有 Qt 5.9 的Microsoft Visual Studio 2017 社区版,并按照以下相同的说明进行操作。
Microsoft Visual Studio 2017Community Edition (32-bits)
Qt 5.9.x
Microsoft Visual Studio 2017社区版(32 位)
Qt 5.9.x
When Installing Qt, make sure to select the correct pre-built components you have (for e.g Microsoft Visual Studio 2017)
安装 Qt 时,请确保选择正确的预构建组件(例如 Microsoft Visual Studio 2017)
For Qt 5.8 and earlier :
对于 Qt 5.8 及更早版本:
Downloads
下载
Download Python 3.6.x (32-bits)any version will do it :
下载Python 3.6.x(32 位)任何版本都可以:
(if you also have python 2.7, make sure to use verions 3 of python)
(如果你也有 python 2.7,请确保使用 python 版本 3)
Download sources for sip and PyQt5: Under "Source Packages", download the "Windows Source"
Microsoft Visual Studio 2015Community Edition (32-bits)
Qt 5.8.0 for Windows 32-bit(VS 2015, 1.0 GB)
下载sip 和 PyQt5 的源代码:在“Source Packages”下,下载“Windows Source”
Microsoft Visual Studio 2015社区版(32 位)
适用于 Windows 32 位的 Qt 5.8.0(VS 2015,1.0GB)
Qt download link must match the Visual Studio (VS) version installed (here VS 2015) and the PyQt5 version you need to install
Qt 下载链接必须匹配安装的 Visual Studio (VS) 版本(此处为 VS 2015)和您需要安装的 PyQt5 版本
For example:
例如:
- PyQt5.8.2
- Qt5.8.0 (Link for VS 2015)
- Microsoft Visual Studio 2015
- PyQt5.8.2
- Qt5.8.0(VS 2015 链接)
- 微软 Visual Studio 2015
Compilation
汇编
Open a terminal and stay on it.
打开一个终端并留在上面。
It is important you stay on the same terminal (cmd.exe
) during the whole process so you don't have to source your environment twice.
cmd.exe
在整个过程中保持在同一个终端 ( )上很重要,这样您就不必两次获取环境。
Let's create an environment to compile PyQt and SIP (in order to compile PyQt, you need first to compile sip)
下面我们来创建一个编译PyQt和SIP的环境(为了编译PyQt,你需要先编译sip)
- Create a folder "compilation" in your Desktop for example:
- Extract the content of your sip archive in this forlder
- Extract the content of your PyQt5 archive in this forlder
- 例如,在您的桌面中创建一个文件夹“编译”:
- 在此文件夹中提取 sip 存档的内容
- 在此文件夹中提取 PyQt5 存档的内容
You should have now :
你现在应该:
.
├── compilation
| ├── sip-4.19.2/
| └── PyQt5_gpl-5.8.2/
Make sure you are using Python 3.x:
确保您使用的是 Python 3.x:
1 - SIP
1 - SIP
Go to sip-4.19.2folder and run :
转到sip-4.19.2文件夹并运行:
python configure.py
python configure.py
At this step, you did not install sip, you only configured it (basically its installation dir, etc...)
这一步,你没有安装sip,你只是配置了它(基本上是它的安装目录等...)
VERY IMPORTANT STEP: source your environment variables by running in the terminal :
非常重要的步骤:通过在终端中运行来获取环境变量:
Keep the double quotes, windows does not like spaces ...
保留双引号,windows 不喜欢空格...
"C:\Qt\Qt5.8.0.8\msvc2015\bin\qtenv2.bat"
After running this command, it automatically change your current directory, stay on the terminal and re-go to your sip-4.19.2 directory and run:
运行此命令后,它会自动更改您的当前目录,停留在终端上并重新转到您的 sip-4.19.2 目录并运行:
"C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\vcvarsall.bat"
In windows, "make" is substituted by "nmake" !
在 Windows 中,“make”被“nmake”代替!
Then (always in the same terminal) you run :
然后(总是在同一个终端中)你运行:
nmake
[...]
[...]
nmake install
This will create a sip.exe in your Python dir, for me it is C:\Python36
, it may elsewhere, depending on where you installed Python.
这将在您的 Python 目录中创建一个 sip.exe,对我来说是C:\Python36
,它可能在其他地方,具体取决于您安装 Python 的位置。
2 - PyQt5
2 - PyQt5
The steps are almost the same as sip but it will take more time.
步骤与 sip 几乎相同,但需要更多时间。
Go to PyQt5_gpl-5.8.2folder and run :
转到PyQt5_gpl-5.8.2文件夹并运行:
python configure.py --disable QtNfc --confirm-license
python configure.py --disable QtNfc --confirm-license
Note that this command disable QtNfs because of a compilation problem I could not resolve.. and automatically accepts the license.
请注意,由于我无法解决的编译问题,此命令禁用 QtNfs 并自动接受许可证。
Then, run (the compilation will take a while) :
然后,运行(编译需要一段时间):
nmake
nmake install
Hope this helps.
希望这可以帮助。
回答by Francesco
This is for all that want to build PyQt4 with latest Qt4 and Python 3.4.x.
这适用于所有想要使用最新的 Qt4 和 Python 3.4.x 构建 PyQt4 的人。
Download Visual Studio 2010 from here: http://download.cnet.com/Microsoft-Visual-Studio-2010-Ultimate/3000-2383_4-75450998.html
从这里下载 Visual Studio 2010:http: //download.cnet.com/Microsoft-Visual-Studio-2010-Ultimate/3000-2383_4-75450998.html
then install it.
然后安装它。
Download SIP source code (in my case version 4.19.5) from here: https://www.riverbankcomputing.com/software/sip/download
从这里下载 SIP 源代码(在我的情况下为 4.19.5 版):https://www.riverbankcomputing.com/software/sip/download
Download PyQt4 source code (in my case version 4.12.1) from here: https://www.riverbankcomputing.com/software/pyqt/download
从这里下载 PyQt4 源代码(在我的情况下为 4.12.1 版):https: //www.riverbankcomputing.com/software/pyqt/download
Extract SIP and PyQt .zip archive in \Users\your_username\Desktop\compilation\
在 \Users\your_username\Desktop\compilation\ 中提取 SIP 和 PyQt .zip 存档
Download latest Qt 4.x (vs2010 version) installer from here: http://download.qt.io/archive/qt/
从这里下载最新的 Qt 4.x(vs2010 版本)安装程序:http: //download.qt.io/archive/qt/
Install Qt (in my case qt-opensource-windows-x86-vs2010-4.8.6.exe).
安装 Qt(在我的例子中是 qt-opensource-windows-x86-vs2010-4.8.6.exe)。
Open a command prompt (use this one for all the process) and execute these commands:
打开命令提示符(对所有进程使用此命令提示符)并执行以下命令:
cd \Users\<your_username>\Desktop\compilation\sip-4.19.5
python configure.py
"C:\Qt.8.6\bin\qtvars.bat"
In the output take note of QMAKESPEC value, in my case win32-msvc2010, then use it later on --spec option for PyQt4 configure-ng script.
在输出中记下 QMAKESPEC 值,在我的情况下是 win32-msvc2010,然后稍后在 PyQt4 configure-ng 脚本的 --spec 选项上使用它。
If the current directory has been changed, execute again:
如果当前目录已更改,则再次执行:
cd \Users\<your_username>\Desktop\compilation\sip-4.19.5
Now, if you use 64-bit version of Python execute:
现在,如果您使用 64 位版本的 Python 执行:
"C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\vcvarsall.bat"
otherwise, if you use 32-bit version of Python execute:
否则,如果您使用 32 位版本的 Python 执行:
"C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\bin\vcvars32.bat"
nmake
nmake install
cd \Users\<your_username>\Desktop\compilation\PyQt4_gpl_win-4.12.1
Now use previous QMAKESPEC value in --spec option:
现在在 --spec 选项中使用以前的 QMAKESPEC 值:
python configure-ng.py --spec win32-msvc2010
nmake
nmake install
That's all ;-)
就这样 ;-)
NOTE: in some cases, in order to avoid this error
注意:在某些情况下,为了避免这个错误
ImportError: DLL load failed: The specified procedure could not be found.
it is necessary to copy .dll files from
有必要从
C:\Qt.8.6\bin
to
到
C:\Python34\Lib\site-packages\PyQt4