2

When I press C-c C-c(python-shell-send-buffer), I get output shown below. Afterwards when I do the same operation (C-c C-c) I always see Sent: #!/usr/bin/env python3... in the echo area.

  • I just want to see the output rather than seeing the send code.

=> How can I instead see only the output of the code in the echo area (if possible)? or show it on the minibuffer compact as possible and close it when C-g is pressed.

enter image description here

The output in the *Python* buffer:

#!/usr/bin/env python3
... 
... print("hello world")
import codecs, os;__pyfile = codecs.open('''/var/folders/mx/m3c2fd193h169gg6nd5x3p480000gn/T/pyK57xMh''', encoding='''utf-8''');__code = __pyfile.read().encode('''utf-8''');__pyfile.close();os.remove('''/var/folders/mx/m3c2fd193h169gg6nd5x3p480000gn/T/pyK57xMh''');exec(compile(__code, '''/Users/alper/code/doo.py''', 'exec'));
hello world
#!/usr/bin/env python3
... 
... print("hello world")
import codecs, os;__pyfile = codecs.open('''/var/folders/mx/m3c2fd193h169gg6nd5x3p480000gn/T/pyK57xMh''', encoding='''utf-8''');__code = __pyfile.read().encode('''utf-8''');__pyfile.close();os.remove('''/var/folders/mx/m3c2fd193h169gg6nd5x3p480000gn/T/pyK57xMh''');exec(compile(__code, '''/Users/alper/code/doo.py''', 'exec'));
hello world

My setup in my init file:

(add-to-list 'auto-mode-alist '("\\.py\\'" . python-mode))

(setq python-shell-interpreter "python3"
      python-shell-prompt-detect-failure-warning nil
      flycheck-python-pycompile-executable "python3"
      python-shell-completion-native-enable nil
      python-shell-completion-native-disabled-interpreters '("python3")
      elpy-shell-echo-output nil ; https://github.com/jorgenschaefer/elpy/issues/1550#issuecomment-574512892
  )

1 Answer 1

0

I encountered the same issue, and this is a solution I found that works for me:

pip3 install gnureadline
cd /Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/lib-dynload/
mv readline.cpython-37m-darwin.so readline.cpython-37m-darwin.so.bak

Some information that might help:
OS: MacOS Catalina 10.15.7.
Emacs: 27.2.
python: 3.7.4.

And here is an unofficial explanation that I understood: the gnureadline is the readline package that should be used by default here, it naturally comes with some version of python but maybe not the one that comes naturally with MacOS, according to the gnureadline's website. Instead the MacOS uses another packages for readline module. And if emacs need to use that readline, it requires some code(the unwanted 'import codecs blablabla') to do so. So here the solution used the gnureadline and unables the default readline module because the one(default readline) in lib-dynload comes before the one in side-packages(gnureadline). So we need to get the default one out of the way.

1
  • I tried this, but when I import gnureadline I get weird printouts every time I send a statement to shell - __PYTHON_EL_eval(...)
    – guibor
    May 2, 2023 at 5:32

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.