py-shell invoking python not ipython

Bug #835151 reported by Terry Jones
14
This bug affects 2 people
Affects Status Importance Assigned to Milestone
python-mode.el
Fix Released
Medium
Andreas Roehler

Bug Description

I've just upgraded from 6.0.1 to 6.0.2. I dropped the *.el files into
my load-path on top of the old files, removed the old *.elc, byte
compiled, exited & re-entered emacs. Confirmed I'm now running 6.0.2
from py-version.

If I visit a .py file and immediately C-c ! the resulting *Python*
buffer has this in it:

Traceback (most recent call last):
  File "<string>", line 1, in <module>
NameError: name 'olors' is not defined
>>>

I'm a bit tired and haven't managed to fully track down what's going
on. I normally use ipython from python mode, and the ipython.el on my
box hasn't changed for a long time. My emacs setup is as it was. I have

ipython-command = "ipython"
py-python-command = "ipython"
py-python-command-args = ("-i" "-colors" "LightBG")

I don't set any of those vars myself, those are the values I see from
C-h v.

Despite this, it's clear that "python" is being called instead of
"ipython".

From iptyhon.el: (executable-find ipython-command) produces
"/usr/bin/ipython".

I'm happy to help debug, just let me know what's needed.

Revision history for this message
Andreas Roehler (a-roehler) wrote : Re: [Bug 835151] [NEW] py-shell invoking python not ipython

Am 27.08.2011 01:49, schrieb Terry Jones:
> NameError: name 'olors' is not defined

Hi Terry,

think this is a well known bug of ipython.el, which doesn't bite AFAIK,
just that nasty warning.

see for example report at

http://mail.scipy.org/pipermail/ipython-user/2007-March/004180.html

Would flag this report "invalid" with resp. to python-mode.el.

However, think we should deliver ipython.el together with
python-mode.el, as it's entry point for beginners is lower than
python-mode.el's usage.

What about a feature-request at <email address hidden> resp. an
Blueprint for that?

Thanks,

Andreas

Changed in python-mode:
assignee: nobody → Andreas Roehler (a-roehler)
Revision history for this message
Terry Jones (terrycojones) wrote :

Hi Andreas

Thanks for the reply. I just tried reverting to 6.0.1 and I still have the problem, so this is not something introduced by 6.0.2. That's really odd, but it's my problem :-) Sorry for the false alarm! I'll mark as Invalid.

Terry

Changed in python-mode:
status: New → Invalid
Revision history for this message
Andreas Roehler (a-roehler) wrote : Re: [Bug 835151] Re: py-shell invoking python not ipython

Am 27.08.2011 12:08, schrieb Terry Jones:
> Hi Andreas
>
> Thanks for the reply. I just tried reverting to 6.0.1 and I still have
> the problem, so this is not something introduced by 6.0.2. That's really
> odd, but it's my problem :-) Sorry for the false alarm! I'll mark as
> Invalid.
>
> Terry
>
>
> ** Changed in: python-mode
> Status: New => Invalid
>

Hi Terry,

think the second part of your report might indicate a bug python-mode
bug though.

The ipython shell with its prompt "[1]" etc. should appear in any case.

Does it?

If not, we have a bug - and some idea, where it comes from... :)

Thanks,

Andreas

Revision history for this message
Terry Jones (terrycojones) wrote :

Hi Andreas

> think the second part of your report might indicate a bug python-mode bug
> though.

The report was only about one thing, but I guess I didn't write it clearly,
apologies!

> The ipython shell with its prompt "[1]" etc. should appear in any case.
>
> Does it?

No. The *Python* buffer contains this:

    Traceback (most recent call last):
      File "<string>", line 1, in <module>
    NameError: name 'olors' is not defined
    >>>

without the indent, of course. Python works just fine in the buffer, but
it seems clear that py-shell has invoked python not ipython. There is only
one ipython on my shell's path (/usr/bin/ipython).

In summary, I can't get ipython to work with either of 6.0.[12]. Both give
me the result above. Just for fun I apt-get installed python-mode and
copied the 6.0.2 .el and .elc files onto of the package files, but got the
same result.

I've done some googling and seen various people with this error, dating
from about 2007 (as in the link you posted), but haven't seen anyone
posting a fix/workaround.

Please let me know if I can help.

Terry

Revision history for this message
Andreas Roehler (a-roehler) wrote :

Am 27.08.2011 15:45, schrieb Terry Jones:
> Hi Andreas
>
>> think the second part of your report might indicate a bug python-mode bug
>> though.
>
> The report was only about one thing, but I guess I didn't write it clearly,
> apologies!
>
>> The ipython shell with its prompt "[1]" etc. should appear in any case.
>>
>> Does it?
>
> No. The *Python* buffer contains this:
>
> Traceback (most recent call last):
> File "<string>", line 1, in<module>
> NameError: name 'olors' is not defined
> >>>
>
> without the indent, of course. Python works just fine in the buffer, but
> it seems clear that py-shell has invoked python not ipython. There is only
> one ipython on my shell's path (/usr/bin/ipython).
>
> In summary, I can't get ipython to work with either of 6.0.[12].

So the title of you bug report is OK, just the error-message given is
unrelated.

Switched the flag to "progess", I'm on it.

As for the probable background: previously "python -i" was hardcoded as
python-command.

Thought that might not be right in all cases.
Seems we have to provide again for the case it is...

Thanks,

Andreas

Changed in python-mode:
importance: Undecided → Medium
status: Invalid → In Progress
milestone: none → 6.0.3
Revision history for this message
Terry Jones (terrycojones) wrote :

Looking around in the efun of py-shell and playing inside emacs: I have py-shell-name nil and when this is run in py-shell, py-shell-name is set to "python".

  (when (null py-shell-name)
    (py-toggle-shells py-default-interpreter))

so python (not ipython) ends up getting run later in py-shell with:

(apply 'make-comint py-which-bufname py-shell-name nil args))

The doc for py-default-interpreter says:

    When the value containes `python', the variables `py-python-command' and
    `py-python-command-args' are consulted to determine the interpreter
    and arguments to use.

But I don't see that in python-mode.el. When py-shell calls py-toggle-shells,
passing py-default-interpreter as arg, it looks like that will be set to be the
value of py-shell-name.

So maybe the fix for me is just to (setq py-default-interpreter "ipython")

Yes, just checked, that solves the problem & I now get ipython running in the
*Python* buffer.

Revision history for this message
Andreas Roehler (a-roehler) wrote :

Am 27.08.2011 17:23, schrieb Terry Jones:
> Looking around in the efun of py-shell and playing inside emacs: I have
> py-shell-name nil and when this is run in py-shell, py-shell-name is set
> to "python".
>
> (when (null py-shell-name)
> (py-toggle-shells py-default-interpreter))
>
> so python (not ipython) ends up getting run later in py-shell with:
>
> (apply 'make-comint py-which-bufname py-shell-name nil args))
>
>
> The doc for py-default-interpreter says:
>
> When the value containes `python', the variables `py-python-command' and
> `py-python-command-args' are consulted to determine the interpreter
> and arguments to use.
>
> But I don't see that in python-mode.el. When py-shell calls py-toggle-shells,
> passing py-default-interpreter as arg, it looks like that will be set to be the
> value of py-shell-name.
>
> So maybe the fix for me is just to (setq py-default-interpreter
> "ipython")
>
> Yes, just checked, that solves the problem& I now get ipython running in the
> *Python* buffer.
>

Great. Looks like we should write a defcustom nearby...

Cheers,

Andreas

Revision history for this message
Andreas Roehler (a-roehler) wrote :

> Please let me know if I can help.
>
> Terry
>

Hi Terry,

there is an item were some help would speed up things a lot:

listing the features in prepare of a python-mode documentation.

Should you have time and being interested, we'll discuss the details,

Thanks,

Andreas

Revision history for this message
Andreas Roehler (a-roehler) wrote : Fwd: [IPython-dev] ipython.el is broken in 0.11

-------- Original-Nachricht --------
Betreff: [IPython-dev] ipython.el is broken in 0.11
Datum: Sat, 3 Sep 2011 00:12:22 -0300
Von: Pedro Kroger <email address hidden>
An: <email address hidden>

Hi,

congrats on the release, lots of good stuff!

But, ipython.el is broken in 0.11 (I tested with emacs 23.3).
This pull request uses the new --color=foo syntax:

https://github.com/ipython/ipython/pull/757

Also, completion is not working on ipython.el shell. I get things like
"Can't find completion for "os.path.""

Thanks,

Pedro

_______________________________________________
IPython-dev mailing list
<email address hidden>
http://mail.scipy.org/mailman/listinfo/ipython-dev

Revision history for this message
Andreas Roehler (a-roehler) wrote : Fwd: Re: [IPython-dev] ipython.el is broken in 0.11

Hi,

there are some bugs as reported. I'm on it.
Beside it might be worth taking notice of the following

-------- Original-Nachricht --------
Betreff: Re: [IPython-dev] ipython.el is broken in 0.11
Datum: Sat, 3 Sep 2011 11:15:33 +0100
Von: Thomas Kluyver <email address hidden>
An: Pedro Kroger <email address hidden>
CC: <email address hidden>

On 3 September 2011 04:12, Pedro Kroger <email address hidden> wrote:

> But, ipython.el is broken in 0.11 (I tested with emacs 23.3).
> This pull request uses the new --color=foo syntax:
>
> https://github.com/ipython/ipython/pull/757
>
> Also, completion is not working on ipython.el shell. I get things like
> "Can't find completion for "os.path.""
>

Thanks, Pedro. If you're comfortable working with emacs lisp, feel free to
make more extensive changes to ipython.el, or to write a new one. Paul
Ivanov recently wrote a very nice IPython integration layer for vim, using
the new ZMQ protocol. I'm sure emacs users would love something similar, but
so far no-one's been motivated to write it.

Best wishes,
Thomas

Changed in python-mode:
status: In Progress → Fix Committed
Changed in python-mode:
status: Fix Committed → Fix Released
Revision history for this message
Juan A Rodriguez (juant-rodri) wrote :

Hi all,

I'm new on the forum.
I had this same problem this afternoon with python-mode 6.0.3, and googleing a bit, i've arrived this post, where Terry Jones gives the solution by correcting some lines in the python-mode.el...

Terry Jones (terrycojones) wrote on 2011-08-27
   > [...] But I don't see that in python-mode.el. When py-shell calls py-toggle-shells,
   > passing py-default-interpreter as arg, it looks like that will be set to be the
   > value of py-shell-name.

   > So maybe the fix for me is just to (setq py-default-interpreter "ipython")
   > Yes, just checked, that solves the problem & I now get ipython running in the
   > *Python* buffer.

As i'm also a bit unexperienced wit Lisp...
Terry, would it be possible if you post me just exactly the part of the code you rearranged?
I can't get where you add this piece of code.

Thanks in advance,

Juan.

Revision history for this message
Terry Jones (terrycojones) wrote : [Bug 835151] Re: py-shell invoking python not ipython

Hola Juan

> Terry, would it be possible if you post me just exactly the part of the
> code you rearranged?

I'd love to help, but I'm afraid I upgraded python mode sometime later and
the error message and python (not ipython) invocation returned. I've been
too busy to investigate again.

Looks like earlier I just put

  (setq py-default-interpreter "ipython"
 py-python-command "ipython")

into my ~/.emacs and it worked. But nothing I say about Python mode should
be taken seriously. I have no idea if that was a good thing to try! :-)

Let me know if you find an answer & I'll do the same.

Un abrazo,
Terry

Changed in python-mode:
status: Fix Released → New
Revision history for this message
Andreas Roehler (a-roehler) wrote :

Am 07.03.2012 01:46, schrieb Terry Jones:
> Hola Juan
>

Hi Terry and Juan,

re-opened this because of the comments coming in - however don't see the issue yet.

Juan, may you check out the current trunk?
Please tell, should you need help for this.

Please consider to send a bug report or feature request at

https://bugs.launchpad.net/python-mode

should something not work as expected.

>> Terry, would it be possible if you post me just exactly the part of the
>> code you rearranged?
>
> I'd love to help, but I'm afraid I upgraded python mode sometime later and
> the error message and python (not ipython) invocation returned. I've been
> too busy to investigate again.
>
> Looks like earlier I just put
>
> (setq py-default-interpreter "ipython"
> py-python-command "ipython")
>
> into my ~/.emacs and it worked.

`py-default-interpreter' is just an alias BTW.

Likewise using M-x customize py-shell-name should make it survive upgrades.

If you want to have another default shell than shipped, there is no way than indicating that somehow.

Beside of this - with changes of py-shell-name taking a full-path, the bug titeling here might show up in some circumstances again.
Please send a report in that case.

   But nothing I say about Python mode should
> be taken seriously. I have no idea if that was a good thing to try! :-)
>
> Let me know if you find an answer& I'll do the same.
>
> Un abrazo,
> Terry
>

Revision history for this message
Andreas Roehler (a-roehler) wrote :

Changing of default Python shell made more explicit in README and INSTALL

Changed in python-mode:
status: New → Fix Committed
Revision history for this message
Juan A Rodriguez (juant-rodri) wrote :

Hi Terry & Andreas:

 Terry Jones (terrycojones) wrote 10 hours ago:

> Looks like earlier I just put

> (setq py-default-interpreter "ipython"
> py-python-command "ipython")
> into my ~/.emacs and it worked.

Terry, It didn't work for me...
I was able to load the ipython by adding to .emacs

     (setq py-shell-name "ipython")

as said here:
https://github.com/ipython/ipython/pull/1015

but when i evaluate the code, the output is given in the
standard python interpreter.

> Juan, may you check out the current trunk?
> Please tell, should you need help for this.

Andreas, i'm a newbie with all this stuff... With current trunk, do you refer to the latest version?
I tried it, and now the error turned out to be:

"File mode specification error: (void-variable py-mode-map)"

Any idea?

> Likewise using M-x customize py-shell-name should make it survive upgrades.
> If you want to have another default shell than shipped, there is no way than indicating that somehow.

How can I do this??

> Beside of this - with changes of py-shell-name taking a full-path, the bug titeling here might show up in some circumstances
> again.

Should I indicate the full path in here?
(setq py-shell-name "ipython")

Thanks so much to both of you. So kind people!

PS: Seriouly thinking about going back to 5.2.0...

Revision history for this message
Andreas Roehler (a-roehler) wrote :

Am 07.03.2012 13:11, schrieb Juan A Rodriguez:
> Hi Terry& Andreas:
>
> Terry Jones (terrycojones) wrote 10 hours ago:
>
>> Looks like earlier I just put
>
>> (setq py-default-interpreter "ipython"
>> py-python-command "ipython")
>> into my ~/.emacs and it worked.
>
> Terry, It didn't work for me...
> I was able to load the ipython by adding to .emacs
>
> (setq py-shell-name "ipython")
>
> as said here:
> https://github.com/ipython/ipython/pull/1015
>
> but when i evaluate the code, the output is given in the
> standard python interpreter.

if the shebang - which would precede - is right, it
is a bug.

I'll look for this

>
>> Juan, may you check out the current trunk?
>> Please tell, should you need help for this.
>
> Andreas, i'm a newbie with all this stuff... With current trunk, do you refer to the latest version?
> I tried it, and now the error turned out to be:
>
> "File mode specification error: (void-variable py-mode-map)"
>
> Any idea?

probably you are still loading (an old version of) ipython.el
>

ipython.el isn't needed any more, the latest version should not disturb however

>> Likewise using M-x customize py-shell-name should make it survive upgrades.
>> If you want to have another default shell than shipped, there is no way than indicating that somehow.
>
> How can I do this??
>
>> Beside of this - with changes of py-shell-name taking a full-path, the bug titeling here might show up in some circumstances
>> again.
>
> Should I indicate the full path in here?
> (setq py-shell-name "ipython")
>

No, only if you want to use a different IPython from default

> Thanks so much to both of you. So kind people!
>
> PS: Seriouly thinking about going back to 5.2.0...
>

Changed in python-mode:
status: Fix Committed → Triaged
milestone: 6.0.3 → 6.0.6
Revision history for this message
Juan A Rodriguez (juant-rodri) wrote :

Hi Andreas,

I have being trying all afternoon to make it work, but it looks like I can't.
With the newest versions of python-mode and ipython, i keep getting the error

   "Symbol's value as variable is void: py-mode-map"

...as I press "C-c !"

Andreas Roehler (a-roehler) wrote 1 hour ago:

> ipython.el isn't needed any more, the latest version should not disturb however

So, does it mean that all I need is the python-mode.el, because the ipython.el is included on it?

I tried as well wit a newer version
https://github.com/ipython/ipython/blob/master/docs/emacs/ipython.el

...and still doesn't works.

Maybe should I put something additional on my emacs init file?
I was able to get it working is with 5.2.0

Or I've just thought that my Python version (2.6.5) might be too old for this...

What do you think?

Cheers,
Juan.

Revision history for this message
Andreas Roehler (a-roehler) wrote :

Am 07.03.2012 19:25, schrieb Juan A Rodriguez:
> Hi Andreas,
>
> I have being trying all afternoon to make it work, but it looks like I can't.
> With the newest versions of python-mode and ipython, i keep getting the error
>
> "Symbol's value as variable is void: py-mode-map"
>
> ...as I press "C-c !"
>
> Andreas Roehler (a-roehler) wrote 1 hour ago:
>
>> ipython.el isn't needed any more, the latest version should not
> disturb however
>
> So, does it mean that all I need is the python-mode.el, because the
> ipython.el is included on it?

so far, yes. Are slight differences. which you should not notice.
If you do, it's a bug.

>
> I tried as well wit a newer version
> https://github.com/ipython/ipython/blob/master/docs/emacs/ipython.el
>
> ...and still doesn't works.
>
> Maybe should I put something additional on my emacs init file?
> I was able to get it working is with 5.2.0
>
> Or I've just thought that my Python version (2.6.5) might be too old for
> this...
>
> What do you think?

just don't load ipython.el, this error should be gone.

BTW being at the original bug here ipython->python

stay patient :)

cheers,

Andreas

>
>
> Cheers,
> Juan.
>

Revision history for this message
Andreas Roehler (a-roehler) wrote :

checked in a fix.
Can you try again?

Please re-open that report, if that python/ipython issue isn't gone

Changed in python-mode:
status: Triaged → Fix Committed
Revision history for this message
Juan A Rodriguez (juant-rodri) wrote :

Andreas,

I've tried it again with the fixed python-mode.el you submitted yesterday
Ok, so now I don't get that "py-mode-map error" : )
I'am able to load IPython in emacs properly, but when I run a piece of code, I get the output in standard python interpreter.
Looks kinda like they are not connecting...

So in brief, I got:
-Ipython 0.12
-python-mode.el 6.0.5
-...and the part of my .emacs refering to these programs looks like this:

        (setq load-path (cons "~/.emacs.d/" load-path))
        (setq py-shell-name "/usr/local/bin/ipython")

        (add-to-list 'load-path "/home/jrodriguez/.emacs.d/py_mode/")
        (setq py-install-directory "/home/jrodriguez/.emacs.d/py_mode/")
        (require 'python-mode)
        (setq auto-mode-alist (cons '("\\.py$" . python-mode) auto-mode-alist))
        (setq interpreter-mode-alist (cons '("python" . python-mode)
                                               interpreter-mode-alist))
        (autoload 'python-mode "python-mode" "Python editing mode." t)

        (setq ipython-command "/usr/local/bin/ipython")
        (setq py-python-command "/usr/local/bin/ipython")
        (require 'ipython)

I don't know why, but I got a feeling I'm missing/setting something wrong in my .emacs...

Thanks again,

Juan

Revision history for this message
Andreas Roehler (a-roehler) wrote :

Am 08.03.2012 15:00, schrieb Juan A Rodriguez:
> Andreas,
>
> I've tried it again with the fixed python-mode.el you submitted yesterday
> Ok, so now I don't get that "py-mode-map error" : )
> I'am able to load IPython in emacs properly, but when I run a piece of code, I get the output in standard python interpreter.

fixed today.

BTW when developing, start your session with a pull.
when working, rather not :)

> Looks kinda like they are not connecting...
>
> So in brief, I got:
> -Ipython 0.12
> -python-mode.el 6.0.5
> -...and the part of my .emacs refering to these programs looks like this:
>
> (setq load-path (cons "~/.emacs.d/" load-path))
> (setq py-shell-name "/usr/local/bin/ipython")
>
> (add-to-list 'load-path "/home/jrodriguez/.emacs.d/py_mode/")
> (setq py-install-directory "/home/jrodriguez/.emacs.d/py_mode/")
> (require 'python-mode)
> (setq auto-mode-alist (cons '("\\.py$" . python-mode) auto-mode-alist))
> (setq interpreter-mode-alist (cons '("python" . python-mode)
> interpreter-mode-alist))
> (autoload 'python-mode "python-mode" "Python editing mode." t)
>
> (setq ipython-command "/usr/local/bin/ipython")
> (setq py-python-command "/usr/local/bin/ipython")

py-python-command is an alias

there is just one default interpreter: py-shell-name

> (require 'ipython)

no, ipython is provided by ipython.el

>
>
> I don't know why, but I got a feeling I'm missing/setting something
> wrong in my .emacs...
>

Cheers,

Andreas

> Thanks again,
>
> Juan
>

Revision history for this message
Juan A Rodriguez (juant-rodri) wrote :

Hey Andreas,

Being trying the whole morning with the new fixed python-mode.el you submmited yesterday... but I'm having the same problem. :P
After loading a "file.py", and then "C-c !"; buffer splits with the IPython prompt, but the output is again given in the standard Python shell, turning into a single buffer, BTW.

I checked all the M-x customize-variable that might be affecting it, and they look right with IPython selected always its possible.

Andreas Roehler (a-roehler) wrote 20 hours ago

> py-python-command is an alias
> there is just one default interpreter: py-shell-name
>> (require 'ipython)
> no, ipython is provided by ipython.el

As well I made this changes to my init file as you indicated.

Anyway, would it be possible for you to send me by email the part of your .emacs referring to this Python/Ipython section?
This is because I just want to be sure the problem is not coming from it in case you are sure that with the last fix it should be working properly...

Thanks one more time, and sorry for being bothering you all the time! :)

Juan

Revision history for this message
Andreas Roehler (a-roehler) wrote :

Am 09.03.2012 15:54, schrieb Juan A Rodriguez:
> Hey Andreas,
>
> Being trying the whole morning with the new fixed python-mode.el you submmited yesterday... but I'm having the same problem. :P
> After loading a "file.py",

Hi,

please send some example of file.py

try from emacs -Q, only load python-mode.el, than this file

[ ... ]
>
> Anyway, would it be possible for you to send me by email the part of your .emacs referring to this Python/Ipython section?
> This is because I just want to be sure the problem is not coming from it in case you are sure that with the last fix it should be working properly...
>

Sure, it's not a secret. However it's designed to switch branches... Send it off-list.

Cheers,

Andreas

> Thanks one more time, and sorry for being bothering you all the time! :)
>
> Juan
>

Changed in python-mode:
status: Fix Committed → Fix Released
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Related blueprints

Remote bug watches

Bug watches keep track of this bug in other bug trackers.