【问题标题】:How to install PyQt5 in Python 3 (Ubuntu 14.04)如何在 Python 3 (Ubuntu 14.04) 中安装 PyQt5
【发布时间】:2016-08-13 22:55:43
【问题描述】:

我需要将一些 Python2+PyQt4 的代码移植到 Python3+PyQt5。

我开始安装 pip3

sudo apt-get install python3-pip

效果很好。试过了

sudo pip3 install PyQt5
Downloading/unpacking PyQt5
  Could not find any downloads that satisfy the requirement PyQt5
Cleaning up...
No distributions at all found for PyQt5

网上我找到以下步骤:

http://pyqt.sourceforge.net/Docs/PyQt5/installation.html

但是他们太多了。在 Ubuntu 14.04 中安装 PyQt5 和 Python3 的最简单方法是什么?

【问题讨论】:

  • pip install pyqt5 工作得很好
  • 安装过程顺利。但是出现运行时错误 QtCore.so: undefined symbol: PySlice_AdjustIndices

标签: python-3.x ubuntu-14.04 pyqt5


【解决方案1】:

为什么不简单地通过 apt-get 安装它?

sudo apt-get install python3-pyqt5

否则您必须手动编译 PyQt(可能还有 Qt),这很麻烦。

【讨论】:

  • 我不知道这是可能的。
  • 这个命令是安装python3.4,请问如何获取python3.7?
【解决方案2】:

我在这里记录了使用 qt 设计器和代码生成安装 pyqt5 的步骤:https://gist.github.com/ujjwal96/1dcd57542bdaf3c9d1b0dd526ccd44ff

安装

pip3 install --user pyqt5  
sudo apt-get install python3-pyqt5  
sudo apt-get install pyqt5-dev-tools
sudo apt-get install qttools5-dev-tools

配置从终端运行

$ qtchooser -run-tool=designer -qt=5

将以下内容写入/usr/lib/x86_64-linux-gnu/qt-default/qtchooser/default.conf

/usr/lib/x86_64-linux-gnu/qt5/bin
/usr/lib/x86_64-linux-gnu

代码生成

创建 uic.py 文件。

#!/usr/bin/python3

import subprocess
import sys

child = subprocess.Popen(['pyuic5' ,'-x',sys.argv[1]],stdout=subprocess.PIPE)

print(str(child.communicate()[0],encoding='utf-8'))

$ chmod +x uic.py

创建符号链接:

$ sudo ln uic.py "/usr/lib/x86_64-linux-gnu/qt5/bin/uic"

桌面入口

[Desktop Entry]
Name=Qt5 Designer
Icon=designer
Exec=/usr/lib/x86_64-linux-gnu/qt5/bin/designer
Type=Application
Categories=Application
Terminal=false
StartupNotify=true
Actions=NewWindow

Name[en_US]=Qt5 Designer

[Desktop Action NewWindow]
Name=Open a New Window
Exec=/usr/lib/x86_64-linux-gnu/qt5/bin/designer

使用 .desktop 扩展名保存在 ~/.local/share/application

【讨论】:

  • pip3 install --user pyqt5 很可能会抛出 Could not find a version that satisfies the requirement sip>=4.19.1。我正在从全新的 Linux 安装中安装它。
  • 你把 uic.py 文件放在哪里了?
【解决方案3】:
  • sudo apt-get install python3-pip
  • sudo pip3 安装 PyQt5

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-10-05
    • 2014-12-10
    • 2017-09-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多