欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

Python3.6安装pyinstaller

程序员文章站 2024-02-10 17:01:28
...

很久之前装了python可是最近需要把xxx.py打包成xxx.exe,然后找了教程试了也无果,各种失败

首先在cmd下输入:python -m pip install PyWin32

然后在官网下载pyinstaller,下载前先看自己的python是32bit还是64bit:

python

Python3.6安装pyinstaller

在官网下载对应版本,解压,重命名(根据个人爱好)然后移动到python目录下:

Python3.6安装pyinstaller

打开cmd,进入刚刚复制的文件夹的目录,执行:python setup.py install

然后进入pyinstaller-pyinstaller文件夹下的script文件夹:

Python3.6安装pyinstaller

复制这个路径到环境变量

如果过程中出现未注册的提示信息复制以下代码运行后在安装

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