Ubuntu 14.04 LTS 搭建 Python2.7+Qt 5.5+PyQt5开发环境

下面来记录一下我搭建python2.7 + Qt5.5 + PyQt5开发环境的过程,作为备忘。

Ubuntu 14.04LTS下默认是安装了python2.76和python3.4的,并且默认的python运行版本是2.76,我们可以在命令行下输入python命令来查看。

这里写图片描述 
如果你常在命令行下键入python命令的话,建议安装Ipython或者Bpython 
或者可以直接在命令行下输入 python -V 查看。 
PyQt虽然是基于Qt开发的工具包,但是并不包含Qt,所以要安装PyQt必须先安装Qt。 
Qt的安装需要满足一些基本的环境,在ubuntu下可以使用apt-get来配置基本的环境

sudo apt-get install build-essential libgl1-mesa-dev

满足以上条件之后就可以经行Qt的下载安装了。 
http://download.qt.io/archive/qt/5.5/5.5.1/选择适合自己平台的版本
下载Qt5.5.1在线安装器qt-opensource-linux-x64-5.5.1.run文件到电脑中,此时文件并没有可执行权限,需要使用chmod命令来将x权限添加给该文件。

$chmod a+x qt-opensource-linux-x64-5.5.1.run

接下来就是类似与Windows下的图形安装过程,在这里就不做截图解释了。 
使用在线安装器安装完毕之后Qt Creator也被安装在电脑中。 
这里写图片描述
安装好Qt之后,下一步要安装的是SIP,SIP也是安装PyQt的必备组件,我安装的是sip-4.19,下载地址https://www.riverbankcomputing.com/software/sip/download 。将下载好的sip的压缩包解压到你的电脑里,打开解压后的文件,你会在里边发现一个doc 文件夹,这个文件夹就是sip文档,里边有详细的不同平台下的安装教程,ubuntu14.04LTS下,只需要简单的三个步骤。

$python configure.py
$make
$sudo make install

安装完SIP之后就是PyQt的安装了,同样下载PyQt5安装包,下载地址https://www.riverbankcomputing.com/software/pyqt/download5 
下载之后与sip一样,解压后在解压包中寻找doc文档,里边有详细的安装教程,类似的三个命令

$python configure.py --qmake /home/cb/Qt5.5.1/5.5/gcc_64/bin/qmake
$make
$sudo make install

我在运行第一条命令的时候遇到了

error: 'qgeolocation.h' file not found
     #include <qgeolocation.h>
               ^
      1 error generated.
      make[1]: *** [sipQtPositioningcmodule.o] Error 1
      make: *** [sub-QtPositioning-make_first-ordered] Error 2

stackoverflow之后得以解决。问题链接 
解决方案是在/PyQt-gpl-5.5.1/QtPositioning下创建一个qgeolocation.h 文件,并将以下代码拷贝进去,保存,重新运行即可。

/****************************************************************************
**
** Copyright (C) 2015 The Qt Company Ltd.
** Contact: http://www.qt.io/licensing/
**
** This file is part of the QtPositioning module of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:LGPL21$
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and The Qt Company. For licensing terms
** and conditions see http://www.qt.io/terms-conditions. For further
** information use the contact form at http://www.qt.io/contact-us.
**
** GNU Lesser General Public License Usage
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 2.1 or version 3 as published by the Free
** Software Foundation and appearing in the file LICENSE.LGPLv21 and
** LICENSE.LGPLv3 included in the packaging of this file. Please review the
** following information to ensure the GNU Lesser General Public License
** requirements will be met: https://www.gnu.org/licenses/lgpl.html and
** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** As a special exception, The Qt Company gives you certain additional
** rights. These rights are described in The Qt Company LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
** $QT_END_LICENSE$
**
****************************************************************************/

#ifndef QGEOLOCATION_H
#define QGEOLOCATION_H

#include <QtCore/QSharedDataPointer>
#include <QtCore/QMetaType>
#include <QtPositioning/qpositioningglobal.h>

QT_BEGIN_NAMESPACE

class QGeoAddress;
class QGeoCoordinate;
class QGeoRectangle;
class QGeoLocationPrivate;

class Q_POSITIONING_EXPORT QGeoLocation
{
public:
    QGeoLocation();
    QGeoLocation(const QGeoLocation &other);

    ~QGeoLocation();

    QGeoLocation &operator=(const QGeoLocation &other);

    bool operator==(const QGeoLocation &other) const;
    bool operator!=(const QGeoLocation &other) const {
        return !(other == *this);
    }

    QGeoAddress address() const;
    void setAddress(const QGeoAddress &address);
    QGeoCoordinate coordinate() const;
    void setCoordinate(const QGeoCoordinate &position);
    QGeoRectangle boundingBox() const;
    void setBoundingBox(const QGeoRectangle &box);

    bool isEmpty() const;

private:
    QSharedDataPointer<QGeoLocationPrivate> d;
};

Q_DECLARE_TYPEINFO(QGeoLocation, Q_MOVABLE_TYPE);

QT_END_NAMESPACE

Q_DECLARE_METATYPE(QGeoLocation)

#endif

以上是PyQt5开发环境配置详细过程。

猜你喜欢

转载自blog.csdn.net/weixin_40047925/article/details/80089854
今日推荐