Invalid command 'py2exe'
Question: 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 version but then the module wasn't found. Now I changed
the sys path:

    
    
    import sys
    sys.path.append('F:\Program Files\Python26\Lib\site-packages\py2exe')
    from build_exe import py2exe 
    from distutils.core import setup
    
    setup( 
     name =...
    

When i type into the console: path\setup.py py2exe I get "error: invalid
command 'py2exe'"

EDIT: I changed the path to 'F:/Program Files/Python26/Lib/site-
packages/py2exe' with correct slashes. Console looks like this:

    
    
    E:\Eclipse Workspace\...\src>setup.py py2exe
    usage: setup.py [global_opts] cmd1 [cmd1_opts] [cmd2 [cmd2_opts] ...]
    or: setup.py --help [cmd1 cmd2 ...]
    or: setup.py --help-commands
    or: setup.py cmd --help
    error: invalid command 'py2exe'
    


Answer: Here is your problem:

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

A backslash (`\`) is an [escape
character](http://en.wikipedia.org/wiki/Escape_character "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](http://superuser.com/questions/176388/why-does-windows-use-
backslashes-for-paths-and-unix-forward-slashes "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()](http://docs.python.org/library/os.path.html#os.path.join
"os.path.join\(\)") function :)

