Launching Leo in Windows

12 views
Skip to first unread message

Nick_H

unread,
Apr 23, 2010, 5:56:05 AM4/23/10
to leo-editor
This is probably a dumb n00b question, but in my Windows (XP SP3)
environment, I have the following "open" command associated with .leo
file extensions:

"C:\Program Files\Python31\pythonw.exe" "C:\Leo\launchLeo.py" "%1"

What I find is that the appropriate file is opened by Leo, but then
instantly closes itself again.
I can run launchLeo from the Python IDLE GUI and then open the
corresponding file, and all is well.
Please can you suggest what I need to fix?
Many thanks.

Nick

--
You received this message because you are subscribed to the Google Groups "leo-editor" group.
To post to this group, send email to leo-e...@googlegroups.com.
To unsubscribe from this group, send email to leo-editor+...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/leo-editor?hl=en.

Terry Brown

unread,
Apr 23, 2010, 9:47:03 AM4/23/10
to leo-e...@googlegroups.com
On Fri, 23 Apr 2010 02:56:05 -0700 (PDT)
Nick_H <n...@plextek.co.uk> wrote:

> "C:\Program Files\Python31\pythonw.exe" "C:\Leo\launchLeo.py" "%1"

Does it work if you use python.exe instead of pythonw.exe? I know that leaves you with a console window you might not want, but just curious if it's something to do with stdout/in/err being closed.

Cheers -Terry

Nick_H

unread,
Apr 23, 2010, 10:40:33 AM4/23/10
to leo-editor


On Apr 23, 9:47 pm, Terry Brown <terry_n_br...@yahoo.com> wrote:
> On Fri, 23 Apr 2010 02:56:05 -0700 (PDT)
>
> Does it work if you use python.exe instead of pythonw.exe?  I know that leaves you with a console window you might not want, but just curious if it's something to do with stdout/in/err being closed.

Yes, you're exactly right. I was messing around trying things, and
that is what I found.
Also with a fresh installation on another PC (Windows XP again) I
found that with pythonw.exe, the editor opened ok and stayed open, but
then was unable to save the open file (with log message:
AttributeError: 'NoneType' object has no attribute 'write'
)

I can always just use python.exe with the console window, but is there
a way I can fix this?
Thanks!

Nick

Terry Brown

unread,
Apr 23, 2010, 10:51:48 AM4/23/10
to leo-e...@googlegroups.com
On Fri, 23 Apr 2010 07:40:33 -0700 (PDT)
Nick_H <n...@plextek.co.uk> wrote:

> AttributeError: 'NoneType' object has no attribute 'write'
> )
>
> I can always just use python.exe with the console window, but is there
> a way I can fix this?

Leo has a tendency to chatter on the console window, you'd probably need to study the code to work out the best way to avoid problems when there's no stdout / stderr.

I think we're basically seeing this error:

>>> import sys
>>> sys.stdout = None
>>> print 'test'
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: 'NoneType' object has no attribute 'write'

I think all occurrences of 'print' were eliminated from the core code, there are probably some lurking in some plugins (mea culpa). So the most general fix might be for Leo to create dummy files on sys.stdout etc. if they're None.

Or we could try and find and eliminate all the bad code, but that raises the specter of missing some cases (or having cases added in the future), and having a Leo that appears to be working fine but will unexpectedly derail when you do something that hits some obscure piece of code.

hmm, just did this in python 3.1 to see what happens:

>>> import sys
>>> sys.stdout = None
>>> print 'test'
File "<stdin>", line 1
print 'test'
^
SyntaxError: invalid syntax
>>> print('test')
[no output]

So perhaps eliminating any calls to 2.x style print is the way to go.

Cheers -Terry

Edward K. Ream

unread,
May 6, 2010, 10:45:25 AM5/6/10
to leo-e...@googlegroups.com
On Fri, Apr 23, 2010 at 9:51 AM, Terry Brown <terry_...@yahoo.com> wrote:
> On Fri, 23 Apr 2010 07:40:33 -0700 (PDT)
> Nick_H <n...@plextek.co.uk> wrote:
>
>> AttributeError: 'NoneType' object has no attribute 'write'
>> )
>>
>> I can always just use python.exe with the console window, but is there
>> a way I can fix this?
>
> Leo has a tendency to chatter on the console window, you'd probably need to study the code to work out the best way to avoid problems when there's no stdout / stderr.
>
> I think we're basically seeing this error:
>
>>>> import sys
>>>> sys.stdout = None
>>>> print 'test'
> Traceback (most recent call last):
>  File "<stdin>", line 1, in <module>
> AttributeError: 'NoneType' object has no attribute 'write'
>
> I think all occurrences of 'print' were eliminated from the core code, there are probably some lurking in some plugins (mea culpa).  So the most general fix might be for Leo to create dummy files on sys.stdout etc. if they're None.

I am a bit lost here. Problems with print vs. print() should give
syntax errors, not runtime errors. Furthermore, I just verified that
one can run launchleo.py from python26/pythonw.exe. Thus, I don't
understand either the problem or the proposed solution :-)

Edward

Terry Brown

unread,
May 6, 2010, 12:14:12 PM5/6/10
to leo-e...@googlegroups.com
On Thu, 6 May 2010 09:45:25 -0500
"Edward K. Ream" <edre...@gmail.com> wrote:

> On Fri, Apr 23, 2010 at 9:51 AM, Terry Brown <terry_...@yahoo.com> wrote:
> > On Fri, 23 Apr 2010 07:40:33 -0700 (PDT)
> > Nick_H <n...@plextek.co.uk> wrote:
> >
> >> AttributeError: 'NoneType' object has no attribute 'write'
> >> )
> >>
> >> I can always just use python.exe with the console window, but is there
> >> a way I can fix this?
> >
> > Leo has a tendency to chatter on the console window, you'd probably need to study the code to work out the best way to avoid problems when there's no stdout / stderr.
> >
> > I think we're basically seeing this error:
> >
> >>>> import sys
> >>>> sys.stdout = None
> >>>> print 'test'
> > Traceback (most recent call last):
> >  File "<stdin>", line 1, in <module>
> > AttributeError: 'NoneType' object has no attribute 'write'
> >
> > I think all occurrences of 'print' were eliminated from the core code, there are probably some lurking in some plugins (mea culpa).  So the most general fix might be for Leo to create dummy files on sys.stdout etc. if they're None.
>
> I am a bit lost here. Problems with print vs. print() should give
> syntax errors, not runtime errors. Furthermore, I just verified that
> one can run launchleo.py from python26/pythonw.exe. Thus, I don't
> understand either the problem or the proposed solution :-)

Printing in Python 2k and 3k behaves differently when sys.stdout == None. 2k raises an AttributeError (i.e. sys.stdout.write(foo) fails), whereas 3k just does nothing, no output or error. There are a small number of places in plugins, and possibly the core also, where 2k style print is used, just launching leo isn't enough to trigger the problem. So changing those to whatever it is that you're supposed to use in leo code instead of print (some g. function I imagine) would probably fix the problem, as long as the g. function itself didn't trip over the sys.stdout == None case.

Just changing print foo to print(foo) is insufficient, because 2k will still trip on sys.stdout == None, and besides printing a tuple adds parentheses to the output.

Cheers -Terry

Edward K. Ream

unread,
May 7, 2010, 12:24:43 AM5/7/10
to leo-e...@googlegroups.com
On Thu, May 6, 2010 at 11:14 AM, Terry Brown <terry_...@yahoo.com> wrote:

> Printing in Python 2k and 3k behaves differently when sys.stdout == None.  2k raises an AttributeError (i.e. sys.stdout.write(foo) fails), whereas 3k just does nothing, no output or error.

Thanks. I didn't know that.

> There are a small number of places in plugins, and possibly the core also, where 2k style print is used, just launching leo isn't enough to trigger the problem.

2k print style will create a Syntax error when compiled by Python 3k.
Thus, Leo's core is guaranteed to be clean in this regard. As you
probably know, there is a script in unitTest.leo, in the node "Other
tests-->Import all plugins script", that attempts to load all plugins.
Running this script (with appropriate settings) will show you which
plugins fail on Python 3k.
Reply all
Reply to author
Forward
0 new messages