Home Ask Login Register

Developers Planet

Your answer is one click away!

Princess Magnificent February 2016

py2exe and setting up setup.py to get its target from argv?

I'm trying to create an executable from a .py file, and if I do things exactly as the py2exe tutorial says, it works. I put setup(console=["thingyIdLikeToDo.py"]) in my setup.py file, then type python setup.py py2exe into my console, and it works.

BUT. This means that whenever I want to make another python file into an executable, I have to go open and edit setup.py. And I'd rather do something else:

from distutils.core import setup
from sys import argv
import py2exe

##This was originally setup(console=["MyTargetFile.py"]) and it DOES work that way

And then type in python setup.py MyTargetFile.py py2exe. On account of it being invalid command name 'MyTargetFile.py'

I've also tried it by changing the order, making it python setup.py py2exe MyTargetFile.py and changing the argv[1] to argv[2]. I get the exact same error message.

I mean, I DO have a functioning way to make my .py files into .exe files, but I'm really annoyed that something that seems like it ought to be such a simple change is't working. What am I missing here?


g.d.d.c February 2016

You're running into trouble because setup is using sys.argv. If you change your call to setup(console = [sys.argv.pop(1)] I believe you will stop stepping on distutils' toes and things should go smoothly.

Post Status

Asked in February 2016
Viewed 2,864 times
Voted 11
Answered 1 times


Leave an answer

Quote of the day: live life