瑕佸皢Python浠g爜杞崲涓哄彲鎵ц鐨.exe鏂囦欢锛屾湁澶氱鏂规硶銆備互涓嬫槸鍏朵腑涓ょ甯哥敤鐨勬柟寮忥細

浣跨敤PyInstaller搴擄紙闇瀹夎锛夛細

棣栧厛锛岀‘淇濆凡缁忓湪璁$畻鏈轰笂瀹夎浜哖ython鍜宲ip鍖呯鐞嗗櫒銆

鎵撳紑鍛戒护鎻愮ず绗︽垨缁堢锛屽苟杩愯浠ヤ笅鍛戒护鏉ュ畨瑁匬yInstaller搴擄細pip install pyinstaller

鍒涘缓涓涓悕涓"main.py"鐨凱ython鑴氭湰锛岃鑴氭湰鍖呭惈鎵闇鐨勫姛鑳姐

鍦ㄥ懡浠ゆ彁绀虹鎴栫粓绔腑瀵艰埅鍒板瓨鏀"main.py"鐨勭洰褰曘

杩愯浠ヤ笅鍛戒护鏉ョ敓鎴.exe鏂囦欢锛歱yinstaller --onefile main.py

PyInstaller浼氳嚜鍔ㄥ垎鏋愪緷璧栭」骞舵瀯寤轰竴涓崟鐙殑鍙墽琛屾枃浠躲傚畬鎴愬悗锛屽湪鍚屼竴鐩綍涓嬩細鐢熸垚涓涓猟ist鏂囦欢澶癸紝閲岄潰鍖呭惈浜嗙敓鎴愮殑.exe鏂囦欢銆

娉ㄦ剰锛氳繖绉嶆柟娉曢傜敤浜庡ぇ閮ㄥ垎鎯呭喌锛屼絾瀵逛簬澶嶆潅鐨勫簲鐢ㄧ▼搴忓彲鑳戒笉澶傚悎銆傛潵婧愶細OD浜戝叏缃戣惀閿www.odweb.cn

浣跨敤cx_Freeze搴擄紙闇瀹夎锛夛細

涓庡墠闈㈢浉鍚岋紝纭繚宸茬粡鍦ㄨ绠楁満涓婂畨瑁呬簡Python鍜宲ip鍖呯鐞嗗櫒銆

鎵撳紑鍛戒护鎻愮ず绗︽垨缁堢锛屽苟杩愯浠ヤ笅鍛戒护鏉ュ畨瑁卌x_Freeze搴擄細pip install cx-freeze

鍒涘缓涓涓悕涓"setup.py"鐨凱ython鑴氭湰锛屽唴瀹瑰涓嬶細

from distutils.core import setup
 
options = {
    'build_exe': {
        'includes': ['your_module'], # 娣诲姞闇瑕佸紩鍏ョ殑妯″潡
        'excludes': [], # 娣诲姞闇瑕佹帓闄ょ殑妯″潡
        'include_files': [] # 娣诲姞闇瑕佸寘鍚殑闈濸ython鏂囦欢
    }
}
 
setup(name='YourApp', version='0.1', description='Description of your app', author='Your Name', options=options)

鍦ㄥ懡浠ゆ彁绀虹鎴栫粓绔腑瀵艰埅鍒板瓨鏀"setup.py"鐨勭洰褰曘

杩愯浠ヤ笅鍛戒护鏉ョ敓鎴.exe鏂囦欢锛歱ython setup.py build

瀹屾垚鍚庯紝鍦ㄥ悓涓鐩綍涓嬩細鐢熸垚涓涓猙uild鏂囦欢澶癸紝閲岄潰鍖呭惈浜嗙敓鎴愮殑.exe鏂囦欢銆

娉ㄦ剰锛氳繖绉嶆柟娉曟洿鍔犵伒娲伙紝鍙互鏍规嵁闇姹傝繘琛岄厤缃紝浣嗕篃姣旇緝澶嶆潅銆

浠ヤ笂灏辨槸濡備綍灏唒ython 浠g爜鐢熸垚EXE鏂囦欢鐨勮缁嗗唴瀹癸紝鏇村淇℃伅璇峰叧娉∣D浜戝叾瀹冪浉鍏虫枃绔狅紒



鏈枃URL锛http://www.odweb.cn/news_show.html?id=273