简体   繁体   English

在树莓派上为 Python3.6 安装 PyQt5

[英]Install PyQt5 on Raspberry for Python3.6

Since I found no answer for my question, neither in older posts nor in other forums, I want to ask the stackoverflow community for advice.由于我在较旧的帖子和其他论坛中都没有找到我的问题的答案,因此我想向 stackoverflow 社区寻求建议。

I am using a raspberry pi 3B+, version 9.4 (lite) with kernel version 4.14.71-v7.我使用的是带有内核版本 4.14.71-v7 的 raspberry pi 3B+,版本 9.4 (lite)。

I use python3.6.我使用python3.6。 I installed it as follows:我是这样安装的:

sudo apt-get install build-essential checkinstall
sudo apt-get install libreadline-gplv2-dev libncursesw5-dev libssl-dev libsqlite3-dev tk-dev libgdbm-dev libc6-dev libbz2-dev

cd /usr/src
sudo wget https://www.python.org/ftp/python/3.6.0/Python-3.6.0.tgz
sudo tar xzf Python-3.6.0.tgz

sudo -s
cd Python-3.6.0
bash configure
make altinstall
exit

Installation was without any trouble and everything works perfectly.安装没有任何问题,一切正常。

Now I wanted to install the PyQt5 modul for python3.6.现在我想为 python3.6 安装 PyQt5 模块。 I usually use我通常使用

sudo python3.6 -m pip install ...

for installing a modul for python3.6.用于为 python3.6 安装模块。 Trying

sudo python3.6 -m pip install pyqt5

gave me the error message给了我错误信息

 Could not find a version that satisfies the requirement PyQt5 (from versions: )
 No matching distribution found for PyQt5

So I tried所以我试过了

sudo apt-get update
sudo apt-get install qt5-default pyqt5-dev pyqt5-dev-tools

But it installed PyQt5 for python3.5 (which is preinstalled) on the raspberry.但是它在树莓派上为python3.5(预装)安装了PyQt5。

So does anybody know how to use or install PyQt5 for the subsequently installed python3.6?那么有没有人知道如何为随后安装的python3.6使用或安装PyQt5?

Edit 08.03.2019: 2019 年 3 月 8 日编辑:
Thanks FlyingTeller.谢谢飞特勒。 I started to build from source.我开始从源代码构建。 I followed the steps from your link.我按照您链接中的步骤操作。

sudo apt-get update
cd /usr/src
sudo wget https://www.riverbankcomputing.com/static/Downloads/sip/sip-4.19.14.tar.gz
sudo tar xzf sip-4.19.14.tar.gz
cd sip-4.19.14
sudo -s
python3.6 configure.py --sip-module=PyQt5.sip 
make
make install

cd /usr/src
sudo wget https://www.riverbankcomputing.com/static/Downloads/PyQt5/PyQt5_gpl-5.12.tar.gz
sudo tar xzf PyQt5_gpl-5.12.tar.gz
cd PyQt5_gpl-5.12
python3.6 configure.py

Then I received the following error然后我收到以下错误

Error: Use the --qmake argument to explicitly specify a working Qt qmake.

I think I am on the right way, but I do not understand what qmake is or what it means.我认为我走在正确的道路上,但我不明白 qmake 是什么或它意味着什么。

Edit 10.03.2019: 2019 年 3 月 10 日编辑:
I could solve the last error message.我可以解决最后一条错误消息。 I installed我安装了

sudo apt-get install qt5-default

Then I did the same procedure as already mentioned.然后我做了与已经提到的相同的程序。 Now I get the error现在我得到了错误

fatal error: sip.h: File or directory not found 
#include <sip.h>

PyQt5 config.py is in: /usr/src/PyQt5_gpl-5.12 PyQt5 config.py 位于:/usr/src/PyQt5_gpl-5.12
SIP sip.h is in: /usr/src/sip-4.19.14 SIP sip.h 位于:/usr/src/sip-4.19.14

Anybody an idea?有人有想法吗? Thanks guys.谢谢你们。

Today I found the solution.今天我找到了解决方案。 The steps below worked for me, without any error.以下步骤对我有用,没有任何错误。 The whole process took almost two hours.整个过程用了将近两个小时。

sudo apt-get update
sudo apt-get install qt5-default
sudo apt-get install sip-dev

cd /usr/src
sudo wget https://www.riverbankcomputing.com/static/Downloads/sip/sip-4.19.14.tar.gz
sudo tar xzf sip-4.19.14.tar.gz
cd sip-4.19.14
sudo python3.6 configure.py --sip-module PyQt5.sip
sudo make
sudo make install

cd /usr/src
sudo wget https://www.riverbankcomputing.com/static/Downloads/PyQt5/PyQt5_gpl-5.12.tar.gz
sudo tar xzf PyQt5_gpl-5.12.tar.gz
cd PyQt5_gpl-5.12
sudo python3.6 configure.py
sudo make
sudo make install

Seems like they moved some things around.似乎他们移动了一些东西。 This seems to work, as far as getting things, and compiling them.就获取事物和编译它们而言,这似乎有效。 It takes a long time to build.建造需要很长时间。

For the associated designer, look at:对于相关的设计师,请看:

QtDesigner for Raspberry Pi 用于 Raspberry Pi 的 QtDesigner

sudo apt-get update
sudo apt-get install qt5-default
sudo apt-get install sip-dev

cd /usr/src
sudo wget https://www.riverbankcomputing.com/static/Downloads/sip/4.19.23/sip-4.19.23.tar.gz
sudo tar xzf sip-4.19.23.tar.gz
cd sip-4.19.23
sudo python3 configure.py --sip-module PyQt5.sip
sudo make
sudo make install

cd /usr/src
sudo wget https://www.riverbankcomputing.com/static/Downloads/PyQt5/5.13.2/PyQt5-5.13.2.tar.gz
sudo tar xzf PyQt5-5.13.2.tar.gz
cd PyQt5-5.13.2
sudo python3  configure.py
sudo make
sudo make install

我尝试按照您的步骤操作,但收到错误消息:我安装了python 3.7.0,因此我进行了相应的更改,现在我在sip上安装了版本5,因此当我尝试“ sudo python3.6 configure.py --sip-模块PyQt5.sip”我得到“没有这样的文件或目录” ...任何帮助或想法?

在我的情况下,它有助于将 pip 从 verion 18 更新到最新版本,在我的情况下是 20.2 ( python -m pip install --upgrade pip ),然后执行pip install PyQt5

The instructions used in the accepted answer did not work for me.接受的答案中使用的说明对我不起作用。 I think it's simply because they are outdated.我认为这仅仅是因为它们已经过时了。 I wanted to post the list of commands that did work for me.我想张贴没有工作对我的命令列表。 I'm running a Pi 400 with the latest version of Raspbian as of 12/20/2020.截至 2020 年 12 月 20 日,我正在使用最新版本的 Raspbian 运行 Pi 400。 I used the default python3 rather than python3.6 .我使用了默认的python3而不是python3.6

Here is the modified list of commands that worked for me:这是对我有用的修改后的命令列表:

sudo apt-get install qt5-default
sudo apt-get install sip-dev

cd /usr/src
sudo wget https://www.riverbankcomputing.com/static/Downloads/sip/sip-5.5.1.dev2011271026.tar.gz
sudo tar xzf sip-5.5.1.dev2011271026.tar.gz
cd sip-5.5.1.dev2011271026
sudo python3 setup.py build
sudo python3 setup.py install

sudo wget https://files.pythonhosted.org/packages/28/6c/640e3f5c734c296a7193079a86842a789edb7988dca39eab44579088a1d1/PyQt5-5.15.2.tar.gz
sudo tar xzf PyQt5-5.15.2.tar.gz
cd PyQt5-5.15.2
sudo python3 configure.py
sudo make
sudo make install

Can't comment due to reputation but I would add to Christ Troutner's useful updated answer, that in case users get a No module named 'PyQt5.sip' error, try --sip-module PyQt5.sip during configure, per the docs:由于声誉而无法发表评论,但我会添加到 Christ Troutner 有用的更新答案中,如果用户收到No module named 'PyQt5.sip'错误,请在配置期间尝试 --sip-module PyQt5.sip,根据文档:

Note笔记

When building PyQt5 v5.11 or later you must configure SIP to create a private copy of the sip module using a command line similar to the following:在构建 PyQt5 v5.11 或更高版本时,您必须配置 SIP 以使用类似于以下内容的命令行创建 sip 模块的私有副本:

python configure.py --sip-module PyQt5.sip python configure.py --sip-module PyQt5.sip

If you already have SIP installed and you just want to build and install the private copy of the module then add the --no-tools option.如果您已经安装了 SIP 并且您只想构建和安装模块的私有副本,那么添加 --no-tools 选项。

The accepted answers did not work for me, below is the code that worked for me.接受的答案对我不起作用,下面是对我有用的代码。

   sudo apt-get update
   sudo apt-get install qt5-default
   sudo apt-get install qtcreator

This code not only installs Qtcreator but also installs Qt5 Assistant, Qt5 Designer, and Qt5 Linguist这段代码不仅安装了Qtcreator,还安装了Qt5 Assistant、Qt5 Designer和Qt5 Linguist

thank you for this thread. 谢谢你的这个话题。 I am following your instructions. 我正在听你的指示。 But at the end after instullation when I run my code/program, I got the following error: 但是在我安装代码/程序时,安装完成后,出现以下错误:

================================== =================================

qt5ct: using qt5ct plugin QEGLPlatformContext: Failed to create context: 3009 qt5ct:使用qt5ct插件QEGLPlatformContext:创建上下文失败:3009

QOpenGLWindow::beginPaint: Failed to create context QOpenGLWindow :: beginPaint:无法创建上下文

QOpenGLWindow::beginPaint: Failed to make context current QOpenGLWindow :: beginPaint:无法使上下文为当前

Traceback (most recent call last): 追溯(最近一次通话):

File "my_prog.py", line 68, in initializeGL 在initializeGL中的文件“ my_prog.py”,第68行

self.gl = self.context().versionFunctions()

AttributeError: module 'PyQt5._QOpenGLFunctions_ES2' has no attribute 'QOpenGLFunctions_ES2' AttributeError:模块“ PyQt5._QOpenGLFunctions_ES2”没有属性“ QOpenGLFunctions_ES2”

Aborted 中止

================================== =================================

Do you have an idea how to solve it? 你有解决的办法吗? Many thanks in advance. 提前谢谢了。

I am using Raspberry Pi4 which has python3.7 by default. 我正在使用默认情况下具有python3.7的Raspberry Pi4。 I installed python3.6 and followed your exact instructions (I got the same message on python3.7 as well) 我安装了python3.6,并按照您的确切说明进行操作(在python3.7上也收到了相同的消息)

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

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