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.69k stars 4.89k forks source link

ipython is not the default interpreter #16001

Closed guibor closed 1 year ago

guibor commented 1 year ago

Description :octocat:

In README.org, it is indicated that "ipython" is the default interpreter for the python shell: "If ipython is available in system executable search paths, ipython will be used to launch python shell".

When I check the value of python-shell-interpreter it is equal to "/opt/homebrew/bin/ipython" and spacemacs--python-shell-interpreter-origin is equal to "python3" ((eval (car (get 'python-shell-interpreter 'standard-value))) evaluates to "python3"). As a result, (or (null python-shell-interpreter) (equal python-shell-interpreter spacemacs--python-shell-interpreter-origin)) is nil and the entire environment isn't setup correctly unless I manually set python-shell-interpreter to "ipython".

Reproduction guide :beetle:

Observed behaviour: :eyes: :broken_heart: python3 shell is launched unless python-shell-interpreter is manually set to "ipython"

Expected behaviour: :heart: :smile: ipython shell starts.

System Info :computer:

lebensterben commented 1 year ago

tagging @sunlin7 since he has recently contributed to python layer.

sunlin7 commented 1 year ago

Hi @guibor You mentioned the statement is in the function spacemacs//python-setup-shell, which will try to setup the two variables: python-shell-interpreter and python-shell-interpreter-args. If you already got the correct value python-shell-interpreter (as your comments, it's "ipython"), the function should skip to change the variables.

guibor commented 1 year ago

README.org explains that ipython is default, when in reality the default is whatever (eval (car (get 'python-shell-interpreter 'standard-value))) evaluates to. So either the code is incorrect or the documentation is.

Note that a few commits ago, the logic was as below (which indeed defaults to ipython), and this changed for some reason:

(if (spacemacs/pyenv-executable-find "ipython")
      (progn (setq python-shell-interpreter "ipython")
             (if (version< (replace-regexp-in-string "\\(\\.dev\\)?[\r\n|\n]$" "" (shell-command-to-string (format "\"%s\" --version" (string-trim (spacemacs/pyenv-executable-find "ipython"))))) "5")
                 (setq python-shell-interpreter-args "-i")
               (setq python-shell-interpreter-args "--simple-prompt -i")))
    (progn
      (setq python-shell-interpreter-args "-i")
      (setq python-shell-interpreter "python")))
sunlin7 commented 1 year ago

The follow commit/conversation has many details for how to determine the python shell interpreter. https://github.com/syl20bnr/spacemacs/pull/15848

The document says:

If =ipython= is available in system executable search paths, =ipython= will be used to launch python shell; otherwise, default =python= interpreter will be used. You may change your system executable search path by activating a virtual environment.

For your case, it seems you have local virtual environments ?

guibor commented 1 year ago

I do not have a local virtual environment. What do you expect (eval (car (get 'python-shell-interpreter 'standard-value))) to evaluate to?

sunlin7 commented 1 year ago

That will give the standard value, which may be different from the customer value. Your initial comment says

python-shell-interpreter it is equal to "/opt/homebrew/bin/ipython"

That indicate it already get the ipython, no need to manually change the value. Or if the value is manually configured by user, then the spacemacs//python-setup-shell won't change anything.

guibor commented 1 year ago

I did not change the value and it was not manually configured - indeed the the default should be ipython. This was the behavior in previous versions of this layer - but now it defaults to (eval (car (get 'python-shell-interpreter 'standard-value))) which is just python3.

lebensterben commented 1 year ago

https://github.com/emacs-mirror/emacs/blob/b28d44d4226497c4b2582bc15a59fc817eb3ce0a/lisp/progmodes/python.el#L2548

standard-value of python-she'll-interpreter will be python3 or python and never ipython.

guibor commented 1 year ago

But the documentation (README.org) says that ipython is default. Furthermore, this was the behavior in the past:

(defun spacemacs//python-setup-shell (&rest args)
  (if (spacemacs/pyenv-executable-find "ipython")
      (progn (setq python-shell-interpreter "ipython")
             (if (version< (replace-regexp-in-string "\\(\\.dev\\)?[\r\n|\n]$" "" (shell-command-to-string (format "\"%s\" --version" (string-trim (spacemacs/pyenv-executable-find "ipython"))))) "5")
                 (setq python-shell-interpreter-args "-i")
               (setq python-shell-interpreter-args "--simple-prompt -i")))
    (progn
      (setq python-shell-interpreter-args "-i")
      (setq python-shell-interpreter "python")))) 
lebensterben commented 1 year ago

I am describing a bug. I am not referring to documentation even for once.

sunlin7 commented 1 year ago

Hi @guibor

Still unable get your key point. Do you have any suggestions on code change or document change? Then maybe can help me to understand what's your concern.

The documents said ipython in the path case:

If =ipython= is available in system executable search paths, =ipython= will be used to launch python shell; otherwise, default =python= interpreter will be used. You may change your system executable search path by activating a virtual environment.

cremacs1 commented 1 year ago

See also #15873. I think my diagnosis is accurate:

I use conda, but I believe the issue is somewhere in the commit; reverting to b28d65b7a, python-shell-interpreter becomes "ipython", but using b28d65b7a (or HEAD), it has the value "python3". I also verified that the same behavior occurs when not using conda (removing the entire anaconda subtree from PATH) and on a fresh install of spacemacs.

sunlin7 commented 1 year ago

trying to reproduce on my local now.

sunlin7 commented 1 year ago

@guibor please help verify the solution #16011 , thanks

guibor commented 1 year ago

Thanks this fixes the issue for me!

sunlin7 commented 1 year ago

Thanks, merged.