syl20bnr / spacemacs

A community-driven Emacs distribution - The best editor is neither Emacs nor Vim, it's Emacs *and* Vim!
http://spacemacs.org
GNU General Public License v3.0
23.68k stars 4.89k forks source link

__PYTHON_EL_eval printouts in ipython REPL #15998

Closed guibor closed 1 year ago

guibor commented 1 year ago

Description :octocat:

Every time I call spacemacs/python-shell-send-region I get weird printouts of __PYTHON_EL_eval. I suppose this isn't directly related to spacemacs related but it is the outcome of the way the Python layer is set up.

Would be happy to get any help.

System Info :computer:

lebensterben commented 1 year ago

Is this a new behavior?

guibor commented 1 year ago

It's hard to know, I just updated my configuration to the latest develop. I have this error even when I use the python layer as is, with no modifications.

lebensterben commented 1 year ago

It's hard to know, I just updated my configuration to the latest develop.

it's not hard to know.

do you see this error before your recent update?

guibor commented 1 year ago

My previous setup used elpy (and lispy as well) and was very different.

I don't think it is related to something that changed recently in spacemacs, but I would be happy for pointers on how to solve this (this happens with the default python layer setup without any modification). From what I read in various places, it is probably related to Mac OS X and various issues with readline but I'm not an expert. Happy to provide more details if it can help find a solution.

lebensterben commented 1 year ago

if it's not related to spacemacs you should ask it elsewhere like reddit or stack overflow.

guibor commented 1 year ago

It is related to the Spacemacs Python layer and how it works with the REPL.

I have a fairly standard Mac OS X setup and am using the vanilla spacemacs Python layer as is in the develop branch to set it all up, with no modifications. I just can't say if the issue is a new behavior or not since I wasn't using the Python layer as is before.

lebensterben commented 1 year ago

how is this related to spacemacs?

can you reproduce the issue with emacs -Q?

guibor commented 1 year ago

After a lot of tinkering, the solution was to use

(setq python-shell-interpreter "ipython" python-shell-interpreter-args " -i )))

Previously the interpreter used the --simple-prompt flag and this led to the weird printouts.

This is related to spacemacs since this flag is configured in spacemacs//python-setup-shell. I'm not entirely sure when this flag should or should not be used, I remember having problems not using it in the past.

(on a side note, once this was changed, I still wasn't completely happy because the statements sent to the shell were not echoed, and I solved this by using a different function to send to shell).

lebensterben commented 1 year ago

what's your ipython version?

guibor commented 1 year ago

8.12

lebensterben commented 1 year ago

https://github.com/syl20bnr/spacemacs/blob/c6c508254f4552549f70af5d131dc7882f0d35d3/layers/%2Blang/python/funcs.el#L166

as long as the ipython version is greater than 5, it won't use --simple-prompt.

you should check whether emacs is using the correct ipython.

guibor commented 1 year ago
(replace-regexp-in-string
                            "\\(\\.dev\\)?[\r\n|\n]$" ""
                            (shell-command-to-string (format "\"%s\" --version" ipython)))

evaluates to "8.12.0" and as a result

(unless (version< version "5") " --simple-prompt")

evaluates to --simple-prompt, what am I missing?

lebensterben commented 1 year ago

I read it wrong.

It should have --simple-prompt since ipython 5.

Could you try setting it to

"-i --simple-prompt --InteractiveShell.display_page=True"

(ref: https://www.emacswiki.org/emacs/PythonProgrammingInEmacs#h5o-41)

guibor commented 1 year ago

Right, so when I do that I get the __PYTHON_EL_eval printouts again. Removing --simple-prompt solves the issue.

lebensterben commented 1 year ago

it does not make any sense

https://www.reddit.com/r/emacs/comments/12jexep/comment/jg5dyoq/

recently another person noted that adding --simple-prompt is needed to solve the exact problem.

lebensterben commented 1 year ago

please use git bisect to pin down the commit that introduced this issue.

https://github.com/syl20bnr/spacemacs/commits/develop/layers/%2Blang/python

here are commits that modified python layer.

lebensterben commented 1 year ago

also, see https://github.com/emacs-mirror/emacs/blob/fd4c9246fc8daea4965b868e80e0f2d9d544dc22/lisp/progmodes/python.el#L72-L73

it's advised by emacs upstream to set --simple-prompt.

guibor commented 1 year ago

It looks like the issue was related to also having to import readline, and not to --simple-prompt per se. Closing. Thanks for the help.

spacegoing commented 1 year ago

@guibor @lebensterben hey guys, im running into exactly the same issue (Ipython 8.12.0).

I got lost tracking your conversations. So please what is the problem and solution?

Many thanks!