I am trying to figure out the best way to deploy a python script that I wrote. Many of the users wont have python on their machines but might want to make slight alterations to the script.

What I was thinking about doing was using Py2exe to compile a script that called an actual .py file in the same directory of the exe.

Is this possible, or are there any better alternatives?

I don't think it's possible because py2exe does not include any source, only the byte code compiled files in case you go for the zip file option.

I'm not sure exactly what kind of tweaks you're thinking your users might be likely to make to your script, but if your users aren't likely to be needing to make any structural/logical changes to the script. Or in other words, if they're only likely to be changing the values of certain variables in the script I can think of two options:

Option 1:
You could alter your script to use an optional text based ini file...So in your documentation for your script you tell users if they want to customise anything, then they should create an ini file called {InsertYourScriptNameHere}.ini and list any options that they can use in the ini.

You then alter your script so it does this:

  • Initialise all variables to your default settings
  • Look for an ini file....
    - If an ini is found; read and parse its contents and overwrite the values of any related variables with the users settings.
    - If no ini is found; no problem, the defaults are already set so you're ready to go!
  • The rest of your script runs as per usual.

Once you've made the necessary changes to your script, you can rebuild your distributable with py2exe. But ensure that you include some kind of documentation to inform users of the options that they can include/change in the ini file.

OR

Option 2.
You could alter your script to take command line arguments. So just like the ini option, you'd initialise your variables to their default settings and then you take a look at the command line arguments and overwrite any variables with the passed-in settings. Again, after making the necessary changes to the script and rebuilding your distributable with py2exe, make sure you include some documentation on the options available to your users.

Which of those two options you choose is up to you.
The command line argument idea would work best if you only have a few options that the user could set. But the drawback there is that the user would have to specify any custom arguments every time they ran the script.
The ini option works well if you potentially have a lot of options that the user can set...Another advantage of using the ini file is that users settings will persist every time the script is ran. (Or at least until they alter or remove the ini file). A lot easier than having to remember command line arguments.

Personally regardless of the amount of options, I'd go with the ini file option.

Like I said, those two options would only work if the users are only likely to need to alter the values of variables used in the script.

If you're expecting your users to be able to change the actual logic of the script, then as Ene Uran has already said, I think you're out of luck! The only option I can think of there would be to package the original source file with your py2exe generated distributable and then in your documentation, tell your users if they want to customise the script to their own needs then they'll need to install the appropriate version of python before altering and running the original script.

But having said that...Anybody who is likely to want to change the script in this way is most likely a python programmer already and therefore is most likely to have python installed anyway, so it's a bit of a moot point!

Anyway, that's my perspective!
Cheers for now,
Jas.

Edited 7 Years Ago by JasonHippy: n/a

Ooops! Thinking about it I'm not sure if you can specify command line arguments with py2exe generated exe's...So option 2 is probably out of the question anyway...But option 1 still stands and is probably the best option if you want the user to be able to alter values of variables in your script!

I was going to remove option 2 from my previous post but the 30 minute edit window for the post has expired...Doh!
Cheers for now,
Jas.

This article has been dead for over six months. Start a new discussion instead.