Completion not working in python script buffer

Bug #981991 reported by Richard Stanton
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
python-mode.el
Fix Released
High
Andreas Roehler

Bug Description

In r937, when I press ESC-TAB in my python script buffer, Emacs no longer hangs, which is good.

However, if I type, say, "ex" and then ESC-TAB, I get the message

Can't find completion for "ex"

Looking further, I see that there is a new buffer called *IPython*, with contents

In [1]: ---------------------------------------------------------------------------
NameError Traceback (most recent call last)
c:\projects\<ipython-input-1-ba21655add90> in <module>()
----> 1 print(';'.join(__IP.Completer.all_completions('ex'))) #PYTHON-MODE SILENT

NameError: name '__IP' is not defined

In [2]:

Changed in python-mode:
importance: Undecided → High
assignee: nobody → Andreas Roehler (a-roehler)
milestone: none → 6.0.6
Revision history for this message
Andreas Roehler (a-roehler) wrote : Re: [Bug 981991] [NEW] Completion not working in python script buffer

Am 15.04.2012 02:09, schrieb Richard Stanton:
> Public bug reported:
>
> In r937, when I press ESC-TAB in my python script buffer, Emacs no
> longer hangs, which is good.
>
> However, if I type, say, "ex" and then ESC-TAB, I get the message
>
> Can't find completion for "ex"
>
> Looking further, I see that there is a new buffer called *IPython*, with
> contents
>
>
> In [1]: ---------------------------------------------------------------------------
> NameError Traceback (most recent call last)
> c:\projects\<ipython-input-1-ba21655add90> in<module>()
> ----> 1 print(';'.join(__IP.Completer.all_completions('ex'))) #PYTHON-MODE SILENT
>
> NameError: name '__IP' is not defined
>
> In [2]:
>

thanks making a new report

can't reproduce with Emacs -Q and python-mode.el - see png attached.
Please send some example code

Revision history for this message
Richard Stanton (a-stanton) wrote :

Try your code but set

  (setq py-shell-name "ipython")

In your init.el first. Completion seems to work if I don't have this set, but fails if I do.

> -----Original Message-----
> From: <email address hidden> [mailto:<email address hidden>] On Behalf
> Of Andreas Roehler
> Sent: Saturday, April 14, 2012 11:53 PM
> To: Richard Stanton
> Subject: Re: [Bug 981991] [NEW] Completion not working in python script
> buffer
>
> Am 15.04.2012 02:09, schrieb Richard Stanton:
> > Public bug reported:
> >
> > In r937, when I press ESC-TAB in my python script buffer, Emacs no
> > longer hangs, which is good.
> >
> > However, if I type, say, "ex" and then ESC-TAB, I get the message
> >
> > Can't find completion for "ex"
> >
> > Looking further, I see that there is a new buffer called *IPython*,
> > with contents
> >
> >
> > In [1]: ---------------------------------------------------------------------------
> > NameError Traceback (most recent call last)
> > c:\projects\<ipython-input-1-ba21655add90> in<module>()
> > ----> 1 print(';'.join(__IP.Completer.all_completions('ex')))
> > ----> #PYTHON-MODE SILENT
> >
> > NameError: name '__IP' is not defined
> >
> > In [2]:
> >
>
> thanks making a new report
>
> can't reproduce with Emacs -Q and python-mode.el - see png attached.
> Please send some example code
>
>
> ** Attachment added: "ex1.png"
>
> https://bugs.launchpad.net/bugs/981991/+attachment/3069436/+files/ex1.
> png
>
> --
> You received this bug notification because you are subscribed to the bug
> report.
> https://bugs.launchpad.net/bugs/981991
>
> Title:
> Completion not working in python script buffer
>
> Status in An Emacs mode for editing Python code:
> New
>
> Bug description:
> In r937, when I press ESC-TAB in my python script buffer, Emacs no
> longer hangs, which is good.
>
> However, if I type, say, "ex" and then ESC-TAB, I get the message
>
> Can't find completion for "ex"
>
> Looking further, I see that there is a new buffer called *IPython*,
> with contents
>
>
> In [1]: ---------------------------------------------------------------------------
> NameError Traceback (most recent call last)
> c:\projects\<ipython-input-1-ba21655add90> in <module>()
> ----> 1 print(';'.join(__IP.Completer.all_completions('ex'))) #PYTHON-MODE
> SILENT
>
> NameError: name '__IP' is not defined
>
> In [2]:
>
> To manage notifications about this bug go to:
> https://bugs.launchpad.net/python-mode/+bug/981991/+subscriptions

Revision history for this message
Richard Stanton (a-stanton) wrote :

One more followup: I note that the code ipython is complaining about below is only supposed to be passed to ipython 0.10, but I'm using 0.12 (and ipython-version equals 12).

> -----Original Message-----
> From: Richard Stanton
> Sent: Sunday, April 15, 2012 4:28 PM
> To: 'Bug 981991'
> Subject: RE: [Bug 981991] [NEW] Completion not working in python script
> buffer
>
> Try your code but set
>
> (setq py-shell-name "ipython")
>
> In your init.el first. Completion seems to work if I don't have this set, but fails
> if I do.
>
>
> > -----Original Message-----
> > From: <email address hidden> [mailto:<email address hidden>] On Behalf
> > Of Andreas Roehler
> > Sent: Saturday, April 14, 2012 11:53 PM
> > To: Richard Stanton
> > Subject: Re: [Bug 981991] [NEW] Completion not working in python
> > script buffer
> >
> > Am 15.04.2012 02:09, schrieb Richard Stanton:
> > > Public bug reported:
> > >
> > > In r937, when I press ESC-TAB in my python script buffer, Emacs no
> > > longer hangs, which is good.
> > >
> > > However, if I type, say, "ex" and then ESC-TAB, I get the message
> > >
> > > Can't find completion for "ex"
> > >
> > > Looking further, I see that there is a new buffer called *IPython*,
> > > with contents
> > >
> > >
> > > In [1]: ---------------------------------------------------------------------------
> > > NameError Traceback (most recent call last)
> > > c:\projects\<ipython-input-1-ba21655add90> in<module>()
> > > ----> 1 print(';'.join(__IP.Completer.all_completions('ex')))
> > > ----> #PYTHON-MODE SILENT
> > >
> > > NameError: name '__IP' is not defined
> > >
> > > In [2]:
> > >
> >
> > thanks making a new report
> >
> > can't reproduce with Emacs -Q and python-mode.el - see png attached.
> > Please send some example code
> >
> >
> > ** Attachment added: "ex1.png"
> >
> >
> https://bugs.launchpad.net/bugs/981991/+attachment/3069436/+files/ex1.
> > png
> >
> > --
> > You received this bug notification because you are subscribed to the
> > bug report.
> > https://bugs.launchpad.net/bugs/981991
> >
> > Title:
> > Completion not working in python script buffer
> >
> > Status in An Emacs mode for editing Python code:
> > New
> >
> > Bug description:
> > In r937, when I press ESC-TAB in my python script buffer, Emacs no
> > longer hangs, which is good.
> >
> > However, if I type, say, "ex" and then ESC-TAB, I get the message
> >
> > Can't find completion for "ex"
> >
> > Looking further, I see that there is a new buffer called *IPython*,
> > with contents
> >
> >
> > In [1]: ---------------------------------------------------------------------------
> > NameError Traceback (most recent call last)
> > c:\projects\<ipython-input-1-ba21655add90> in <module>()
> > ----> 1 print(';'.join(__IP.Completer.all_completions('ex')))
> > #PYTHON-MODE SILENT
> >
> > NameError: name '__IP' is not defined
> >
> > In [2]:
> >
> > To manage notifications about this bug go to:
> > https://bugs.launchpad.net/python-mode/+bug/981991/+subscriptions

Revision history for this message
Richard Stanton (a-stanton) wrote :
Download full text (3.7 KiB)

Further investigating:

At line 11,029 in function ipython-complete, py-set-ipython-completion-command-string... returns the (wrong) result

"print(';'.join(__IP.Completer.all_completions('%s'))) #PYTHON-MODE SILENT\n"

> -----Original Message-----
> From: Richard Stanton
> Sent: Sunday, April 15, 2012 4:47 PM
> To: 'Bug 981991'
> Subject: RE: [Bug 981991] [NEW] Completion not working in python script
> buffer
>
> One more followup: I note that the code ipython is complaining about below
> is only supposed to be passed to ipython 0.10, but I'm using 0.12 (and
> ipython-version equals 12).
>
> > -----Original Message-----
> > From: Richard Stanton
> > Sent: Sunday, April 15, 2012 4:28 PM
> > To: 'Bug 981991'
> > Subject: RE: [Bug 981991] [NEW] Completion not working in python
> > script buffer
> >
> > Try your code but set
> >
> > (setq py-shell-name "ipython")
> >
> > In your init.el first. Completion seems to work if I don't have this
> > set, but fails if I do.
> >
> >
> > > -----Original Message-----
> > > From: <email address hidden> [mailto:<email address hidden>] On
> Behalf
> > > Of Andreas Roehler
> > > Sent: Saturday, April 14, 2012 11:53 PM
> > > To: Richard Stanton
> > > Subject: Re: [Bug 981991] [NEW] Completion not working in python
> > > script buffer
> > >
> > > Am 15.04.2012 02:09, schrieb Richard Stanton:
> > > > Public bug reported:
> > > >
> > > > In r937, when I press ESC-TAB in my python script buffer, Emacs no
> > > > longer hangs, which is good.
> > > >
> > > > However, if I type, say, "ex" and then ESC-TAB, I get the message
> > > >
> > > > Can't find completion for "ex"
> > > >
> > > > Looking further, I see that there is a new buffer called
> > > > *IPython*, with contents
> > > >
> > > >
> > > > In [1]: ---------------------------------------------------------------------------
> > > > NameError Traceback (most recent call last)
> > > > c:\projects\<ipython-input-1-ba21655add90> in<module>()
> > > > ----> 1 print(';'.join(__IP.Completer.all_completions('ex')))
> > > > ----> #PYTHON-MODE SILENT
> > > >
> > > > NameError: name '__IP' is not defined
> > > >
> > > > In [2]:
> > > >
> > >
> > > thanks making a new report
> > >
> > > can't reproduce with Emacs -Q and python-mode.el - see png attached.
> > > Please send some example code
> > >
> > >
> > > ** Attachment added: "ex1.png"
> > >
> > >
> >
> https://bugs.launchpad.net/bugs/981991/+attachment/3069436/+files/ex1.
> > > png
> > >
> > > --
> > > You received this bug notification because you are subscribed to the
> > > bug report.
> > > https://bugs.launchpad.net/bugs/981991
> > >
> > > Title:
> > > Completion not working in python script buffer
> > >
> > > Status in An Emacs mode for editing Python code:
> > > New
> > >
> > > Bug description:
> > > In r937, when I press ESC-TAB in my python script buffer, Emacs no
> > > longer hangs, which is good.
> > >
> > > However, if I type, say, "ex" and then ESC-TAB, I get the message
> > >
> > > Can't find completion for "ex"
> > >
> > > Looking further, I see that there is a n...

Read more...

Revision history for this message
Richard Stanton (a-stanton) wrote :
Download full text (5.3 KiB)

Further follow-up:

Things go wrong in py-set-ipython-completion-command-string because line 6678 sets ipython-version to 0.

The line that fails is

... (ipython-version
          (when (string-match "ipython" pyshellname)
            (string-to-number (substring (shell-command-to-string (concat pyshellname " -V")) 2 -1)))))

By comparison, the following almost identical line in py-set-shell-completion-environment works fine:

 (setq ipython-version (string-to-number (substring (shell-command-to-string (concat py-shell-name " -V")) 2 -1)))

The only difference between the two lines is that one refers to py-shell-name and the other to pyshellname.
 py-shell-name is set to "c:/python27/Scripts/ipython.bat", whereas pyshellname is set to "ipython".

The latter fails because is causes the following command to be passed to the shell: "ipython -V". Because I'm using the bash shell, this command fails (EPD ipython is started using a DOS batch file ipython.bat, which bash doesn't find when you only tell it to look for "ipython").

It seems to me that both should use py-shell-name, as this would avoid the problem.

> -----Original Message-----
> From: Richard Stanton
> Sent: Sunday, April 15, 2012 5:03 PM
> To: 'Bug 981991'
> Subject: RE: [Bug 981991] [NEW] Completion not working in python script
> buffer
>
> Further investigating:
>
> At line 11,029 in function ipython-complete, py-set-ipython-completion-
> command-string... returns the (wrong) result
>
> "print(';'.join(__IP.Completer.all_completions('%s'))) #PYTHON-MODE
> SILENT\n"
>
> > -----Original Message-----
> > From: Richard Stanton
> > Sent: Sunday, April 15, 2012 4:47 PM
> > To: 'Bug 981991'
> > Subject: RE: [Bug 981991] [NEW] Completion not working in python
> > script buffer
> >
> > One more followup: I note that the code ipython is complaining about
> > below is only supposed to be passed to ipython 0.10, but I'm using
> > 0.12 (and ipython-version equals 12).
> >
> > > -----Original Message-----
> > > From: Richard Stanton
> > > Sent: Sunday, April 15, 2012 4:28 PM
> > > To: 'Bug 981991'
> > > Subject: RE: [Bug 981991] [NEW] Completion not working in python
> > > script buffer
> > >
> > > Try your code but set
> > >
> > > (setq py-shell-name "ipython")
> > >
> > > In your init.el first. Completion seems to work if I don't have this
> > > set, but fails if I do.
> > >
> > >
> > > > -----Original Message-----
> > > > From: <email address hidden> [mailto:<email address hidden>] On
> > Behalf
> > > > Of Andreas Roehler
> > > > Sent: Saturday, April 14, 2012 11:53 PM
> > > > To: Richard Stanton
> > > > Subject: Re: [Bug 981991] [NEW] Completion not working in python
> > > > script buffer
> > > >
> > > > Am 15.04.2012 02:09, schrieb Richard Stanton:
> > > > > Public bug reported:
> > > > >
> > > > > In r937, when I press ESC-TAB in my python script buffer, Emacs
> > > > > no longer hangs, which is good.
> > > > >
> > > > > However, if I type, say, "ex" and then ESC-TAB, I get the
> > > > > message
> > > > >
> > > > > Can't find completion for "ex"
> > > > >
> > > > > Looking further, I see t...

Read more...

Revision history for this message
Richard Stanton (a-stanton) wrote :
Download full text (6.3 KiB)

More follow-up, all using the test file:

Print "Hi, Richard"
ex

1) I switched from using bash as my shell to using the default (Windows) shell, with py-shell-name set to "ipython". Completion now works if I press ESC-TAB after the end of the second line.

2) Same as #1, but this time with py-shell-name set to "c:/python27/Scripts/ipython.bat"
Now completion fails again, even with the Windows default shell.

> -----Original Message-----
> From: Richard Stanton
> Sent: Sunday, April 15, 2012 9:22 PM
> To: 'Bug 981991'
> Subject: RE: [Bug 981991] [NEW] Completion not working in python script
> buffer
>
> Further follow-up:
>
> Things go wrong in py-set-ipython-completion-command-string because line
> 6678 sets ipython-version to 0.
>
> The line that fails is
>
> ... (ipython-version
> (when (string-match "ipython" pyshellname)
> (string-to-number (substring (shell-command-to-string (concat
> pyshellname " -V")) 2 -1)))))
>
> By comparison, the following almost identical line in py-set-shell-completion-
> environment works fine:
>
> (setq ipython-version (string-to-number (substring (shell-command-to-
> string (concat py-shell-name " -V")) 2 -1)))
>
> The only difference between the two lines is that one refers to py-shell-
> name and the other to pyshellname.
> py-shell-name is set to "c:/python27/Scripts/ipython.bat", whereas
> pyshellname is set to "ipython".
>
> The latter fails because is causes the following command to be passed to the
> shell: "ipython -V". Because I'm using the bash shell, this command fails (EPD
> ipython is started using a DOS batch file ipython.bat, which bash doesn't find
> when you only tell it to look for "ipython").
>
> It seems to me that both should use py-shell-name, as this would avoid the
> problem.
>
>
> > -----Original Message-----
> > From: Richard Stanton
> > Sent: Sunday, April 15, 2012 5:03 PM
> > To: 'Bug 981991'
> > Subject: RE: [Bug 981991] [NEW] Completion not working in python
> > script buffer
> >
> > Further investigating:
> >
> > At line 11,029 in function ipython-complete,
> > py-set-ipython-completion- command-string... returns the (wrong)
> > result
> >
> > "print(';'.join(__IP.Completer.all_completions('%s'))) #PYTHON-MODE
> > SILENT\n"
> >
> > > -----Original Message-----
> > > From: Richard Stanton
> > > Sent: Sunday, April 15, 2012 4:47 PM
> > > To: 'Bug 981991'
> > > Subject: RE: [Bug 981991] [NEW] Completion not working in python
> > > script buffer
> > >
> > > One more followup: I note that the code ipython is complaining about
> > > below is only supposed to be passed to ipython 0.10, but I'm using
> > > 0.12 (and ipython-version equals 12).
> > >
> > > > -----Original Message-----
> > > > From: Richard Stanton
> > > > Sent: Sunday, April 15, 2012 4:28 PM
> > > > To: 'Bug 981991'
> > > > Subject: RE: [Bug 981991] [NEW] Completion not working in python
> > > > script buffer
> > > >
> > > > Try your code but set
> > > >
> > > > (setq py-shell-name "ipython")
> > > >
> > > > In your init.el first. Completion seems to work if I don't have
> > > > this s...

Read more...

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

seems the relations between shebang, completion-function and py-shell-name must be re-considered

Changed in python-mode:
status: New → In Progress
Revision history for this message
Richard Stanton (a-stanton) wrote : RE: [Bug 981991] Re: Completion not working in python script buffer

I agree. In particular, while on Unix machines the idea of a "default" python installation may make sense, it's not so obvious on a Windows machine, where whatever version of python is installed, it's not that likely to be found in /usr/bin, and may well not be in the user's path at all. Given this, you can't read too much into whether the user specifies a fully qualified path name for (i)python, and can't assume that running the command "ipython" will actually achieve anything.

Maybe we want to allow the user to specify a full path for both the default python and default ipython commands, and use these (if specified) by default whenever a python or ipython shell is required, as well as having one more flag for whether python or ipython ought to be used when C-c C-c is typed.

> -----Original Message-----
> From: <email address hidden> [mailto:<email address hidden>] On Behalf
> Of Andreas Roehler
> Sent: Sunday, April 15, 2012 10:25 PM
> To: Richard Stanton
> Subject: [Bug 981991] Re: Completion not working in python script buffer
>
> seems the relations between shebang, completion-function and py-shell-
> name must be re-considered
>
> ** Changed in: python-mode
> Status: New => In Progress
>
> --
> You received this bug notification because you are subscribed to the bug
> report.
> https://bugs.launchpad.net/bugs/981991
>
> Title:
> Completion not working in python script buffer
>
> Status in An Emacs mode for editing Python code:
> In Progress
>
> Bug description:
> In r937, when I press ESC-TAB in my python script buffer, Emacs no
> longer hangs, which is good.
>
> However, if I type, say, "ex" and then ESC-TAB, I get the message
>
> Can't find completion for "ex"
>
> Looking further, I see that there is a new buffer called *IPython*,
> with contents
>
>
> In [1]: ---------------------------------------------------------------------------
> NameError Traceback (most recent call last)
> c:\projects\<ipython-input-1-ba21655add90> in <module>()
> ----> 1 print(';'.join(__IP.Completer.all_completions('ex'))) #PYTHON-MODE
> SILENT
>
> NameError: name '__IP' is not defined
>
> In [2]:
>
> To manage notifications about this bug go to:
> https://bugs.launchpad.net/python-mode/+bug/981991/+subscriptions

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

please re-open if not done

Changed in python-mode:
status: In Progress → Fix Committed
Changed in python-mode:
status: Fix Committed → Fix Released
Revision history for this message
Richard Stanton (a-stanton) wrote :

With py-shell-name to "ipython", when I visit a python script file two Python buffers are created, one called *Python* and one called *IPython*. If I press ESC TAB to complete in the script buffer, Emacs hangs. If I get out of the hang by pressing C-g, then look in the *Python* buffer, it contains:

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

Completion works if I type M-x ipython-complete instead of typing ESC-TAB.

Changed in python-mode:
status: Fix Released → New
Changed in python-mode:
status: New → Confirmed
milestone: 6.0.6 → 6.0.7
Revision history for this message
Yaroslav Halchenko (yarikoptic) wrote :

Hi guys,
I am test driving on Debian
Barry's
http://barry.warsaw.us/debian/python-mode_6.0.6-1.dsc
and 'out of the box' (I moved my .emacs .emacs.d away, python is stock Python 2.7.2+ (default, Nov 30 2011, 19:22:03) ) M-TAB stalls on me if I try to complete anything.

if I \C-g it to get control back then in the python terminal it appears

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

or actually

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

if I do not first start interpreter (C-!) manually

how could I troubleshoot WTF?

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

Am 23.04.2012 23:29, schrieb Yaroslav Halchenko:
> Hi guys,
> I am test driving on Debian
> Barry's
> http://barry.warsaw.us/debian/python-mode_6.0.6-1.dsc
> and 'out of the box' (I moved my .emacs .emacs.d away, python is stock Python 2.7.2+ (default, Nov 30 2011, 19:22:03) ) M-TAB stalls on me if I try to complete anything.
>
> if I \C-g it to get control back then in the python terminal it appears
>
>>>> Traceback (most recent call last):
> File "<stdin>", line 1, in<module>
> NameError: name 'emacs' is not defined

means the modul defined in emacs2.py, or emacs3.py
is not loaded

needed by run-python's command using emacs.eexecfile

will look for this

>
> or actually
>
>>>> Traceback (most recent call last):
> File "<stdin>", line 1, in<module>
> NameError: name 'nil' is not defined

see it

>
>
> if I do not first start interpreter (C-!) manually

that was always required

tried to avoid this, but not successfully as it seems.

>
> how could I troubleshoot WTF?
>

No easy way out AFAIS

A running Python shell always was needed for completion.

With the exeption of Pymacs based py-complete..., which might fail with Python3

py-shell-complete opens a shell but fails at first time nonetheless

Fabián E. Gallina's design seems to offer a solution - however it's run-shell is
not backward compatible with previous python.el, already build in here to some extend.

Adapting the later seems the most promising option at longer run for me.

Thanks!

Andreas

Revision history for this message
Barry Warsaw (barry) wrote :

On Apr 24, 2012, at 07:35 AM, Andreas Röhler wrote:

>Am 23.04.2012 23:29, schrieb Yaroslav Halchenko:
>> Hi guys,
>> I am test driving on Debian
>> Barry's
>> http://barry.warsaw.us/debian/python-mode_6.0.6-1.dsc
>> and 'out of the box' (I moved my .emacs .emacs.d away, python is stock Python 2.7.2+ (default, Nov 30 2011, 19:22:03) ) M-TAB stalls on me if I try to complete anything.
>>
>> if I \C-g it to get control back then in the python terminal it appears
>>
>>>>> Traceback (most recent call last):
>> File "<stdin>", line 1, in<module>
>> NameError: name 'emacs' is not defined
>
>means the modul defined in emacs2.py, or emacs3.py
>is not loaded

Where do these come from?

Changed in python-mode:
status: Confirmed → Fix Committed
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

Bug attachments

Remote bug watches

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