How to execute python script using innoSetup function

I am trying to run a python script while creating setup from InnoSetup, but nothing works. Neither the Run section nor the Exec section of the Code Code section are different depending on what I call it.

Of course, I install Python during installation if it is not already present. Here is the Inno test code

[Setup] AppName=PyPy_client AppVersion=0.1 DefaultDirName={pf}\DeployPyPy UninstallDisplayIcon={app}\test.py Compression = zip/1 OutputDir=deploy SetupLogging = yes UsePreviousGroup=False DisableProgramGroupPage=yes PrivilegesRequired = admin [Files] Source: "D:\Dev\deploy_python\python-3.3.2.msi"; DestDir: "{app}\deploy"; Flags: ignoreversion Source: "D:\Dev\deploy_python\test.py"; DestDir: "{app}"; Flags: ignoreversion [Run] Filename: "msiexec"; Parameters: "/i ""{app}\deploy\python-3.3.2.msi"" /qb! ALLUSER=1 ADDLOCAL=ALL"; WorkingDir: "{app}\deploy"; Flags: 32bit; Check: python_is_installed Filename: "cmd.exe"; Parameters: "/c{code:GetPythonPath}\python.exe {app}\test.py"; WorkingDir: "{app}"; Flags: waituntilterminated [Code] function python_is_installed() : Boolean; var key : string; begin //check registry key := 'software\Python\PythonCore\3.3\InstallPath' Result := not RegValueExists(HKEY_LOCAL_MACHINE,Key,''); end; function GetPythonPath(Param : String) : String; var dir, key : String; begin dir := ''; key := 'software\Python\PythonCore\3.3\InstallPath' RegQueryStringValue(HKEY_LOCAL_MACHINE,key,'',dir); Result := dir end; procedure DeinitializeSetup(); var ResultCode: integer; begin if Exec('cmd.exe', ExpandConstant('/c' +GetPythonPath('')+ '\python.exe {app}\test.py'), '', SW_SHOW, ewWaitUntilTerminated, ResultCode) then Log(intTostr(Resultcode)); end; 

I am trying to use python.exe directly in the Run section and in the code: Exec, but not at all.

And of course, if I find test.py on the Windows command line, it works, and cmd.exe / cC: \ python33 \ python.exe C: \ app \ test.py also

Is someone already using python script successfully with innosetup?

The purpose of this is not to distribute the application py file, but to use the python script during the installation process to do some things.

Now I use CXfreeeze to create exe scripts, but I prefer to store only python script and not exe (for automation purposes)

for information, the python script test is fair:

 import ctypes def msgbox(message,title): ctypes.windll.user32.MessageBoxW(0, message, title, 0) def debug() : msgbox('test','test test') debug() 

EDIT *

As shown in @Tlama, I tried using the command in [Run] using OriginalUser instead of the admin mode set to inno (I use PrivilegesRequired = admin), but it does not work.

And since I install python for all users using the command line ALLUSERS = 1 existing users (or admin) can run python scripts.

I am also trying to change WorkDir in [Run] and in CODE: Exec, but all the probes give me the same ResultCode "2"

 Filename: "cmd.exe"; Parameters: "/c{code:GetPythonPath}\python.exe {app}\test.py"; WorkingDir: "{app}"; Flags: waituntilterminated Filename: "cmd.exe"; Parameters: "/c{code:GetPythonPath}\python.exe {app}\test.py"; WorkingDir: "{code:GetPythonPath}"; Flags: waituntilterminated Filename: "python.exe"; Parameters: "{app}\test.py"; WorkingDir: "{code:GetPythonPath}"; Flags: waituntilterminated Filename: "python.exe"; Parameters: "{app}\test.py"; WorkingDir: "{app}"; Flags: waituntilterminated 

in CODE:

  Log('Start pypy 1'); Exec('cmd.exe', ExpandConstant('/c' +GetPythonPath('')+ '\python.exe {app}\test.py'), GetPythonPath(''), SW_SHOW, ewWaitUntilTerminated, ResultCode); Log(intToStr(Resultcode)); Log('Start pypy 2'); Exec(GetPythonPath('')+ '\python.exe', ExpandConstant('{app}\test.py'), GetPythonPath(''), SW_SHOW, ewWaitUntilTerminated, ResultCode); Log(intToStr(Resultcode)); Log('Start pypy 3'); Exec('cmd.exe', ExpandConstant('/c' +GetPythonPath('')+ '\python.exe {app}\test.py'),ExpandConstant('{app}'), SW_SHOW, ewWaitUntilTerminated, ResultCode); Log(intToStr(Resultcode)); 
+6
source share
1 answer

I suspect that the problem is that python did not exist on the path when the installer started, and this path and other environment variables, such as PYTHONPATH, were not set in the area in which the program was running.

There are two different possibilities:

  • Call python with its absolute path to which it was installed, the absolute path for the script to execute, and explicitly set things like PYTHONPATH in your script if necessary - you can check this using the -E flag from the command line when testing your script.
  • Start a new shell that will get a new path, etc. in instead of the current one in the current one, that the current process is running - for this just change your command from python somescript.py to, (for windows), start python somescript.py should do the job well.
+3
source

Source: https://habr.com/ru/post/954682/


All Articles