3

I have had success using pyInstaller 2.0 to create executables from simple python scripts. I have a python script which runs different searches and produces different output based on command line arguments. Is there a way to use pyInstaller to create an executable of the script assuming certain arguments? As in, I want to produce an exe file that will run and produce the same output as if I were to run it from the command line as follows:

python pacman.py --layout mediumMaze --pacman SearchAgent

Is this possible with pyInstaller 2.0? I have not been able to find this addressed in the provided manual. Thank you in advance.

1
  • 1
    Edit pacman.py to assume these arguments as default? Commented Dec 30, 2012 at 22:33

1 Answer 1

1

This is sort of a roundabout way to do it, but you could import pacman.py in a separate python file, and call it in such a way that it does the things the command line arguments specify. Then, using pyinstaller, you would compile the separate python file.

If it's not possible to use pacman.py in that manner, you could try creating the following Python file and letting pyinstaller compile that.

import sys

sys.argv.extend(['--layout', 'mediumMaze', '--pacman', 'SearchAgent'])

import pacman
pacman.main() # if your file has a `main` function

(In both cases, pyinstaller would still combine the two files together into one exe)

Sign up to request clarification or add additional context in comments.

2 Comments

Yeah, it is (in this regard). Note that if pacman.py is reasonably well-written (doesn't actually do anything if it isn't __main__), this won't do anything. In well-written stand-alone scripts, there's usually a main() function or something which would have to be called explicitly when wrapping it by importing it.
This seems to run the file with the correct default arguments, but the executable doesn't disply the pygame output unfortunately. I don't understand why that is, because the script runs as expected. Hm.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.