在 Ubuntu 14.04 上构建 PyQt5 的问题

Issues with building PyQt5 on Ubuntu 14.04

我在 Ubuntu 14.04 上构建 PyQt5 时遇到一些问题。我正在使用一些对 Python 2.7 具有硬依赖性的代码;因此,我无法使用 Ubuntu 存储库中的 python3 包。进一步搜索 Ubuntu 的包显示 Python 2 pyqt5 有 dev 和 doc 包。但是,无需安装编写代码所需的库。

这促使我为 PyQt5 创建自定义构建。我从这里获得了 5.5 版的源代码:https://www.riverbankcomputing.com/software/pyqt/download5 我正在使用 Ubuntu 存储库提供的 sip(安装 kubuntu-desktop 需要 sip)。

我了解到 sip 版本很容易不匹配,所以我做了以下检查:

Python 2.7.6 (default, Jun 22 2015, 17:58:13) 
[GCC 4.8.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import sip
>>> print(sip, sip.SIP_VERSION_STR)
(<module 'sip' from '/usr/lib/python2.7/dist-packages/sip.so'>, '4.16.9')

并且:

$ sip -V
4.16.9

我还使用 Ubuntu 存储库提供的 Qt5 工具。这包括安装 qtdeclarative5-*(可能有点矫枉过正)和 qt5-default。以下是有关 qmake 的一些信息:

qmake --version
QMake version 3.0
Using Qt version 5.2.1 in /usr/lib/x86_64-linux-gnu

我目前安装了 PyQt4 并阅读了安装说明,只要它们都是针对相同版本的 sip 编译的就没问题。

下载后,我解压了 tarball 并尝试构建如下:

sudo ln -s  /usr/include/python2.7  /usr/local/include/python2.7
python configure.py --sip-incdir=/usr/include/python2.7/
make

配置输出似乎识别了正确的 sip 版本,我从 make 得到以下(看似)与 sip 相关的编译错误:

make[1]: Entering directory `~/Downloads/PyQt-gpl-5.5/QtWebKit'
g++ -c -m64 -pipe -fno-exceptions -O2 -Wall -W -D_REENTRANT -fPIC -DSIP_PROTECTED_IS_PUBLIC -Dprotected=public -DQT_NO_DEBUG -DQT_PLUGIN -DQT_WEBKIT_LIB -DQT_NETWORK_LIB -DQT_GUI_LIB -DQT_CORE_LIB -I/usr/lib/x86_64-linux-gnu/qt5/mkspecs/linux-g++-64 -I. -I. -I/usr/include/python2.7 -I/usr/include/qt5 -I/usr/include/qt5/QtWebKit -I/usr/include/qt5/QtNetwork -I/usr/include/qt5/QtGui -I/usr/include/qt5/QtCore -I. -o sipQtWebKitQWebSecurityOrigin.o sipQtWebKitQWebSecurityOrigin.cpp
~/Downloads/PyQt-gpl-5.5/QtWebKit/sipQtWebKitQWebSecurityOrigin.cpp: In function ‘PyObject* meth_QWebSecurityOrigin_addAccessWhitelistEntry(PyObject*, PyObject*)’:
~/Downloads/PyQt-gpl-5.5/QtWebKit/sipQtWebKitQWebSecurityOrigin.cpp:384:9: error: ‘SubdomainSetting’ is not a member of ‘QWebSecurityOrigin’
         QWebSecurityOrigin::SubdomainSetting a2;
         ^
~/Downloads/PyQt-gpl-5.5/QtWebKit/sipQtWebKitQWebSecurityOrigin.cpp:384:46: error: expected ‘;’ before ‘a2’
         QWebSecurityOrigin::SubdomainSetting a2;
                                              ^
~/Downloads/PyQt-gpl-5.5/QtWebKit/sipQtWebKitQWebSecurityOrigin.cpp:387:214: error: ‘a2’ was not declared in this scope
         if (sipParseArgs(&sipParseErr, sipArgs, "BJ1J1E", &sipSelf, sipType_QWebSecurityOrigin, &sipCpp, sipType_QString,&a0, &a0State, sipType_QString,&a1, &a1State, sipType_QWebSecurityOrigin_SubdomainSetting, &a2))
                                                                                                                                                                                                                      ^
~/Downloads/PyQt-gpl-5.5/QtWebKit/sipQtWebKitQWebSecurityOrigin.cpp:389:21: error: ‘class QWebSecurityOrigin’ has no member named ‘addAccessWhitelistEntry’
             sipCpp->addAccessWhitelistEntry(*a0,*a1,a2);
                     ^
~/Downloads/PyQt-gpl-5.5/QtWebKit/sipQtWebKitQWebSecurityOrigin.cpp: In function ‘PyObject* meth_QWebSecurityOrigin_removeAccessWhitelistEntry(PyObject*, PyObject*)’:
~/Downloads/PyQt-gpl-5.5/QtWebKit/sipQtWebKitQWebSecurityOrigin.cpp:417:9: error: ‘SubdomainSetting’ is not a member of ‘QWebSecurityOrigin’
         QWebSecurityOrigin::SubdomainSetting a2;
         ^
~/Downloads/PyQt-gpl-5.5/QtWebKit/sipQtWebKitQWebSecurityOrigin.cpp:417:46: error: expected ‘;’ before ‘a2’
         QWebSecurityOrigin::SubdomainSetting a2;
                                              ^
~/Downloads/PyQt-gpl-5.5/QtWebKit/sipQtWebKitQWebSecurityOrigin.cpp:420:214: error: ‘a2’ was not declared in this scope
         if (sipParseArgs(&sipParseErr, sipArgs, "BJ1J1E", &sipSelf, sipType_QWebSecurityOrigin, &sipCpp, sipType_QString,&a0, &a0State, sipType_QString,&a1, &a1State, sipType_QWebSecurityOrigin_SubdomainSetting, &a2))
                                                                                                                                                                                                                      ^
~/Downloads/PyQt-gpl-5.5/QtWebKit/sipQtWebKitQWebSecurityOrigin.cpp:422:21: error: ‘class QWebSecurityOrigin’ has no member named ‘removeAccessWhitelistEntry’
             sipCpp->removeAccessWhitelistEntry(*a0,*a1,a2);
                     ^
~/Downloads/PyQt-gpl-5.5/QtWebKit/sipQtWebKitQWebSecurityOrigin.cpp: In function ‘void* init_type_QWebSecurityOrigin(sipSimpleWrapper*, PyObject*, PyObject*, PyObject**, PyObject**, PyObject**)’:
~/Downloads/PyQt-gpl-5.5/QtWebKit/sipQtWebKitQWebSecurityOrigin.cpp:477:48: error: no matching function for call to ‘QWebSecurityOrigin::QWebSecurityOrigin(const QUrl&)’
             sipCpp = new QWebSecurityOrigin(*a0);
                                                ^
~/Downloads/PyQt-gpl-5.5/QtWebKit/sipQtWebKitQWebSecurityOrigin.cpp:477:48: note: candidates are:
In file included from ~/Downloads/PyQt-gpl-5.5/sip/QtWebKit/qwebsecurityorigin.sip:26:0:
/usr/include/qt5/QtWebKit/qwebsecurityorigin.h:64:5: note: QWebSecurityOrigin::QWebSecurityOrigin(QWebSecurityOriginPrivate*)
     QWebSecurityOrigin(QWebSecurityOriginPrivate* priv);
     ^
/usr/include/qt5/QtWebKit/qwebsecurityorigin.h:64:5: note:   no known conversion for argument 1 from ‘const QUrl’ to ‘QWebSecurityOriginPrivate*’
/usr/include/qt5/QtWebKit/qwebsecurityorigin.h:58:5: note: QWebSecurityOrigin::QWebSecurityOrigin(const QWebSecurityOrigin&)
     QWebSecurityOrigin(const QWebSecurityOrigin& other);
     ^
/usr/include/qt5/QtWebKit/qwebsecurityorigin.h:58:5: note:   no known conversion for argument 1 from ‘const QUrl’ to ‘const QWebSecurityOrigin&’
~/Downloads/PyQt-gpl-5.5/QtWebKit/sipQtWebKitQWebSecurityOrigin.cpp: At global scope:
~/Downloads/PyQt-gpl-5.5/QtWebKit/sipQtWebKitQWebSecurityOrigin.cpp:516:48: error: ‘AllowSubdomains’ is not a member of ‘QWebSecurityOrigin’
     {sipName_AllowSubdomains, static_cast<int>(QWebSecurityOrigin::AllowSubdomains), 21},
                                                ^
~/Downloads/PyQt-gpl-5.5/QtWebKit/sipQtWebKitQWebSecurityOrigin.cpp:517:51: error: ‘DisallowSubdomains’ is not a member of ‘QWebSecurityOrigin’
     {sipName_DisallowSubdomains, static_cast<int>(QWebSecurityOrigin::DisallowSubdomains), 21},
                                                   ^
make[1]: *** [sipQtWebKitQWebSecurityOrigin.o] Error 1
make[1]: Leaving directory `~/Downloads/PyQt-gpl-5.5/QtWebKit'
make: *** [sub-QtWebKit-make_first-ordered] Error 2

结果是我可以进行安装并获得一些我期望的功能;但是,我缺少 WebKit 小部件的一些必需功能。我希望我已经提供了足够的信息来描述我被困在哪里。我只是不好意思深入研究代码;但是,我假设答案实际上要简单得多。

提前致谢!

所以,

我开始在源码包中寻找编译失败的文件。在 sip 目录中有一个 sip 文件 QWebSecurityOrigin 包含以下内容:

%If (Qt_5_2_0 -)

    enum SubdomainSetting
    {
        AllowSubdomains,
        DisallowSubdomains,
    };

%End

我可以合理地期望包含此代码,因为 qmake 告诉我以下内容:

qmake --version
QMake version 3.0
Using Qt version 5.2.1 in /usr/lib/x86_64-linux-gnu

接下来我想查看 Qt 提供的 qwebsecurityorigin.h 以查看错误是否来自那里。我的安装在这里:/usr/include/qt5/QtWebKit/qwebsecurityorigin.h

#ifndef _WEBSECURITYORIGIN_H_
#define _WEBSECURITYORIGIN_H_

#include <QtCore/qurl.h>
#include <QtCore/qshareddata.h>

#include "qwebkitglobal.h"

namespace WebCore {
    class SecurityOrigin;
    class ChromeClientQt;
}

class QWebSecurityOriginPrivate;
class QWebDatabase;
class QWebFrame;

class QWEBKIT_EXPORT QWebSecurityOrigin {
public:
    static QList<QWebSecurityOrigin> allOrigins();
    static void addLocalScheme(const QString& scheme);
    static void removeLocalScheme(const QString& scheme);
    static QStringList localSchemes();

    ~QWebSecurityOrigin();

    QString scheme() const;
    QString host() const;
    int port() const;

    qint64 databaseUsage() const;
    qint64 databaseQuota() const;

    void setDatabaseQuota(qint64 quota);
    void setApplicationCacheQuota(qint64 quota);

    QList<QWebDatabase> databases() const;

    QWebSecurityOrigin(const QWebSecurityOrigin& other);
    QWebSecurityOrigin &operator=(const QWebSecurityOrigin& other);
private:
    friend class QWebDatabase;
    friend class QWebFrameAdapter;
    friend class WebCore::ChromeClientQt;
    QWebSecurityOrigin(QWebSecurityOriginPrivate* priv);

private:
    QExplicitlySharedDataPointer<QWebSecurityOriginPrivate> d;
};

注意,没有定义枚举。搜索 Qt 5.5 表明枚举应该在那里:http://doc.qt.io/qt-5/qwebsecurityorigin.html#SubdomainSetting-enum

最后,我记得我将 libqt5webkit 与大部分 Qt 库分开安装;所以,我对包进行了版本检查:

dpkg -s libqt5webkit5
Package: libqt5webkit5
Status: install ok installed
Priority: optional
Section: libs
Installed-Size: 34225
Maintainer: Ubuntu Developers <ubuntu-devel-discuss@lists.ubuntu.com>
Architecture: amd64
Multi-Arch: same
Source: qtwebkit-opensource-src
Version: 5.1.1-1ubuntu8

此输出与开发包几乎相同。所以这使得它看起来像大部分 Qt5 发行版,在 repos 中,是与 webkit 不同的版本。此外,如果 QWebKit 在 5.1.1 上,它会解释为什么缺少枚举,因为 sip 文件似乎表明它是 5.2.0 中的一个附加项。

所以我的解决方案是使用自动安装程序从 Qt 网站下载并安装 Qt 5.5(运行 使用 sudo,使用默认设置)。然后,我通过删除构建目录并再次解压源代码,重新开始使用 PyQt5 源代码:

python configure.py --sip-incdir=/usr/include/python2.7/ --qmake=/opt/Qt/5.5/gcc_64/bin/qmake 
make
sudo make install 

许可证不兼容;然而,使用错误输出快速搜索 pyqt5 configure.py 脚本,可能会提供一些有关配置和编译代码的信息。