Issues with building PyQt5 on Ubuntu 14.04

2019-04-29 20:59发布

问题:

I am having some problems building PyQt5 on Ubuntu 14.04. I am working with some code that has a hard dependency on Python 2.7; so, I am unable to use the python3 packages from Ubuntu's repository. Further searches of Ubuntu's packages reveal that there are dev and doc packages for Python 2 pyqt5. But, nothing to install the libraries necessary to write code.

This has led me to creating a custom build for PyQt5. I obtained the source for version 5.5 from here: https://www.riverbankcomputing.com/software/pyqt/download5 and I am using sip as provided by the Ubuntu repos (installation of kubuntu-desktop requires sip).

I read that its easy to have mismatched versions of sip so I did the following check:

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')

And:

$ sip -V
4.16.9

Also I am using the Qt5 tools provided by the Ubuntu repos. This included installing qtdeclarative5-* (probably overkill) and qt5-default. Here is some information about qmake:

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

I currently have PyQt4 installed and read on the installation notes that this would be fine as long as they were both compiled against the same version of sip.

After downloading, I unpacked the tarball and attempted a build as follows:

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

The configuration output appeared to identify the correct version of sip and I get the following (seemingly) sip related compile errors from make:

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

The outcome is that I can make install and get some of the functionality that I'd expect; however, I am missing some required functionality with the WebKit widgets. I hope that I have supplied enough information to describe where i'm stuck. I feel just shy of digging into the code; however, I'm assuming that the answer is actually much simpler.

Thanks in advance!

回答1:

So,

I started digging through the source package for the file that is failing to be compiled. In the sip directory there is a sip file QWebSecurityOrigin that contains the following:

%If (Qt_5_2_0 -)

    enum SubdomainSetting
    {
        AllowSubdomains,
        DisallowSubdomains,
    };

%End

I can reasonably expect that this code be included as qmake tells me the following:

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

Next I wanted to look into the qwebsecurityorigin.h that was provided by Qt to see if the error could come from there. Mine is installed here: /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;
};

Note, no enum is defined. A search of Qt 5.5 suggests that the enum should be there: http://doc.qt.io/qt-5/qwebsecurityorigin.html#SubdomainSetting-enum

Finally, had recalled that I installed libqt5webkit separately from the bulk of the Qt libraries; so, I did a version check on the package:

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

This output is almost identical for the dev package. So this makes it appear as the bulk of the Qt5 distribution, in the repos, is on a different version than webkit. Furthermore, if QWebKit is on 5.1.1, it would explain why the enum is missing as the sip file seems to suggest it was an addition in 5.2.0.

So my solution was to download and install Qt 5.5 from the Qt website using the automated installer (ran with sudo, using defaults). I then started fresh with the PyQt5 source by blowing away the build directory and unpacking source again:

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

The licenses are not compatible; however, a quick search through the pyqt5 configure.py script, using the error output, may give some insight into getting the code configured and compiling.