34
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

成功的

但仍然得到同样No module named 'PyQt5.sip'的错误import PyQt5.QtCore

也尝试了 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'
>>> 
4

8 回答 8

70

我认为最初pip install的麻烦是由于 PyQt5 切换到最新版本的 manylinux2014 平台标签(请参阅 PyPI 上的轮子5.14.15.14.0)。只有 pip 版本 >= 19.3 可以识别这个平台标签 ( ref ),所以如果你碰巧有旧版本的 pip,它会尝试从源代码安装。

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

  • 通过将 pip 更新到最新版本pip3 install --upgrade pip
  • 安装以前的版本,它使用 manylinux1 ( pip3 install pyqt5==5.14.0)
于 2020-01-18T04:14:18.987 回答
19

看来最新版的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

于 2020-01-13T07:24:38.587 回答
10

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

在andUbuntu 18.04上,我可以通过以下步骤进行 pip 安装:Python 3.6.9Pip 9.0.1PyQt5

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二进制轮子(不需要/使用setup.py),而不是从源 tarball 构建。

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

于 2020-04-07T14:37:35.653 回答
2

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

sudo apt-get update 
sudo apt-get install python3-pyqt5
于 2020-07-08T09:14:59.607 回答
1

我也遇到了这个问题。这是因为您使用的pip是旧版本,您应该使用以下命令对其进行更新:

pip3 install setuptools wheel
pip3 install --upgrade pip
pip3 install --user pyqt5
于 2020-11-19T14:42:17.843 回答
0

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

sudo python3 -m pip install pyqt5==5.12 pyqtchart==5.12
于 2020-09-15T12:43:57.760 回答
0

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

于 2020-11-10T05:27:38.117 回答
0

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

No module named 'PyQt5.sip'

进而

python3 -m pip install PyQt5.sip

解决了这个问题

于 2021-03-02T15:17:00.120 回答