很久之前裝了python可是最近需要把xxx.py打包成xxx.exe,然後找了教程試了也無果,各種失敗
首先在cmd下輸入:python -m pip install PyWin32
然後在官網下載下傳pyinstaller,下載下傳前先看自己的python是32bit還是64bit:
python
在官網下載下傳對應版本,解壓,重命名(根據個人愛好)然後移動到python目錄下:
打開cmd,進入剛剛複制的檔案夾的目錄,執行:python setup.py install
然後進入pyinstaller-pyinstaller檔案夾下的script檔案夾:
複制這個路徑到環境變量
如果過程中出現未注冊的提示資訊複制以下代碼運作後在安裝
import sys
from winreg import *
# tweak as necessary
version = sys.version[:3]
installpath = sys.prefix
regpath = "SOFTWARE\\Python\\Pythoncore\\%s\\" % (version)
installkey = "InstallPath"
pythonkey = "PythonPath"
pythonpath = "%s;%s\\Lib\\;%s\\DLLs\\" % (
installpath, installpath, installpath
)
def RegisterPy():
try:
reg = OpenKey(HKEY_CURRENT_USER, regpath)
except EnvironmentError as e:
try:
reg = CreateKey(HKEY_CURRENT_USER, regpath)
SetValue(reg, installkey, REG_SZ, installpath)
SetValue(reg, pythonkey, REG_SZ, pythonpath)
CloseKey(reg)
except:
print("*** Unable to register!")
return
print("--- Python", version, "is now registered!")
return
if (QueryValue(reg, installkey) == installpath and
QueryValue(reg, pythonkey) == pythonpath):
CloseKey(reg)
print("=== Python", version, "is already registered!")
return
CloseKey(reg)
print("*** Unable to register!")
print("*** You probably have another Python installation!")
if __name__ == "__main__":
RegisterPy()