2

Is it possible to distribute a Python library I made using Inno Setup instead of Python distutils? I am talking about the distutils Windows installers. If so, how? The modules are at https://code.google.com/p/mathworks/.

EDIT: I have made some progress with lots of Googling. Here is my setup script, but it can't locate Python. maybe somebody can help.

; Script generated by the Inno Setup Script Wizard.
; SEE THE DOCUMENTATION FOR DETAILS ON CREATING INNO SETUP SCRIPT FILES!

[Setup]
; NOTE: The value of AppId uniquely identifies this application.
; Do not use the same AppId value in installers for other applications.
; (To generate a new GUID, click Tools | Generate GUID inside the IDE.)
AppId={{3B6685C2-D478-4410-B973-57FA36A6DA6D}
AppName=Mathworks
AppVersion=1.3
;AppVerName=Mathworks 1.3
AppPublisherURL=https://code.google.com/p/mathworks/
AppSupportURL=https://code.google.com/p/mathworks/
AppUpdatesURL=https://code.google.com/p/mathworks/
DefaultDirName={code:GetDirName}
DisableDirPage=yes
DefaultGroupName=My Program
DisableProgramGroupPage=yes
LicenseFile=C:\Users\Ryan\Documents\mathworks-git\LICENSE_1_0.txt
OutputDir=C:\Users\Ryan\Desktop
OutputBaseFilename=mathworks-mwver
Compression=lzma
SolidCompression=yes

[Languages]
Name: "english"; MessagesFile: "compiler:Default.isl"

[Files]
Source: "C:\Users\Ryan\Documents\mathworks-git\__init__.py"; DestDir: "{app}"; Flags: ignoreversion
Source: "C:\Users\Ryan\Documents\mathworks-git\exponent.py"; DestDir: "{app}"; Flags: ignoreversion
Source: "C:\Users\Ryan\Documents\mathworks-git\LICENSE_1_0.txt"; DestDir: "{app}"; Flags: ignoreversion
Source: "C:\Users\Ryan\Documents\mathworks-git\multiples.py"; DestDir: "{app}"; Flags: ignoreversion
Source: "C:\Users\Ryan\Documents\mathworks-git\ptheorem.py"; DestDir: "{app}"; Flags: ignoreversion
Source: "C:\Users\Ryan\Documents\mathworks-git\shapes.py"; DestDir: "{app}"; Flags: ignoreversion
; NOTE: Don't use "Flags: ignoreversion" on any shared system files

[Code]
var CancelWithoutPrompt: boolean;

function InitializeSetup() : Boolean;
begin
  CancelWithoutPrompt := false;
  result := true;
end;

function GetDirName(Value: string): string;
var          
  InstallPath: string;
begin
  if RegQueryStringValue(HKLM, 'SOFTWARE\Python\PythonCore\2.7\InstallPath', '(Default)', InstallPath) then
    BEGIN
    Result := InstallPath
  END else
  if RegQueryStringValue(HKCU, 'SOFTWARE\Python\PythonCore\2.7\InstallPath', '(Default)', InstallPath) then
    BEGIN
    Result := InstallPath;
  END else
  if RegQueryStringValue(HKLM, 'SOFTWARE\Wow6432Node\Python\PythonCore\2.7', '(Default)', InstallPath) then
    BEGIN
    Result := InstallPath;
  END else
    MsgBox('Could not find Python',mbError,MB_OK);
    CancelWithoutPrompt := true;
    WizardForm.Close;
end;

procedure CancelButtonClick(CurPageID: Integer; var Cancel, Confirm: Boolean);
begin
  if CurPageID=wpInstalling then
    Confirm := not CancelWithoutPrompt;
end;

I got the code from Inno Setup - Setting DefaultDir using wildcard registry entry? and Inno Setup: How to Abort/Terminate Setup During Install?.

Community
  • 1
  • 1
kirbyfan64sos
  • 10,377
  • 6
  • 54
  • 75
  • There's no need to use distutils. Just make a folder in package path and the `__init__.py` from that library will [`mark that directory as a Python package directory`](http://effbot.org/pyfaq/what-is-init-py-used-for.htm). So if you create and copy the mathworks project files into a Python's package folder like `..\mathworks`, you should be able to import modules from that package (according to the `__init__.py` file content) by e.g. `import mathworks.shapes`. So simply use `[Files]` section to copy the content of a mathworks library into your wished Python's package subfolder. – TLama Apr 23 '13 at 18:10
  • @TLama: I know that. I am talking about Windows installers. The zip file at Google Code has the __init__.py that imports everything. My idea is to have Inno Setup use Pascal Script to get the Python installation directory from one of two places in the registry. It then would install to that directory. – kirbyfan64sos Apr 23 '13 at 21:07
  • Why didn't you tell this in your question ? Please edit your question and try to desrcibe your requirements. – TLama Apr 24 '13 at 05:51

1 Answers1

1

I figured it out! My code:

#define AppName "Mathworks"
#define AppDir "mathworks"
#define PyVer "2.7"
#define AppVer "1.3:

[Setup]
AppId={{3B6685C2-D478-4410-B973-57FA36A6DA6D}
AppName={#AppName}
AppVersion={#AppVer}
AppVerName=Mathworks {#AppVer}
AppPublisherURL=https://code.google.com/p/mathworks/
AppSupportURL=https://code.google.com/p/mathworks/
AppUpdatesURL=https://code.google.com/p/mathworks/
DefaultDirName={code:GetDirName}
DefaultGroupName={#AppName}
DisableProgramGroupPage=yes
LicenseFile=C:\Users\Ryan\Documents\mathworks-git\LICENSE_1_0.txt
OutputDir=C:\Users\Ryan\Desktop\Inno Setup
OutputBaseFilename=mathworks-{#AppVer}-python-{#PyVer}
Compression=lzma
SolidCompression=yes

[Languages]
Name: "english"; MessagesFile: "compiler:Default.isl"

[Files]
Source: "C:\Users\Ryan\Documents\mathworks-git\__init__.py"; DestDir: "{app}"; Flags: ignoreversion
Source: "C:\Users\Ryan\Documents\mathworks-git\exponent.py"; DestDir: "{app}"; Flags: ignoreversion
Source: "C:\Users\Ryan\Documents\mathworks-git\LICENSE_1_0.txt"; DestDir: "{app}"; Flags: ignoreversion
Source: "C:\Users\Ryan\Documents\mathworks-git\multiples.py"; DestDir: "{app}"; Flags: ignoreversion
Source: "C:\Users\Ryan\Documents\mathworks-git\ptheorem.py"; DestDir: "{app}"; Flags: ignoreversion
Source: "C:\Users\Ryan\Documents\mathworks-git\shapes.py"; DestDir: "{app}"; Flags: ignoreversion

[Code]
procedure ExitProcess(exitCode:integer);
  external 'ExitProcess@kernel32.dll stdcall';

function GetDirName(Value: string): string;
var          
  InstallPath: string;
  reg1 : string;
  reg2 : string;
begin
  reg1 := 'SOFTWARE\Python\PythonCore\' + '{#PyVer}' + '\InstallPath';
  reg2 := 'SOFTWARE\Python\PythonCore\Wow6432Node\' + '{#PyVer}' + '\InstallPath';
  if RegQueryStringValue(HKLM, reg1, '', InstallPath) then
    BEGIN
    Result := InstallPath + 'Lib\site-packages\' + '{#AppDir}';
  END else
  if RegQueryStringValue(HKCU, reg1, '', InstallPath) then
    BEGIN
    Result := InstallPath + 'Lib\site-packages\' + '{#AppDir}';
  END else
  if RegQueryStringValue(HKLM, reg2, '', InstallPath) then
    BEGIN
    Result := InstallPath + 'Lib\site-packages\' + '{#AppDir}';
  END else
    BEGIN
    MsgBox('Could not find Python',mbError,MB_OK);
    ExitProcess(1);
   END
end;
kirbyfan64sos
  • 10,377
  • 6
  • 54
  • 75
  • @Aivar: So you think distutils is ugly too? I was thinking of making a program to generate these files, but I didn't think anyone else would be interested. – kirbyfan64sos Jul 22 '13 at 15:55
  • Well the ugly was not my main problem -- I wanted to attach an extra uninstall script to distutils installer, but it turned out it doesn't get executed, although documentation promises it. – Aivar Jul 22 '13 at 16:13
  • about your idea about generating those iss-s, have you seen this: https://pypi.python.org/pypi/innosetup/ – Aivar Jul 22 '13 at 16:15
  • @Aivar: py2exe gives me DLL trouble. – kirbyfan64sos Jul 22 '13 at 16:30