Invalid command 'py2exe'

我怕爱的太早我们不能终老 提交于 2019-12-13 00:36:00

问题


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'

回答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 :)




回答2:


The solution is very simple.

Add install.

So instead of

setup.py py2exe

write

setup.py py2exe install

and it works



来源:https://stackoverflow.com/questions/6871520/invalid-command-py2exe

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!