python脚本有什么问题?
代码:import os
import shutil
import getpass
os.mkdir("C:\dtmp")
shutil.copy("C:\path\to\bb-freeze-script.py","C:\dtmp")
os.chdir("C:\dtmp")
shutil.copy("C:\path\to\main.py","C:\dtmp")
os.system("python bb-freeze-script.py main.py")
os.mkdir("C:\Program Files\Directories v0.6")
os.chdir("C:\")
shutil.rmtree("C:\dtmp")
print getpass.getuser()
错误:Traceback (most recent call last):
File "bb-freeze-script.py", line 8, in <module>
load_entry_point('bbfreeze==0.97.3', 'console_scripts', 'bb-freeze')()
File "C:Python27libsite-packagesbbfreeze-0.97.3-py2.7-win32.eggbbfreeze__init__.py", line 24, in main
f.addScript(x)
File "C:Python27libsite-packagesbbfreeze-0.97.3-py2.7-win32.eggbbfreezefreezer.py", line 410, in addScript
s = self.mf.run_script(path)
File "C:Python27libsite-packagesbbfreeze-0.97.3-py2.7-win32.eggbbfreezemodulegraphmodulegraph.py", line 241, in run_script
co = compile(file(pathname, READ_MODE).read()+'n', pathname, 'exec')
File "C:dtmpmain.py", line 14
^
IndentationError: expected an indented block
操作系统—Windows XP
下面是关于如何阅读回溯的快速演练。这很简单。
-
查看您的代码,所有这些都是调用Python内置模块。可以肯定地说,它们没有引起错误,所以唯一剩下的是
os.system
调用。果然,您通过上述调用调用python
(为什么不直接导入您要调用的模块呢?)。 -
回溯确认错误在您正在调用的其他Python中:
Traceback (most recent call last): File "bb-freeze-script.py", line 8, in <module> load_entry_point('bbfreeze==0.97.3', 'console_scripts', 'bb-freeze')()
-
接下来,通读记录的行,以挖掘调用堆栈并找出错误发生的确切位置。
File "C:Python27libsite-packagesbbfreeze-0.97.3-py2.7-win32.eggbbfreeze__init__.py", line 24, in main f.addScript(x) File "C:Python27libsite-packagesbbfreeze-0.97.3-py2.7-win32.eggbbfreezefreezer.py", line 410, in addScript s = self.mf.run_script(path) File "C:Python27libsite-packagesbbfreeze-0.97.3-py2.7-win32.eggbbfreezemodulegraphmodulegraph.py", line 241, in run_script co = compile(file(pathname, READ_MODE).read()+'n', pathname, 'exec')
-
直到你到达
File "C:dtmpmain.py", line 14 IndentationError: expected an indented block
好了,错误在main.py
的第14行,在那里你应该有一个缩进,但没有。