Mac OS X 10.11.1下搭建Python3.4 + PyQt5.5.1 +Eric6.1.1開發平臺

因爲Python易學、開源、面向對象、可移植性高、庫豐富的特色,近期開始學習Python。百度瞭解了各款Python IDE後,仍是認爲Eric比較適合我,因此踏上了安裝Eric坎坷之路,從選定工具到安裝成功一共花費了8天時間,從Windows到Linux再到Mac,挨個折騰了一遍,Windows的搭建比較簡單,下載好相應版本直接運行exe就好了,Linux和Mac下我都是用源碼包安裝的,因此遇到了很多問題最後,終於在Mac上研究明白了。把搭建的整個過程寫下來,和與我同樣的小白分享。html

PS:Mac與Linux的搭建沒什麼區別,Linux下的也可參考本文,因爲我安裝過xcode因此gcc我沒有再單獨去安裝,沒有的請根據提示自行安裝。python

1、準備文件

  1. Python3.4
  2. Qt5.5.1
  3. SIP4.17
  4. QScintilla2.9.1
  5. PyQt5.5.1

2、安裝過程

1.安裝Python3.4

            從官網(https://www.python.org/download)下載相應平臺的版本安裝便可編程

        注意!!vim

 

  • 若是您是iOS開發者,請不要刪除python2.7,由於Xcode使用的2.7的腳本,不支持3以上版本!!!
2.安裝Qt5.5.1

            從官網(http://qt-project.org/downloads)下載相應平臺的版本安裝便可,路徑設成默認(/Users/*/Qt5.5.1)便可api

            安裝完成須要將Qt5添加到環境變量~/.bash_profile           xcode

    

1 vim ~/.bash_profile

 

 

    將下面兩行添加進去bash

1 PATH="/Users/*/Qt5.5.1/5.5/clang_64/bin:${PATH}"
2 export PATH

 

3.安裝SIP4.14

            下載地址:http://www.riverbankcomputing.com/software/sip/download            app

1 tar -zxvf sip-4.17.tar.gz  
2 cd sip-4.17
3 python3 configure.py  
4 make  && date # 加&&date是我的習慣,make成功會顯示時間
5 sudo make install  && date # 必定要加sudo

 

4.安裝QScintilla/Qt4Qt5
      下載地址:http://www.riverbankcomputing.com/software/qscintilla/download

             QScintilla2 文件中有3個文件夾的內容要分別安裝:Qt4Qt5,designer-Qt4Qt5和Python。python2.7

             Qt4Qt5文件夾要在PyQt以前安裝,designer-Qt4Qt5和Python要在PyQt以後安裝,順序必定要注意!!ide

1 cd ./QScintilla-gpl-2.9.1/Qt4Qt5
2 qmake qscintilla.pro
3 make && date
4 sudo make install && date

 

5.安裝PyQt5.5.1

            下載地址:https://www.riverbankcomputing.com/software/pyqt/download5

            因爲是安裝在Python的site-packages裏,因此要首先肯定包的位置

1 python3
2 Python3.4.4(v3.4.4:737efcadf5a6,Dec192015,20:38:52)
3 [GCC 4.2.1(AppleInc. build 5666)(dot 3)] on darwin
4 Type"help","copyright","credits" or "license"for more information.
5 >>> import site
6 >>> site.getsitepackages()
7 ['/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages','/Library/Frameworks/Python.framework/Versions/3.4/lib/site-python','/Library/Python/3.4/site-packages']

 

          知道了位置開始編譯

 

1 cd PyQt-gpl-5.5.1
2 $python3 configure.py -q /Users/**/Qt5.5.1/5.5/clang_64/bin/qmake -d /Library/Python/3.4/site-packages/ #-q 後面的是qmake的位置,-d 後面是Python包的位置
3 make && date

 

 

 

注意!!

我在執行make的時候出了一個這樣的錯誤

1 /Users/Kallan/Documents/Python開發/PyQt-gpl-5.5.1/sip/QtPositioning/qgeolocation.sip:28:10: fatal error:
2          'qgeolocation.h' file not found
3     #include <qgeolocation.h>
4             ^
5     1 error generated.
6 make[1]:***[sipQtPositioningcmodule.o]Error1
7 make:***[sub-QtPositioning-make_first-ordered]Error2

 

解決方法:

/PyQt-gpl-5.5.1/QtPositioning文件夾下建立一個頭文件qgeolocation.h,把下面的內容複製進去

 1     /****************************************************************************
 2     **
 3     **Copyright(C)2015TheQtCompanyLtd.
 4     **Contact: http://www.qt.io/licensing/
 5     **
 6     **This file is part of the QtPositioning module of the QtToolkit.
 7     **
 8     ** $QT_BEGIN_LICENSE:LGPL21$
 9     **CommercialLicenseUsage
10     **Licensees holding valid commercial Qt licenses may use this file in
11     ** accordance with the commercial license agreement provided with the
12     **Softwareor, alternatively,in accordance with the terms contained in
13     ** a written agreement between you andTheQtCompany.For licensing terms
14     **and conditions see http://www.qt.io/terms-conditions.For further
15     ** information use the contact form at http://www.qt.io/contact-us.
16     **
17     ** GNU LesserGeneralPublicLicenseUsage
18     **Alternatively, this file may be used under the terms of the GNU Lesser
19     **GeneralPublicLicense version 2.1or version 3as published by the Free
20     **SoftwareFoundationand appearing in the file LICENSE.LGPLv21and
21     ** LICENSE.LGPLv3 included in the packaging of this file.Please review the
22     ** following information to ensure the GNU LesserGeneralPublicLicense
23     ** requirements will be met: https://www.gnu.org/licenses/lgpl.html and
24     ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
25     **
26     **As a special exception,TheQtCompany gives you certain additional
27     ** rights.These rights are described inTheQtCompany LGPL Exception
28     ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
29     **
30     ** $QT_END_LICENSE$
31     **
32     ****************************************************************************/
33     #ifndef QGEOLOCATION_H
34     #define QGEOLOCATION_H
35     #include <QtCore/QSharedDataPointer>
36     #include <QtCore/QMetaType>
37     #include <QtPositioning/qpositioningglobal.h>
38     QT_BEGIN_NAMESPACE
39     classQGeoAddress;
40     classQGeoCoordinate;
41     classQGeoRectangle;
42     classQGeoLocationPrivate;
43     class Q_POSITIONING_EXPORT QGeoLocation
44     {
45     public:
46        QGeoLocation();
47        QGeoLocation(const QGeoLocation&other);
48        ~QGeoLocation();
49        QGeoLocation&operator=(const QGeoLocation&other);
50        bool operator==(const QGeoLocation&other) const;
51        bool operator!=(const QGeoLocation&other) const {
52            return!(other ==*this);
53        }
54        QGeoAddress address() const;
55        void setAddress(const QGeoAddress&address);
56        QGeoCoordinate coordinate() const;
57        void setCoordinate(const QGeoCoordinate&position);
58        QGeoRectangle boundingBox() const;
59        void setBoundingBox(const QGeoRectangle&box);
60        bool isEmpty() const;
61     private:
62        QSharedDataPointer<QGeoLocationPrivate> d;
63     };
64     Q_DECLARE_TYPEINFO(QGeoLocation, Q_MOVABLE_TYPE);
65     QT_END_NAMESPACE
66     Q_DECLARE_METATYPE(QGeoLocation)
67     #endif

 

繼續!

1 make && date
2 sudo make install && date

 

6.安裝QScintilla/Python
1 cd /QScintilla-gpl-2.9.1/Python
2 python3 configure.py --pyqt=PyQt5-d /Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/PyQt5--pyqt-sipdir=/Library/Frameworks/Python.framework/Versions/3.4/share/sip/PyQt5-v /Library/Frameworks/Python.framework/Versions/3.4/share/sip/PyQt5
3 make && date
4 sudo make install && date

 

若是在Python裏import不會報錯,即表明安裝成功,可繼續往下進行

1 python3
2 Python3.4.4(v3.4.4:737efcadf5a6,Dec192015,20:38:52)
3 [GCC 4.2.1(AppleInc. build 5666)(dot 3)] on darwin
4 Type"help","copyright","credits" or "license"for more information.
5 >>> import PyQt5.Qsci
6 >>> exit()

 

7.安裝QScintilla/designer-Qt4Qt5        
1 cd /QScintilla-gpl-2.9.1/designer-Qt4Qt5
2 qmake designer.pro
3 make && date
4 sudo make install && date

 

8.安裝Eric6

下載地址:http://sourceforge.net/projects/eric-ide/files/eric6/stable/

下載其中的eric6-6.1.1.tar主文件和eric6-i18n-zh_CN.GB2312-6.1.1.tar中文語言包。

將兩個文件提取出來,將中文語音包的eric複製到主文件內合併

1 cd eric6-6.1.1
2 sudo python3 install.py 

 

配置Eric6

一、選擇Eric6-> preference -> Editor -> Autocompation。勾選全部選框;

2.Editor -> QScintilla 。勾上左右的兩個選框,而後在下面source中,選擇from Document and API files;

3.Editor -> APIs。勾選Complie APIs Autocompation,在Language中,選擇python3。點面下面的Add from installed APIs按鈕,選擇住須要的.api文件。最後點擊Compile APIs;

四、Interface -> Interface。Language選擇中文,重啓生效。

大功告成!

3、曾經遇到的問題

1.安裝QScintilla designer-Qt4Qt5時報錯!

 

1 root@kallan:/media/kallan/D盤/編程學習/python/QScintilla-gpl-2.9.1/designer-Qt4Qt5# qmake -qt5 designer.pro Project ERROR: Unknown module(s) in QT: designer

 

 

 

緣由: Qt沒有安裝好

2.安裝QScintilla Python時報錯!
1 python3 configure.py --pyqt=PyQt5-d /Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/PyQt5--pyqt-sipdir=/Library/Frameworks/Python.framework/Versions/3.4/share/sip/PyQt5--qsci-sipdir=/Library/Frameworks/Python.framework/Versions/3.4/share/sip/PyQt5
2 Error:Make sure you have a working sip on your PATH or use the --sip argument
3 to explicitly specify a working sip.

 

緣由:沒有安裝SIP

3.安裝QScintilla Python時報錯!
 1 python3 configure.py --pyqt=PyQt5
 2 ConfiguringQScintilla2.9.1...
 3 QScintilla2.9.1 is being used.
 4 TheQScintilla.sip files will be installed in/usr/share/sip/PyQt5.
 5 TheQScintilla module will be installed in
 6 /usr/lib/python3/dist-packages/PyQt5.
 7 PyQt5.3.1 is being used.
 8 Qt5.3.1 is being used.
 9 sip 4.16.2 is being used.
10 The sip executable is /usr/bin/sip.
11 TheQScintilla module is being built with 'protected' redefined as 'public'.
12 TheQScintilla API file will be installed in/usr/share/qt5/qsci/api/python.
13 Generating the C++ source for the Qsci module...
14 Error:Unable to create the C++ code.

 

緣由:安裝順序錯誤——先安裝的PyQt5,然後安裝的QScintilla Qt4Qt5

4.QScintilla的Python安裝完成可是在Python中import時報錯!
1 >>> import PyQt5.Qsci
2 Traceback(most recent call last):
3 File"<stdin>", line 1,in<module>
4 ImportError: dlopen(/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/PyQt5/Qsci.so,2):Library not loaded:@rpath/QtPrintSupport.framework/Versions/5/QtPrintSupport
5 Referenced from:/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/PyQt5/Qsci.so
6 Reason: image not found

 

5.安裝Eric報錯!
1 python3 install.py
2 Checking dependencies
3 PythonVersion:3.4.4
4 FoundPyQt5
5 Sorry, please install QScintilla2 and
6 its PyQt5/PyQt4 wrapper.
7 Error: dlopen(/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/PyQt5/Qsci.so,2):Library not loaded:@rpath/QtPrintSupport.framework/Versions/5/QtPrintSupport
8 Referenced from:/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/PyQt5/Qsci.so
9 Reason: image not found

 

4和5問題的緣由是同樣的,QScintilla的Python沒有安裝成功

 


本文版權歸做者和博客園共有,歡迎轉載,但未經做者贊成必須保留此段聲明,且在文章頁面明顯位置給出原文鏈接,不然保留追究法律責任的權利。

相關文章
相關標籤/搜索