aroberge / easygui_qt

Inspired by easygui, designed for PyQt
BSD 3-Clause "New" or "Revised" License
61 stars 18 forks source link

python 2.7 subprocess issues (affects launcher demo) #9

Closed jeremygray closed 9 years ago

jeremygray commented 9 years ago

Maybe supporting python 2.7 is too much of a hassle...

The launcher demo is not working for me on 2.7.8, due to subprocess.check_input expecting a list rather than string. The launcher is shown, but when trying to launch anything I get same the OSError:

>>> launcher.main()
Traceback (most recent call last):
  File "easygui_qt/demos/launcher.py", line 153, in get_string
    output = launch('get_string')
  File "easygui_qt/demos/launcher.py", line 24, in launch
    output = subprocess.check_output('python {} {}'.format(filename, name))
  File "/Users/jgray/anaconda/lib/python2.7/subprocess.py", line 566, in check_output
    process = Popen(stdout=PIPE, *popenargs, **kwargs)
  File "/Users/jgray/anaconda/lib/python2.7/subprocess.py", line 710, in __init__
    errread, errwrite)
  File "/Users/jgray/anaconda/lib/python2.7/subprocess.py", line 1327, in _execute_child
    raise child_exception
OSError: [Errno 2] No such file or directory

For me, passing a string to subprocess fails:

>>> v = subprocess.check_output('python -c "import sys; print(sys.version)"')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Users/jgray/anaconda/lib/python2.7/subprocess.py", line 566, in check_output
    process = Popen(stdout=PIPE, *popenargs, **kwargs)
  File "/Users/jgray/anaconda/lib/python2.7/subprocess.py", line 710, in __init__
    errread, errwrite)
  File "/Users/jgray/anaconda/lib/python2.7/subprocess.py", line 1327, in _execute_child
    raise child_exception
OSError: [Errno 2] No such file or directory

But doing as a list works as intended:

>>> v = subprocess.check_output(['python', '-c', "import sys; print(sys.version)"])
>>> v
'2.7.8 |Anaconda 2.0.1 (x86_64)| (default, Aug 21 2014, 15:21:46) \n[GCC 4.2.1 (Apple Inc. build 5577)]\n'

and when I hardcode that, then the launcher > python version button works as expected.

aroberge commented 9 years ago

I have just added a note in the readme file about attempting to support Python 2.7 (modulo some potential unicode issues) as I've had anothe request. With Python 2.7.9, the launcher works properly on Windows ... but I remember reading not so long ago about passing the arguments to subprocess as a list like you did instead of the way I did. I will try to make the change here and, if it works, use the list approach. I'll need to read about supporting Python 2 and 3 (the last project I did which supported both was done 6 years ago!) as much "wisdom" about doing so has been uncovered since from what I have been reading.

aroberge commented 9 years ago

it should work now (fingers crossed). I had broken something when trying to fix the unicode issue. Furthermore, I think I had made some assumptions about where the files would be launched; the new way should be more robust.

jeremygray commented 9 years ago

fixed with #10