python打包exe程式

2021-06-28 19:40:26 字數 1866 閱讀 7345

1.安裝py2exe

2.編寫setup.py**如下:

#-*-coding: utf-8-*-

from distutils.core import setup

import py2exe

# powered by ***

includes =

options = }

setup(

options = options,

description = "my py2exe",

zipfile=none,

console=,

)

具體的option和其它的選項是什麼含意可以search一下,網上非常多的資料,我就不贅述了

下一步,執行命令:

python setup.py py2exe
編譯完成後會在當前目錄下生成乙個dist目錄,裡面有park.exe檔案,不過執行時並不成功

出現如下錯誤:

1 traceback (most recent call last):

2 file "park.py", line 4, in 3 file "zipextimporter.pyo", line 82, in load_module

4 file "pyquery.pyo", line 9, in 5 file "zipextimporter.pyo", line 82, in load_module

6 file "cssselectpatch.pyo", line 6, in 7 file "zipextimporter.pyo", line 82, in load_module

8 file "lxml\cssselect.pyo", line 8, in 9 file "zipextimporter.pyo", line 98, in load_module

10 file "lxml.etree.pyx", line 72, in init lxml.etree (src/lxml/lxml.etree.c:156121)

11 importerror: no module named _elementpath

在網上找了下解決方案,問題出在了lxml庫。

不能正確找到路徑,因為是lxml第三方庫,要多加一條指令指定路徑;將編譯命令改為

python setup.py py2exe -p lxml,gzip
這裡還多加了gzip,原因同lxml一樣

最後執行生成的檔案有park.exe和python27.dll,只要把這兩個檔案放到乙個資料夾,然後就可以在任何一台電腦上執行啦。

1. 安裝cxfreeze

2. 在python的安裝目錄下,找到cxfreeze.bat檔案(我的安裝路徑是 

c:\python34\scripts\cxfreeze.bat

).   修改檔案內容中的路徑為自己本機python的安裝路徑,儲存退出。

3.打包

cd進入python安裝目錄的scripts目錄下,執行打包命令

cd c:\python34\scripts
解釋一下:

--target-dir dirname 是在當前路徑下建立乙個名為dirname的資料夾,打包後的exe檔案位於該資料夾下

--base-name=win32gui 是指建立出來的exe是基於win32平台的gui程式(如果源py檔案是圖形化介面應用,則生成exe執行時沒有附加的cmd黑框框控制台)。

python 打包成exe程式

1.需要安裝 py2exe 2.示例 exetest.py 建立乙個gui介面,只用乙個標籤和按鈕,無功能 from tkinter import win tk label label win,text hello btn button win,text click label.pack btn.p...

python程式打包EXE檔案

目的 解決pyinstaller打包程式啟動慢的缺點 安裝pyinstaller pip install pyinstaller使用pyinstaller打包 python程式 pyinstaller命令解釋 不能使用 f,打包成獨立exe檔案 pyinstaller w i 圖示.ico 路徑 檔...

把python程式打包成exe程式

python64位和32位打包出來的程式不能通用 需要注意的是,pyinstaller打包的執行檔案,只能在和打包機器系統同樣的環境下。也就是說,不具備可移植性,若需要在不同系統上執行,就必須針對該平台進行打包。摘自 我在64 win7系統 64位的python 打包程式,在win7 32和winx...