我在 Python 2.6 中编写的模块 (test.py) 可以通过以下命令从 Python IDLE 导入并完美运行:
import test
test.run_test_suite()
但是,如果我在命令行中使用命令“python test.py”,它显然会在命令“import os”上崩溃(根据回溯)。
正如您从下面的代码中看到的,当从命令行运行时,它的执行应该与在 IDLE 中运行时相同。为什么不在 IDLE 中运行它会导致问题?我的 google-foo 只能在代码在命令行运行但不能在 IDLE 中运行时才能得到结果。
if __name__ == "__main__":
table = run_test_suite()
print '---=== Results ===---'
print_table(table)
需要指出的是,这个模块无非就是做大量的基础数学,检查一些外部计算的数据是否可行。
完整的追溯是:
Traceback (most recent call last):
File "...\Python\test.py", line 170, in <module>
print '---=== Results ===---'
File "...\Python\test.py", line 160, in build_data
if Links == False:
File "...\Python\test.py", line 103, in load_table
if Abbrev[M.solution_type()] == 'pos':
File "...\Python\test.py", line 85, in build_example
import os
File "SnapPy.pyx", line 173, in snappy.SnapPy.uFatalError (SnapPy.c:5507)
snappy.SnapPy.SnapPeaFatalError:
SnapPea crashed in function cusp_modulus(), defined in cusp_modulus.c.