Python does exe need to pay attention to 32-bit and 64-bit issues

1. The first method was to download py2exe, but when it was executed in cmd, it kept saying "initialization failed" and gave up.

Later, I know why not use py2exe?

Because py2exe can only run under the same system after packaging; packaging also requires packaging various files such as dll files

After pyInstall is packaged, there is only one exe running file

2. So use pyInstaller method

Just install it directly in pip

3. Also install pywin32, I encountered a problem when installing this

pywin32 download address 
[ https://sourceforge.net/projects/pywin32/files/pywin32/Build%20221/] 
Write picture description here

It stands to reason that the downloaded .exe file is installed directly. By default, the next step is to find the local python directory by himself, but there is a problem

Python version 2.7 required, which was not found in the registry.

solve

Desktop creation file: register.py

# script to register Python 2.0 or later for use with win32all
# and other extensions that require Python registry settings
#
# written by Joakim Loew for Secret Labs AB / PythonWare
#
# source:
# http://www.pythonware.com/products/works/articles/regpy20.htm
#
# modified by Valentine Gogichashvili as described in http://www.mail-archive.com/[email protected]/msg10512.html

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()

After saving, enter the desktop directory in cmd and execute python registed.py 
to re-run the installation of pywin32 
(additional, pywin32 must be installed to the corresponding version, python is 32-bit, the computer is 64-bit, and the installed pywin32 must be 32 Position)

Guess you like

Origin blog.csdn.net/woaisjm/article/details/112816716