无效的命令“py2exe" [英] Invalid command 'py2exe'

查看:76
本文介绍了无效的命令“py2exe"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我安装了 python 2.5 和 2.6.我在 2.6 上运行我的项目.首先,我安装了 2.5 版的 py2exe,但它不起作用,所以我安装了 2.6 版的 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 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 =...

当我在控制台中输入:path\setup.py py2exe我收到错误:无效命令‘py2exe’"

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

我使用正确的斜杠将路径更改为F:/Program Files/Python26/Lib/site-packages/py2exe".控制台如下所示:

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'

推荐答案

这是你的问题:

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

反斜杠 (\) 是一个 escape字符,并被几乎所有编程语言(包括 Python)以特殊方式解释.

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

不幸的是,DOS(以及扩展的Windows)也使用反斜杠作为目录分隔符而不是斜杠.这背后有一段历史...

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:

使用斜线.Python 会在内部将它们转换为反斜杠.

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\\'

使用不解释转义字符的原始"字符串.通过在字符串前添加 r 来做到这一点.

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

d = r'C:\Program Files\'

我个人更喜欢第一种解决方案.但我已经看到其他两个也被使用了很多.请注意,这也适用于其他方式,因此如果您使用反斜杠,Python 会在 UNIX 和 Linux 系统上将其转换为斜杠.

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.

作为免费的奖励提示,这也可能是指出 os.path.join() 函数 :)

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

这篇关于无效的命令“py2exe"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆