PALMisLIFE 討論區

搜索
鹹魚爸魅力四射舞蹈教室
查看: 10313|回復: 0
打印 上一主題 下一主題

[分享] 建立 Windows 下的 Qt + Python + PyQt 的環境

[複製鏈接]

218

主題

9

好友

3516

積分

我沒有頭銜!

  • TA的每日心情
    開心
    2011-8-12 07:38
  • 簽到天數: 110 天

    連續簽到: 3 天

    [LV.6]常住居民II

    文章
    2679
    跳轉到指定樓層
    1#
    發表於 2005-3-16 06:34 |只看該作者 |倒序瀏覽
    <!--StartFragment -->有人想在 Windows 上開發 Qt/Python/PyQt (Zaurus 用的使用者介面&nbsp;Qtopia,大概可算是 Qt 的子集合) 程式的嗎?可是 <a href="http://www.trolltech.com/">Trolltech</a> 在 Windows 上只有放出 Qt&nbsp;<a href="http://www.trolltech.com/products/qt/licensing.html">Commercial License</a> 的版本,如果也想要在 Windows 上實作 Qt/PyQt,這是一大麻煩。(在 Linux 上的Qt 是 GPL 授權的)<br /><br />不過有個 <a href="http://kde-cygwin.sourceforge.net/">kde-cygwin</a> 計劃,他們把 GPL license 的 Qt3 port 到 Windows 下,稱為 &quot;<a href="http://kde-cygwin.sourceforge.net/qt3-win32/index.php">Qt3/Windows Free Edition</a>&quot;,關於版權的部份,他們是這麼說:<blockquote>* Complete gpl licensed replacement for win32 environments<br /><br />* based on the gpl'ed Qt/X11 sources means there is no licensing problems with any commercial trolltech license</blockquote><span class="fullpost">底下我主要是依 <a href="http://kscraft.sourceforge.net/convert_xhtml.php?doc=pyqt-windows-install.xhtml">Getting GPLed Qt/PyQt Running on Windows</a> 及 <a href="http://kde-cygwin.sourceforge.net/qt3-win32/compile-mingw.php">Qt 3/Windows Free Edition: MinGW Compiling instructions</a> 的內容,外加自行東串串西串串,建立了 Windows 下的 Qt + Python + PyQt 的環境。<hr /><ol><li>安裝 MinGW:MinGW 是指 Minimalistic GNU for Windows,可以建立在 Windows 下的 GNU 編譯環境。<br /><br />只要下載並安裝 <a href="http://prdownloads.sf.net/mingw/MinGW-3.2.0-rc-3.exe?download">MinGW-3.2.0-rc-3.exe</a> 即可。(預設安裝路徑是 C:\MinGW)<br /><br />在安裝完後,在 C:\MinGW\bin 下有個 mingwm10.dll,把它複製一份到 C:\Windows\system32 下。<br /><br /></li><li>安裝 Qt:先下載 Qt3 的程式碼:到 <a href="http://webdev.cegit.de/snapshots/kde-cygwin/qt/">KDE-Cygwin snapshot area</a> 下載程式碼後,把它解開到 C:\qt-3 下 (用 WinRar 即可解開 .tar.bz2 的檔案)。<br /><br />編譯 Qt3:開 cmd 視窗,執行下列的指令<blockquote>set QTDIR=C:\qt-3<br />set MINGW=C:\MinGW<br />set PATH=%QTDIR%\bin;%MINGW%\bin;%PATH%<br />set QMAKESPEC=win32-g++<br />cd C:\qt-3<br />configure.bat -thread -gif -fast -verbose</blockquote>這會花蠻久的時間, 大概是要好幾個鐘頭,最好是找點事情做做,再回來看結果即可。<br /><br />如果有編譯成功,可以在 C:\qt-3\lib 下找到 qt-mt3.dll,把它複製一份到 C:\Windows\system32 下。<br /><br />也可到 C:\qt-3\bin 及 C:\qt-3\examples 目錄中,找到一些編譯成功的執行檔,試著執行看看。<br /><br /></li><li>安裝 Python:到 <a href="http://www.python.org/download/">Download Standard Python Software</a>,下載及安裝 Windows 版本的 Python。(預設安裝路徑是 C:\Python24)<br /><br />然後執行下列的指令,來得到相容於 MinGW 的 python 程式庫:<blockquote>cd C:\Python24\libs<br />pexports C:\WINDOWS\system32\python24.dll &gt; python24.def<br />dlltool --dllname python24.dll --def python24.def --output-lib libpython24.a</blockquote>可以檢查一下,在 C:\Python24\libs 會多了一個 libpython24.a 檔。<br /><br /></li><li>安裝 SIP:依 SIP 的說明,它是 &quot;a tool for automatically generating Python bindings for C and C++ libraries&quot;。<br /><br />因為原來 <a href="http://www.riverbankcomputing.co.uk/">Riverbank</a> 所放出的版本是針對 <a href="http://www.trolltech.com/">Trolltech</a> 的商業版本,所以要先 patch 一下,改下載<a href="http://prdownloads.sourceforge.net/kscraft/sip-4.1.1-patched.zip?download">這個 patch 過的版本</a>。下載後把檔案解開,放到 C:\Python24\sip-4.1.1 下。並執行下列指令:<blockquote>cd C:\Python24\sip-4.1.1<br />c:\Python24\python configure.py -p win32-g++ -l qt-mt<br />mingw32-make.exe<br />mingw32-make.exe install</blockquote></li><li>安裝 QScintilla:若不想安裝 eric3,這個部份可略過。先下載 <a href="http://www.riverbankcomputing.co.uk/qscintilla/download.php">QScintilla</a>,把它解開到 C:\Python24\qscintilla-1.62-gpl-1.5.1。並執行下列指令:<blockquote>cd C:\Python24\qscintilla-1.62-gpl-1.5.1\qt<br />qmake qscintilla.pro<br />mingw32-make.exe<br />copy qextscintilla*.h %QTDIR%\include<br />copy qscintilla*.qm %QTDIR%\translations</blockquote>如果編譯成功的話,在 C:\qt-3\lib 下會有 qscintilla.dll 檔,將它複製到 C:\Windows\system32 下。<br /><br /></li><li>安裝 PyQt:一樣是因為 <a href="http://www.riverbankcomputing.co.uk/">Riverbank</a> 所放出的版本是針對 <a href="http://www.trolltech.com/">Trolltech</a> 的商業版本,所以要先 patch 一下,改下載<a href="http://prdownloads.sourceforge.net/kscraft/PyQt-x11-gpl-3.13-patched.zip?download">這個 patch 過的版本</a>。下載後把檔案解開,放到 C:\Python24\PyQt-x11-gpl-3.13 下。並執行下列指令:<blockquote>cd C:\Python24\PyQt-x11-gpl-3.13<br />c:\Python24\python configure.py<br />mingw32-make.exe<br />mingw32-make.exe install</blockquote>PyQt 的編譯時間也很長,要有點耐心。在 C:\Python24\PyQt-x11-gpl-3.13\examples3 下有許多範例檔,可以試著執行看看。<br /><br /></li><li>安裝 eric3:eric3 是個用 python 編寫的 IDE 環境,除了 python 外,也支援許多的語言。先下載 <a href="http://prdownloads.sourceforge.net/eric-ide/eric-3.6.2.tar.gz?download">eric3</a>,把它解開到 C:\Python24\eric-3.6.2。並執行下列指令:<blockquote>cd C:\Python24\eric-3.6.2<br />c:\Python24\python install.py</blockquote>然後就可以用 &quot;C:\Python24\eric3.bat&quot; 執行 eric3 了。<br /><br />不過,我在執行時,每次啟動到 &quot;Setting up connections ...&quot; 時,程式就會當掉。目前還在瞭解原因中。<br /><br />後來 eric3 改用 eric-snapshot-20050309 版本,狀況有好一點,程式會在 UI 全部出來後才當掉。&gt;&quot;&lt;</li></ol>註 1:在步驟 2. 中的環境變數 QTDIR/MINGW/PATH,在步驟 3. 到 6. 中都需要。<br />註 2:整個編譯的時間相當的久,要有點耐心。<br />註 3:我習慣把一些 dll 檔移到 C:\Windows\system32 下,免得 PATH 會愈加愈長。(如果只有一、兩個 dll 的話)<br />註 4:雖然目前 eric3 還無法正常執行,不過其它的 PyQt 程式都可正常執行無誤。<br /><hr />在編譯完後,大概耗費了超過 1G 的空間,不過應該有很多部份是可以清掉的。</span>
    分享淘帖0 分享分享0 收藏收藏0 頂0 踩0
    您需要登錄後才可以回帖 登錄 | 免費註冊

    與站長聯繫| PALMisLIFE 掌上生活      下載:更快、更棒、更好玩

    GMT+8, 2024-6-3 06:21 , Processed in 0.036421 second(s), 33 queries , Gzip On.

    Powered by Discuz!

    © 2001-2012 Comsenz Inc. style by eisdl

    回頂部