Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/307.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 如何动态查找使用PyInstaller编译的exe的路径?_Python_Windows_Operating System_Pyinstaller - Fatal编程技术网

Python 如何动态查找使用PyInstaller编译的exe的路径?

Python 如何动态查找使用PyInstaller编译的exe的路径?,python,windows,operating-system,pyinstaller,Python,Windows,Operating System,Pyinstaller,我需要在运行PyInstaller时添加一个用PyInstaller编译的exe作为启动。 问题是,我不知道如何动态查找使用PyInstaller编译的exe的路径 我在脚本中使用了此函数: def AddToRegistry(): # in python __file__ is the instant of # file path where it was executed # so if it was executed from desktop, # the

我需要在运行PyInstaller时添加一个用PyInstaller编译的exe作为启动。 问题是,我不知道如何动态查找使用PyInstaller编译的exe的路径

我在脚本中使用了此函数:

def AddToRegistry():

    # in python __file__ is the instant of
    # file path where it was executed
    # so if it was executed from desktop,
    # then __file__ will be
    # c:\users\current_user\desktop
    pth = os.path.join(os.path.dirname(__file__))

    # name of the python file with extension
    s_name="\\"+os.path.basename(__file__)


    # joins the file name to end of path address
    address=pth+s_name

    # key we want to change is HKEY_CURRENT_USER
    # key value is Software\Microsoft\Windows\CurrentVersion\Run
    key = reg.HKEY_CURRENT_USER
    key_value = "Software\Microsoft\Windows\CurrentVersion\Run"

    # open the key to make changes to
    open = reg.OpenKey(key,key_value,0,reg.KEY_ALL_ACCESS)

    # modifiy the opened key
    reg.SetValueEx(open,"any_name",0,reg.REG_SZ,address)

    # now close the opened key
    reg.CloseKey(open)
这样,程序会找到.py文件路径,但找不到exe路径。
我需要在启动时添加exe而不是.py。

我建议您使用安装程序(msi或类似InnoSetup的东西),这样更简单、更健壮。PyIntaller文档中介绍了如何获取该文件。