python創建exe文件

date:2019/9/14 22:10

需求:python如何創建exe文件並執行呢

1、安裝包pyinstaller

pip install pyinstaller

2、創建一個簡單的py文件

import sys

# 輸出第一個參數
img_path = sys.argv[1]
print('輸出路徑:', img_path)

3、打開控制檯

pyinstaller -F demo1.py

參數說明:-F 打包成當個文件可以添加這個參數,如果是多個py,就不要寫這個參數

可以看到該目錄的文件有文件夾__pycache__、文件夾build、文件夾dist、demo1.py、demo1.spec

exe文件就存在dist文件中

4、運行exe文件

在windows系統:進入該目錄,運行.\demo1.exe

D:\數據集下載\aaa\dist>.\demo1.exe hello
輸出路徑: hello

在Linux系統:進入該目錄,運行./demo1

(mxnet) user@ubuntu:~/cf/generator_exefile/dist$ ./demo1 python
輸出路徑: python

5、添加圖標

從網上下載圖片,轉換爲ico格式,可以通過http://www.bitbug.net將圖片轉換爲ico圖標

pyinstaller -F -i a.ico demo1.py

在生成的dist文件夾下可以看到有圖標的demo1.exe文件

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章