在 Linux 上安装 PyQt5 5.14.1

Install PyQt5 5.14.1 on Linux

pip3 install PyQt5
Collecting PyQt5
  Using cached https://files.pythonhosted.org/packages/3a/fb/eb51731f2dc7c22d8e1a63ba88fb702727b324c6352183a32f27f73b8116/PyQt5-5.14.1.tar.gz
    Complete output from command python setup.py egg_info:
    Traceback (most recent call last):
      File "<string>", line 1, in <module>
      File "/usr/lib/python3.6/tokenize.py", line 452, in open
        buffer = _builtin_open(filename, 'rb')
    FileNotFoundError: [Errno 2] No such file or directory: '/tmp/pip-build-b2zw891b/PyQt5/setup.py'

    ----------------------------------------
Command "python setup.py egg_info" failed with error code 1 in /tmp/pip-build-b2zw891b/PyQt5/

然后我从 https://www.riverbankcomputing.com/software/pyqt/download5 和 运行 下载了 zip 文件夹:

python3 configure.py --qmake /home/oo/Qt/5.14.0/gcc_64/bin/qmake
make
sudo make install

成功

>>> import PyQt5
>>> import PyQt5.QtCore
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named 'PyQt5.sip'
>>> 

所以我安装了

pip3 install PyQt5.sip
pip3 install sip

成功

import PyQt5.QtCore

仍然出现相同的错误 No module named 'PyQt5.sip'

也试过 PyQtChart 还是报错

pip3 install PyQtChart
Collecting PyQtChart
  Using cached https://files.pythonhosted.org/packages/83/35/4f6328db9a31e2776cdcd82ef7688994c11e265649f503858f1913444ba9/PyQtChart-5.14.0-5.14.0-cp35.cp36.cp37.cp38-abi3-manylinux1_x86_64.whl
Collecting PyQt5>=5.14 (from PyQtChart)
  Using cached https://files.pythonhosted.org/packages/3a/fb/eb51731f2dc7c22d8e1a63ba88fb702727b324c6352183a32f27f73b8116/PyQt5-5.14.1.tar.gz
    Complete output from command python setup.py egg_info:
    Traceback (most recent call last):
      File "<string>", line 1, in <module>
      File "/usr/lib/python3.6/tokenize.py", line 452, in open
        buffer = _builtin_open(filename, 'rb')
    FileNotFoundError: [Errno 2] No such file or directory: '/tmp/pip-build-gzep4mr7/PyQt5/setup.py'

----------------------------------------
Command "python setup.py egg_info" failed with error code 1 in /tmp/pip-build-gzep4mr7/PyQt5/

我还从 https://www.riverbankcomputing.com/software/pyqtchart/download 和 运行:

下载了 zip 文件夹
python3 configure.py --qmake /home/oo/Qt/5.14.0/gcc_64/bin/qmake
Error: Unable to import PyQt5.QtCore. Make sure PyQt5 is installed.

QT 截图::

我的最终目标是 运行 使用 pyqt5 的烛台图表。

sudo python3 -m pip install pyqt5 pyqtchart
[sudo] password for oo:  
The directory '/home/oo/.cache/pip/http' or its parent directory is not owned by the current user and the cache has been disabled. Please check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.
The directory '/home/oo/.cache/pip' or its parent directory is not owned by the current user and caching wheels has been disabled. check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.
Requirement already satisfied: pyqt5 in /usr/lib/python3/dist-packages
Requirement already satisfied: pyqtchart in /usr/local/lib/python3.6/dist-packages
Requirement already satisfied: PyQt5-sip<13,>=12.7 in /home/oo/.local/lib/python3.6/site-packages (from pyqtchart)

但仍然出现同样的错误:

Python 3.6.9 (default, Nov  7 2019, 10:44:02) 
[GCC 8.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import PyQt5
>>> import PyQt5.QtCore
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named 'PyQt5.sip'
>>> 

好像最新版的PyQt5到pypi有bug所以安装了一个5.14的版本:

sudo apt-get update && \
    sudo apt-get autoclean

sudo apt-get update && sudo apt-get install \
    -y --no-install-recommends \
    python3-pip \
    python3-setuptools

sudo python3 -m pip install pyqt5==5.14 pyqtchart==5.14

的例子复制到main.py然后运行:

python3 main.py

我建议您搜索失败尝试生成的文件夹和文件并删除它们。

对于我的测试,我使用了以下 Dockerfile

我认为最初的 pip install 问题是由于 PyQt5 切换到最新版本的 manylinux2014 平台标签(参见 PyPI 上的轮子 5.14.1 vs 5.14.0). Only pip versions >= 19.3 recognize this platform tag (ref),所以如果你碰巧有一个旧版本的 pip,它会尝试从源安装。

两个简单的选项(避免源安装):

  • 通过pip3 install --upgrade pip
  • 更新pip到最新
  • 安装以前的版本,它使用了 manylinux1 (pip3 install pyqt5==5.14.0)

我在安装 PyQt5 时也遇到了同样的问题(在尝试安装 ReText 时)。

Ubuntu 18.04 上使用 Python 3.6.9Pip 9.0.1,我能够通过以下步骤 pip 安装 PyQt5

python3 -m venv env
source env/bin/activate
pip3 install pyqt5 --only-binary pyqt5

这足以让 pip 下载 PyQt5-5.14.0-5.14.0-cp35.cp36.cp37.cp38-abi3-manylinux1_x86_64.whl 二进制轮(不是 need/use setup.py),而不是从源 tarball 构建。

根据 https://pypi.org/project/PyQt5/#files,还有其他二进制轮子,希望能满足大多数平台需求。

有时很难在 Debian 或 Ubuntu Linux 发行版上安装 PyQt5。 我能够在我的系统 运行 Debian 10 buster(稳定版)上为 python3 安装它。
我用 apt 包管理器安装了它。

sudo apt-get update 
sudo apt-get install python3-pyqt5

对于那些不是迫切需要5.14的人来说,5.12可能是一个解决方案。这对我有用:

sudo python3 -m pip install pyqt5==5.12 pyqtchart==5.12

如问题所示,您正在下载 tar.zip 文件而不是 wheel。只有 wheel 才允许使用 pip 安装 QT。在 PyPI 主页中选择具有 wheel 文件并与您的 Python 版本匹配的版本。

我也有这个问题。这是因为您的 pip 是旧版本,您应该使用以下命令更新它:

pip3 install setuptools wheel
pip3 install --upgrade pip
pip3 install --user pyqt5

为了从源代码构建所需版本的 PyQt5,我必须从源代码构建正确版本的 sip,然后我还遇到了以下错误:

No module named 'PyQt5.sip'

然后

python3 -m pip install PyQt5.sip

解决了问题