views:

115

answers:

2

A module that I have written (test.py) in Python 2.6 can be imported and run perfectly well from with the Python IDLE with the commands:

import test
test.run_test_suite()

However if I use the command "python test.py" at the command line, it crashes apparently (according to traceback) on the command "import os".

As you can see from the code below, when run from the command line it should perform the same as when run inside the IDLE. Why would not running this in the IDLE cause a problem? My google-foo only can up with results when code would run at the command line but not in IDLE.

if __name__ == "__main__":
    table = run_test_suite()
    print '---=== Results ===---'
    print_table(table)

It should be pointed out that this module is doing nothing more than large amounts of basic maths to check some externally calculated data is feasible.

the full traceback is:

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.
A: 

Are you using the same python version in both cases? When starting from the commandline, you get the first Python in your path, while IDLE is most probably executed directly from a shortcut.
If you have more than one version of python installed on your machine, this could translate in two complete different environments.

Roberto Liffredo
No, I only have python 2.6 installed.
qwerty1793
how go you switch between versions?
Drewdin
On Windows? You need to change the file association for .py files, adn change the path. The task can be automated, but I do not know of anything already available doing it (never searched, though).
Roberto Liffredo
A: 

Look for a file named os.py in your current working directory. If you have one, rename it. Or check the Python documentation for "absolute import".

Thud Foo
As I added above, adding 'import math' or infact any other module i could think of to the line above 'import os' now causes it to crash with 'File "...\Python\test.py", line 85, in build_example import math' So it doesn't appear to be a real problem with import os. There is no other python file in the working directory.
qwerty1793