I've created my setup.py file as instructed but I don't actually.. understand what to do next. Typing "python setup.py build" into the command line just gets a syntax error.
我按照指示创建了我的setup.py文件,但实际上我并不知道接下来要做什么。在命令行中键入“python setup.py build”只会出现语法错误。
So, what do I do?
那么,我该怎么办?
setup.py:
setup.py:
from cx_Freeze import setup, Executable
setup(
name = "On Dijkstra's Algorithm",
version = "3.1",
description = "A Dijkstra's Algorithm help tool.",
exectuables = [Executable(script = "Main.py", base = "Win32GUI")])
5 个解决方案
#1
33
- Add
import sys
as the new topline - 添加import sys作为新的topline
- You misspelled "executables" on the last line.
- 你在最后一行拼错了“可执行文件”。
- Remove
script =
on last line. - 在最后一行删除script =。
The code should now look like:
代码现在应该如下所示:
import sys
from cx_Freeze import setup, Executable
setup(
name = "On Dijkstra's Algorithm",
version = "3.1",
description = "A Dijkstra's Algorithm help tool.",
executables = [Executable("Main.py", base = "Win32GUI")])
Use the command prompt (cmd
) to run python setup.py build
. (Run this command from the folder containing setup.py
.) Notice the build
parameter we added at the end of the script call.
使用命令提示符(cmd)运行python setup.py构建。 (从包含setup.py的文件夹中运行此命令。)请注意我们在脚本调用结束时添加的构建参数。
#2
11
I'm really not sure what you're doing to get that error, it looks like you're trying to run cx_Freeze on its own, without arguments. So here is a short step-by-step guide on how to do it in windows (Your screenshot looks rather like the windows command line, so I'm assuming that's your platform)
我真的不确定你在做什么来得到那个错误,看起来你正试图自己运行cx_Freeze,没有参数。所以这里有一个关于如何在Windows中执行此操作的简短分步指南(您的屏幕截图看起来很像Windows命令行,所以我假设这是您的平台)
-
Write your setup.py file. Your script above looks correct so it should work, assuming that your script exists.
编写setup.py文件。上面的脚本看起来是正确的,所以假设您的脚本存在,它应该可以工作。
-
Open the command line (
Start
->Run
->"cmd"
)打开命令行(开始 - >运行 - >“cmd”)
-
Go to the location of your setup.py file and run
python setup.py build
转到setup.py文件的位置并运行python setup.py build
Notes:
笔记:
-
There may be a problem with the name of your script. "Main.py" contains upper case letters, which might cause confusion since windows' file names are not case sensitive, but python is. My approach is to always use lower case for scripts to avoid any conflicts.
您的脚本名称可能存在问题。 “Main.py”包含大写字母,这可能会导致混淆,因为Windows的文件名不区分大小写,但python是。我的方法是始终使用小写脚本来避免任何冲突。
-
Make sure that python is on your PATH (read http://docs.python.org/using/windows.html)1
确保python在你的PATH上(阅读http://docs.python.org/using/windows.html)1
-
Make sure are are looking at the new cx_Freeze documentation. Google often seems to bring up the old docs.
确保正在查看新的cx_Freeze文档。谷歌似乎经常提出旧的文档。
#3
7
I ran into a similar issue. I solved it by setting the Executable options in a variable and then simply calling the variable. Below is a sample setup.py that I use:
我遇到了类似的问题。我通过在变量中设置可执行选项然后简单地调用变量来解决它。下面是我使用的setup.py示例:
from cx_Freeze import setup, Executable
import sys
productName = "ProductName"
if 'bdist_msi' in sys.argv:
sys.argv += ['--initial-target-dir', 'C:\InstallDir\\' + productName]
sys.argv += ['--install-script', 'install.py']
exe = Executable(
script="main.py",
base="Win32GUI",
targetName="Product.exe"
)
setup(
name="Product.exe",
version="1.0",
author="Me",
description="Copyright 2012",
executables=[exe],
scripts=[
'install.py'
]
)
#4
7
You can change the setup.py code to this:
您可以将setup.py代码更改为:
from cx_freeze import setup, Executable
setup( name = "foo",
version = "1.1",
description = "Description of the app here.",
executables = [Executable("foo.py")]
)
I am sure it will work. I have tried it on both windows 7 as well as ubuntu 12.04
我相信它会奏效。我在Windows 7以及ubuntu 12.04上都尝试过它
#5
2
find the cxfreeze
script and run it. It will be in the same path as your other python helper scripts, such as pip
.
找到cxfreeze脚本并运行它。它将与您的其他python帮助程序脚本(例如pip)处于相同的路径中。
cxfreeze Main.py --target-dir dist
cxfreeze Main.py --target-dir dist
read more at: http://cx-freeze.readthedocs.org/en/latest/script.html#script
更多信息,请访问:http://cx-freeze.readthedocs.org/en/latest/script.html#script
#1
33
- Add
import sys
as the new topline - 添加import sys作为新的topline
- You misspelled "executables" on the last line.
- 你在最后一行拼错了“可执行文件”。
- Remove
script =
on last line. - 在最后一行删除script =。
The code should now look like:
代码现在应该如下所示:
import sys
from cx_Freeze import setup, Executable
setup(
name = "On Dijkstra's Algorithm",
version = "3.1",
description = "A Dijkstra's Algorithm help tool.",
executables = [Executable("Main.py", base = "Win32GUI")])
Use the command prompt (cmd
) to run python setup.py build
. (Run this command from the folder containing setup.py
.) Notice the build
parameter we added at the end of the script call.
使用命令提示符(cmd)运行python setup.py构建。 (从包含setup.py的文件夹中运行此命令。)请注意我们在脚本调用结束时添加的构建参数。
#2
11
I'm really not sure what you're doing to get that error, it looks like you're trying to run cx_Freeze on its own, without arguments. So here is a short step-by-step guide on how to do it in windows (Your screenshot looks rather like the windows command line, so I'm assuming that's your platform)
我真的不确定你在做什么来得到那个错误,看起来你正试图自己运行cx_Freeze,没有参数。所以这里有一个关于如何在Windows中执行此操作的简短分步指南(您的屏幕截图看起来很像Windows命令行,所以我假设这是您的平台)
-
Write your setup.py file. Your script above looks correct so it should work, assuming that your script exists.
编写setup.py文件。上面的脚本看起来是正确的,所以假设您的脚本存在,它应该可以工作。
-
Open the command line (
Start
->Run
->"cmd"
)打开命令行(开始 - >运行 - >“cmd”)
-
Go to the location of your setup.py file and run
python setup.py build
转到setup.py文件的位置并运行python setup.py build
Notes:
笔记:
-
There may be a problem with the name of your script. "Main.py" contains upper case letters, which might cause confusion since windows' file names are not case sensitive, but python is. My approach is to always use lower case for scripts to avoid any conflicts.
您的脚本名称可能存在问题。 “Main.py”包含大写字母,这可能会导致混淆,因为Windows的文件名不区分大小写,但python是。我的方法是始终使用小写脚本来避免任何冲突。
-
Make sure that python is on your PATH (read http://docs.python.org/using/windows.html)1
确保python在你的PATH上(阅读http://docs.python.org/using/windows.html)1
-
Make sure are are looking at the new cx_Freeze documentation. Google often seems to bring up the old docs.
确保正在查看新的cx_Freeze文档。谷歌似乎经常提出旧的文档。
#3
7
I ran into a similar issue. I solved it by setting the Executable options in a variable and then simply calling the variable. Below is a sample setup.py that I use:
我遇到了类似的问题。我通过在变量中设置可执行选项然后简单地调用变量来解决它。下面是我使用的setup.py示例:
from cx_Freeze import setup, Executable
import sys
productName = "ProductName"
if 'bdist_msi' in sys.argv:
sys.argv += ['--initial-target-dir', 'C:\InstallDir\\' + productName]
sys.argv += ['--install-script', 'install.py']
exe = Executable(
script="main.py",
base="Win32GUI",
targetName="Product.exe"
)
setup(
name="Product.exe",
version="1.0",
author="Me",
description="Copyright 2012",
executables=[exe],
scripts=[
'install.py'
]
)
#4
7
You can change the setup.py code to this:
您可以将setup.py代码更改为:
from cx_freeze import setup, Executable
setup( name = "foo",
version = "1.1",
description = "Description of the app here.",
executables = [Executable("foo.py")]
)
I am sure it will work. I have tried it on both windows 7 as well as ubuntu 12.04
我相信它会奏效。我在Windows 7以及ubuntu 12.04上都尝试过它
#5
2
find the cxfreeze
script and run it. It will be in the same path as your other python helper scripts, such as pip
.
找到cxfreeze脚本并运行它。它将与您的其他python帮助程序脚本(例如pip)处于相同的路径中。
cxfreeze Main.py --target-dir dist
cxfreeze Main.py --target-dir dist
read more at: http://cx-freeze.readthedocs.org/en/latest/script.html#script
更多信息,请访问:http://cx-freeze.readthedocs.org/en/latest/script.html#script