GNU bug report logs - #29592
25.3; python does not print input or output in the inferior process

Previous Next

Package: emacs;

Reported by: Alex Branham <alex.branham <at> gmail.com>

Date: Wed, 6 Dec 2017 19:00:02 UTC

Severity: wishlist

Merged with 30632

Found in versions 25.3, 26.0.91

Fixed in version 28.1

Done: Lars Ingebrigtsen <larsi <at> gnus.org>

Bug is archived. No further changes may be made.

To add a comment to this bug, you must first unarchive it, by sending
a message to control AT debbugs.gnu.org, with unarchive 29592 in the body.
You can then email your comments to 29592 AT debbugs.gnu.org in the normal way.

Toggle the display of automated, internal messages from the tracker.

View this report as an mbox folder, status mbox, maintainer mbox


Report forwarded to bug-gnu-emacs <at> gnu.org:
bug#29592; Package emacs. (Wed, 06 Dec 2017 19:00:02 GMT) Full text and rfc822 format available.

Acknowledgement sent to Alex Branham <alex.branham <at> gmail.com>:
New bug report received and forwarded. Copy sent to bug-gnu-emacs <at> gnu.org. (Wed, 06 Dec 2017 19:00:02 GMT) Full text and rfc822 format available.

Message #5 received at submit <at> debbugs.gnu.org (full text, mbox):

From: Alex Branham <alex.branham <at> gmail.com>
To: bug-gnu-emacs <at> gnu.org
Subject: 25.3; python does not print input or output in the inferior process
Date: Wed, 06 Dec 2017 12:59:06 -0600
In python-mode (from python.el), writing

import pandas as pd
pd.Series([1, 2, 3, 4, 5])

after starting an inferior python process, selecting the buffer, and
running M-x python-shell-send-region no output is printed in the process
buffer even though the statements are evaluated.

If you manually type pd.Series([1, 2, 3, 4, 5]) into the python process
buffer, it prints

0    1
1    2
2    3
3    4
dtype: int64

I think ideally, Emacs should show that the statements are sent to the interpreter by printing them and also show their output so running python-shell-send-region from above would leave the inferior process buffer looking something like:

>>> import pandas as pd
>>> pd.Series([1, 2, 3, 4, 5])
0    1
1    2
2    3
3    4
4    5
dtype: int64
>>> 


In GNU Emacs 25.3.1 (x86_64-pc-linux-gnu, GTK+ Version 3.22.19)
 of 2017-09-16 built on juergen
Windowing system distributor 'The X.Org Foundation', version 11.0.11905000
Configured using:
 'configure --prefix=/usr --sysconfdir=/etc --libexecdir=/usr/lib
 --localstatedir=/var --with-x-toolkit=gtk3 --with-xft --with-modules
 'CFLAGS=-march=x86-64 -mtune=generic -O2 -pipe -fstack-protector-strong
 -fno-plt' CPPFLAGS=-D_FORTIFY_SOURCE=2
 LDFLAGS=-Wl,-O1,--sort-common,--as-needed,-z,relro,-z,now'

Configured features:
XPM JPEG TIFF GIF PNG RSVG IMAGEMAGICK SOUND GPM DBUS GCONF GSETTINGS
NOTIFY ACL GNUTLS LIBXML2 FREETYPE M17N_FLT LIBOTF XFT ZLIB
TOOLKIT_SCROLL_BARS GTK3 X11 MODULES

Important settings:
  value of $LANG: en_US.UTF-8
  locale-coding-system: utf-8-unix




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#29592; Package emacs. (Tue, 12 Dec 2017 23:29:02 GMT) Full text and rfc822 format available.

Message #8 received at 29592 <at> debbugs.gnu.org (full text, mbox):

From: Noam Postavsky <npostavs <at> users.sourceforge.net>
To: Alex Branham <alex.branham <at> gmail.com>
Cc: 29592 <at> debbugs.gnu.org
Subject: Re: bug#29592: 25.3;
 python does not print input or output in the inferior process
Date: Tue, 12 Dec 2017 18:28:01 -0500
severity 29592 wishlist
quit

Alex Branham <alex.branham <at> gmail.com> writes:

> In python-mode (from python.el), writing
>
> import pandas as pd
> pd.Series([1, 2, 3, 4, 5])
>
> after starting an inferior python process, selecting the buffer, and
> running M-x python-shell-send-region no output is printed in the process
> buffer even though the statements are evaluated.
>
> If you manually type pd.Series([1, 2, 3, 4, 5]) into the python process
> buffer, it prints
>
> 0    1
> 1    2
> 2    3
> 3    4
> dtype: int64
>
> I think ideally, Emacs should show that the statements are sent to the
> interpreter by printing them and also show their output so running
> python-shell-send-region from above would leave the inferior process
> buffer looking something like:
>
>>>> import pandas as pd
>>>> pd.Series([1, 2, 3, 4, 5])
> 0    1
> 1    2
> 2    3
> 3    4
> 4    5
> dtype: int64
>>>> 

python-shell-send-region works by saving to a temp file, and loading
that.  I think sending each statement separately should be a separate
command.




Severity set to 'wishlist' from 'normal' Request was from Noam Postavsky <npostavs <at> users.sourceforge.net> to control <at> debbugs.gnu.org. (Tue, 12 Dec 2017 23:29:03 GMT) Full text and rfc822 format available.

Merged 29592 30632. Request was from Noam Postavsky <npostavs <at> gmail.com> to control <at> debbugs.gnu.org. (Tue, 27 Feb 2018 23:44:02 GMT) Full text and rfc822 format available.

Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#29592; Package emacs. (Fri, 25 Feb 2022 21:59:02 GMT) Full text and rfc822 format available.

Message #15 received at 29592 <at> debbugs.gnu.org (full text, mbox):

From: Ben Sturmfels <ben <at> sturm.com.au>
To: Alex Branham <alex.branham <at> gmail.com>
Cc: 29592 <at> debbugs.gnu.org
Subject: Re: bug#29592: 25.3; python does not print input or output in the
 inferior process
Date: Sat, 26 Feb 2022 08:57:38 +1100
On Wed, 06 Dec 2017, Alex Branham wrote:

> In python-mode (from python.el), writing
>
> import pandas as pd
> pd.Series([1, 2, 3, 4, 5])
>
> after starting an inferior python process, selecting the buffer, and
> running M-x python-shell-send-region no output is printed in the process
> buffer even though the statements are evaluated.

I found that Python REPL output is displayed only if the python code is
on the first line of the buffer. Is this the same for you Alex?

For example, running `emacs -q`, I open /tmp/foo.py, and M-x run-python
(C-c C-p) to open the Python REPL. Then I switch focus back to the
foo.py buffer and enter 'abc' on the first line, including quotes. I run
M-x python-shell-send-statement (C-c C-e), Emacs says 'Sent: "abc"...'
and '>>> abc\n' is displayed in the REPL. If I add a newline before
'abc' and repeat, it says 'Sent: "abc"' and only ">>> " is printed to
the REPL.

Same issue when using M-x python-shell-send-region (C-c C-r) and
explicitly highlighting the 'abc' when it's not the first line in the
buffer.

I'm using GNU Emacs 27.2 (build 1, x86_64-pc-linux-gnu, GTK+ Version
3.24.30, cairo version 1.16.0). Windowing system distributor 'The X.Org
Foundation', version 11.0.12101002. System Description: Guix System

Regards,
Ben




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#29592; Package emacs. (Fri, 25 Feb 2022 23:01:01 GMT) Full text and rfc822 format available.

Message #18 received at 29592 <at> debbugs.gnu.org (full text, mbox):

From: Ben Sturmfels <ben <at> sturm.com.au>
To: Alex Branham <alex.branham <at> gmail.com>
Cc: 29592 <at> debbugs.gnu.org
Subject: Re: bug#29592: 25.3; python does not print input or output in the
 inferior process
Date: Sat, 26 Feb 2022 10:00:35 +1100
The GitHub ticket below for elpy also mentions this issue and includes some
"quick-and-dirty" that does seem to address the issue. The code works,
but I get an extra line break in the REPL when evaluating lines other
than the first line of the buffer.

https://github.com/jorgenschaefer/elpy/issues/924#issuecomment-314922197

> This is not an elpy issue, it also occurs with plain python-mode. It
> seems to be caused by certain versions of Python only. A quick-and-dirty
> fix is (in .emacs):
> 
> (defun python-shell-append-to-output (string)
>   (let ((buffer (current-buffer)))
>     (set-buffer (process-buffer (python-shell-get-process)))
>     (let ((oldpoint (point)))
>       (goto-char (process-mark (python-shell-get-process)))
>       (insert string)
>       (set-marker (process-mark (python-shell-get-process)) (point))
>       (goto-char oldpoint))
>     (set-buffer buffer)))
> 
> (defadvice python-shell-send-string
>     (around advice-python-shell-send-string activate)
>   (interactive)
>   (let* ((append-string1
>          (if (string-match "import codecs, os;__pyfile = codecs.open.*$" string)
>              (replace-match "" nil nil string)
>            string))
>         (append-string2
>          (if (string-match "^# -\\*- coding: utf-8 -\\*-\n*$" append-string1)
>              (replace-match "" nil nil append-string1)
>            append-string1))
>         (append-string
>          (if (string-match "^\n*$" append-string2)
>              (replace-match "" nil nil append-string2)
>            append-string2)))  
>     (python-shell-append-to-output
>      (concat (string-trim-right append-string) "\n")))
>   (if (called-interactively-p 'any)
>       (call-interactively (ad-get-orig-definition 'python-shell-send-string))
>     ad-do-it))




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#29592; Package emacs. (Sat, 26 Feb 2022 16:27:01 GMT) Full text and rfc822 format available.

Message #21 received at submit <at> debbugs.gnu.org (full text, mbox):

From: Augusto Stoffel <arstoffel <at> gmail.com>
To: Ben Sturmfels via "Bug reports for GNU Emacs, the Swiss army knife of
 text editors" <bug-gnu-emacs <at> gnu.org>
Cc: Alex Branham <alex.branham <at> gmail.com>, Ben Sturmfels <ben <at> sturm.com.au>,
 29592 <at> debbugs.gnu.org
Subject: Re: bug#29592: 25.3; python does not print input or output in the
 inferior process
Date: Sat, 26 Feb 2022 17:26:07 +0100
On Sat, 26 Feb 2022 at 08:57, Ben Sturmfels via "Bug reports for GNU Emacs, the Swiss army knife of text editors" <bug-gnu-emacs <at> gnu.org> wrote:

> On Wed, 06 Dec 2017, Alex Branham wrote:
>
>> In python-mode (from python.el), writing
>>
>> import pandas as pd
>> pd.Series([1, 2, 3, 4, 5])
>>
>> after starting an inferior python process, selecting the buffer, and
>> running M-x python-shell-send-region no output is printed in the process
>> buffer even though the statements are evaluated.
>
> I found that Python REPL output is displayed only if the python code is
> on the first line of the buffer. Is this the same for you Alex?
>
> For example, running `emacs -q`, I open /tmp/foo.py, and M-x run-python
> (C-c C-p) to open the Python REPL. Then I switch focus back to the
> foo.py buffer and enter 'abc' on the first line, including quotes. I run
> M-x python-shell-send-statement (C-c C-e), Emacs says 'Sent: "abc"...'
> and '>>> abc\n' is displayed in the REPL. If I add a newline before
> 'abc' and repeat, it says 'Sent: "abc"' and only ">>> " is printed to
> the REPL.
>
> Same issue when using M-x python-shell-send-region (C-c C-r) and
> explicitly highlighting the 'abc' when it's not the first line in the
> buffer.
>
> I'm using GNU Emacs 27.2 (build 1, x86_64-pc-linux-gnu, GTK+ Version
> 3.24.30, cairo version 1.16.0). Windowing system distributor 'The X.Org
> Foundation', version 11.0.12101002. System Description: Guix System

This was fixed in Emacs 28.

> Regards,
> Ben




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#29592; Package emacs. (Sat, 26 Feb 2022 16:27:02 GMT) Full text and rfc822 format available.

Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#29592; Package emacs. (Sun, 27 Feb 2022 13:00:02 GMT) Full text and rfc822 format available.

Message #27 received at 29592 <at> debbugs.gnu.org (full text, mbox):

From: Lars Ingebrigtsen <larsi <at> gnus.org>
To: Augusto Stoffel <arstoffel <at> gmail.com>
Cc: alex.branham <at> gmail.com, ben <at> sturm.com.au, 29592 <at> debbugs.gnu.org
Subject: Re: bug#29592: 25.3; python does not print input or output in the
 inferior process
Date: Sun, 27 Feb 2022 13:58:51 +0100
Augusto Stoffel <arstoffel <at> gmail.com> writes:

>> I'm using GNU Emacs 27.2 (build 1, x86_64-pc-linux-gnu, GTK+ Version
>> 3.24.30, cairo version 1.16.0). Windowing system distributor 'The X.Org
>> Foundation', version 11.0.12101002. System Description: Guix System
>
> This was fixed in Emacs 28.

OK; I'm closing this bug report, then.

-- 
(domestic pets only, the antidote for overdose, milk.)
   bloggy blog: http://lars.ingebrigtsen.no




bug marked as fixed in version 28.1, send any further explanations to 29592 <at> debbugs.gnu.org and Alex Branham <alex.branham <at> gmail.com> Request was from Lars Ingebrigtsen <larsi <at> gnus.org> to control <at> debbugs.gnu.org. (Sun, 27 Feb 2022 13:00:03 GMT) Full text and rfc822 format available.

Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#29592; Package emacs. (Sun, 27 Feb 2022 22:59:01 GMT) Full text and rfc822 format available.

Message #32 received at 29592 <at> debbugs.gnu.org (full text, mbox):

From: Ben Sturmfels <ben <at> sturm.com.au>
To: Augusto Stoffel <arstoffel <at> gmail.com>
Cc: alex.branham <at> gmail.com, 29592 <at> debbugs.gnu.org
Subject: Re: bug#29592: 25.3; python does not print input or output in the
 inferior process
Date: Mon, 28 Feb 2022 09:58:22 +1100
On Sat, 26 Feb 2022, Augusto Stoffel wrote:

> On Sat, 26 Feb 2022 at 08:57, Ben Sturmfels wrote:
>
>> I'm using GNU Emacs 27.2 (build 1, x86_64-pc-linux-gnu, GTK+ Version
>> 3.24.30, cairo version 1.16.0). Windowing system distributor 'The X.Org
>> Foundation', version 11.0.12101002. System Description: Guix System
>
> This was fixed in Emacs 28.

Thanks so much Augusto! I've just built Emacs 28.0.91 and can confirm
that the python-shell-send-statement output is showing in the REPL. :)

Regards,
Ben




bug archived. Request was from Debbugs Internal Request <help-debbugs <at> gnu.org> to internal_control <at> debbugs.gnu.org. (Mon, 28 Mar 2022 11:24:06 GMT) Full text and rfc822 format available.

This bug report was last modified 2 years and 28 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.