Skip to content Skip to sidebar Skip to footer

Invalid Command 'py2exe'

I have python 2.5 and 2.6 installed. I'm running my project on 2.6. First I had py2exe for 2.5 installed but it didn't work so I installed py2exe for 2.6 and deleted the other ver

Solution 1:

Here is your problem:

sys.path.append('F:\Program Files\Python26\Lib\site-packages\py2exe')

A backslash (\) is an escape character and interperted in a special way by almost all programming languages, including Python.

It's unfortunate that DOS (And by extension Windows) also uses the backslash as a directory separator instead of a a slash. There is a bit of history behind this...

In any case, you have a few options:

Use slashes. Python will convert them to backslashes internally.

d = 'C:/Program Files/'

Use two backslahes, this will escape the backslashes and insert a single backslashes.

d = 'C:\\Program Files\\'

Use a "raw" string which doesn't interpret escape character. Do this by adding a r before the string.

d = r'C:\Program Files\'

I personally prefer the first solution. But I've seen the other two being used quite a bit too. Note that this also works the other way around, so if you use backslashes Python will convert it to slashes on UNIX and Linux systems.

As a free bonus hint, this may also be a good place to point out the os.path.join() function :)


Solution 2:

The solution is very simple.

Add install.

So instead of

setup.py py2exe

write

setup.py py2exe install

and it works


Post a Comment for "Invalid Command 'py2exe'"