5

I have the symptoms described here Input and Output does not show up in python mode, except this happens with python3 as interpreter as well as ipython, and I've tried the suggestions there for fixing ipython and have no improvement. show output from python-shell-send-region

With Ubuntu Linux, Emacs-25.2.2, the Python Inferior Shell does not show either the input nor the output I expect. I've tested with both python3 and ipython3, and I have the same symptom. Because I use R with Emacs-ESS, I had some expectation that Python with an inferior session would be similar, but, well, this seems to do nothing.

My init.el file has custom-set-variables so I use python3

(python-shell-interpreter "python3")

When I open a python code file, the Emacs status line says (Python) and to launch the interpreter, I either can use pull down menu Python -> Start Interpreter or M-x run-python. Either way, new buffer starts, looks like this:

In the python code buffer, I highlight some lines of code and use the pull down menu Python -> Eval Region. Emacs minibuffer says "Sent: import re ..." but, when using python3, the Inferior shell does not change at all. It displays neither input nor output.

I'll be specific. I'm using BeautifulSoup to read in an HTML file I saved. My Python region:

import re
from bs4 import BeautifulSoup

filename = "../workingdata/wp039-910.html"
soup = BeautifulSoup(open(filename, encoding='windows-1251'), "html.parser")

links = soup.find_all("a")
type(links)

type(links[4])

The Shell looks like this:

Python 3.6.3 (default, Oct  3 2017, 21:45:48) 
[GCC 7.2.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> python.el: native completion setup loaded
>>>

THat does not change when I highlight new code regions and run them, even if commands do trigger output

However, I can type a line into the shell and it shows the session did run those line.

type(links[4])

I notice, however, that the history of the Python shell does not include the lines that were submitted by python mode, only the one I manually typed in.

What I want is for this to behave like Emacs-ESS, where the code I run fills in the output buffer, and the output also appears there.

When I change the shell to ipython3 with this insertion in the init file:

(setq python-shell-interpreter "ipython3"
   python-shell-interpreter-args "--simple-prompt --pprint")

The problem is slightly different. I can see the prompt incrementing in the shell when I send a region, but never see any input or output. Here I highlighted a block of lines and use pull down Python -> Eval Region, and I see the counter increments from 1 to 2:

Python 3.6.3 (default, Oct  3 2017, 21:45:48) 
Type "copyright", "credits" or "license" for more information.

IPython 5.1.0 -- An enhanced Interactive Python.
?         -> Introduction and overview of IPython's features.
%quickref -> Quick reference.
help      -> Python's own help system.
object?   -> Details about 'object', use 'object??' for extra details.

In [1]: 
In [2]: 

And I can type commands there and it seems correct.

In [2]: links = soup.find_all("a")

In [3]: links[3]
Out[3]: 
<a class="a1" href="wp001e">English</a>

As it stands, this Inferior shell seems rather useless, if the only workable way to interact with it is to copy/paste from a py file at the prompt. I can't see any benefit in this and wonder if it is like this for everybody.

8
  • Apparently this solves it for some - github.com/jorgenschaefer/elpy/issues/924 - but causes separate issues for me. Commented Oct 12, 2019 at 4:42
  • You might want to try lpy as a cool alternative github.com/abo-abo/lpy
    – guibor
    Commented Oct 12, 2019 at 17:09
  • I have exactly the same problem, and found no solution. Can anyone tell if there is a way to fix this problem?
    – thibault
    Commented Mar 12, 2020 at 12:11
  • 1
    With IPython part that shows input increments. It won't print the output until you explicitly print it in your Python script like print(object). Regarding the input, Python doesn't work like R, R interpreter can echo the input, check the options, you can disable it. For example Rscript some_file.R doesn't echo the input, as far as I remember. Python interpreter doesn't have the option to echo the input, at least I have never found it. This has to be manually done, I think elpy package has some functions to do this, I can't remember.
    – Arktik
    Commented Mar 28, 2023 at 11:16
  • 1
    When you evaluate the region, does your code actually get evaluated? Can you see the new objects in the console?
    – Arktik
    Commented Mar 28, 2023 at 11:17

1 Answer 1

0

I had a similar issue, to be more specific about the comments above:

1) For https://github.com/jorgenschaefer/elpy/issues/924 (suggested by thelatemail), I simply added the suggested block to (add-hook 'python-mode-hook ...)

2) The second option (lpy) prints evaluated sexps/lines in the minibuffer, and has other really nice features

1
  • The answer is unclear. Please do not reference comments - they can be deleted at any time. Instead, integrate the information into the answer. And even your #1 is not too clear: show the code changes you made.
    – Drew
    Commented Oct 15, 2019 at 22:54

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.