spacemacs
spacemacs copied to clipboard
python layer: issues with conda setup and python inferior shell
Description :octocat:
I am trying to get python working, I use conda to manage my python installation.
But whenever I try to start a REPL , s i I get the following error
Error: (file-missing "Searching for program" "No such file or directory" "python")
if: Failed to start python shell properly
It seems to work for me fine when I include the following in my user-config
(use-package conda
:ensure t
:init
(setq conda-anaconda-home (expand-file-name "~/miniconda3"))
(setq conda-env-home-directory (expand-file-name "~/miniconda3")))
Which I found here: https://stackoverflow.com/questions/55175916/emacs-and-conda-workaround
The problem with that solution is that I loose out on all the other setup done in the python layer (e.g., can't send code to the REPL etc...)
Any help would be most appreciated.
Justin
System Info :computer:
- OS: gnu/linux
- Emacs: 27.1
- Spacemacs: 0.300.0
- Spacemacs branch: develop (rev. df15f8cc1)
- Graphic display: t
- Distribution: spacemacs
- Editing style: vim
- Completion: helm
- Layers:
((python :variables python-backend 'anaconda)
csv auto-completion emacs-lisp git helm
(markdown :variables markdown-command "pandoc")
multiple-cursors org spell-checking syntax-checking
(ranger :variables ranger-override-dired 'ranger ranger-show-preview t)
(mu4e variables: mu4e-org-compose-support t)
latex bibtex ess polymode imenu-list
(evil-snipe :variables evil-snipe-enable-alternate-f-and-t-behaviors t)
theming)
- System configuration features: XPM JPEG TIFF GIF PNG RSVG CAIRO SOUND GPM DBUS GSETTINGS GLIB NOTIFY INOTIFY ACL LIBSELINUX GNUTLS LIBXML2 FREETYPE HARFBUZZ M17N_FLT LIBOTF ZLIB TOOLKIT_SCROLL_BARS GTK3 X11 XDBE XIM MODULES THREADS LIBSYSTEMD JSON PDUMPER LCMS2 GMP
just move the two lines to user-config
And I don't understand
The problem with that solution is that I loose out on all the other setup done in the python layer (e.g., can't send code to the REPL etc...)
Those lines
(use-package conda
:ensure t
:init
(setq conda-anaconda-home (expand-file-name "~/miniconda3"))
(setq conda-env-home-directory (expand-file-name "~/miniconda3")))
were in my user-config. Not sure what two lines you are talking about, nothing I wrote was "two lines"
Anyways I recently figured out at least part of the issue, I found the conda layer and now have it setup like this:
(conda :variables conda-anaconda-home "/home/jds6696/miniconda3")
which seems to serve the same purpose as my use-package conda line.
Still I am having a problems getting most of the REPL stuff working with the python layer.
For example, I am having this weird problem where I try to send output to the REPL using
python-shell-send-region
rather than evaluating 5+5, showing the call in the REPL and the output. Instead it just adds another 3 >>> marks and shows me nothing. I am not sure what is going on here but I think if I figure out this problem it will explain some other more importnat issues I am running into but are harder to explain.
Notably, if I enter the REPL and type 5+5 and then ENTER, it works as expected.

In case its helpful, I do notice that the echo area reads Sent: 5+5... just nothing happends in the Inferior Python REPL buffer... not sure where to begin debuggging this.
You can just add
(setq conda-anaconda-home (expand-file-name "~/miniconda3"))
(setq conda-env-home-directory (expand-file-name "~/miniconda3"))
to user-config.
It's obvious what I was referring to if you read the source code https://github.com/syl20bnr/spacemacs/blob/2fd3eb3edbc7c09b825892ce53721120bb999504/layers/%2Btools/conda/packages.el#L30-L45
It's also okay if you just add them to :variables as you have done.
What's the shell you're using.
I see your just much much better at reading Elisp than me.
Anyways that was in my config.
Any idea on the Send to REPL issue?
Sent from my Mobile Device
On Jun 14, 2021, at 22:44, Lucius Hu @.***> wrote:
You can just add
(setq conda-anaconda-home (expand-file-name "~/miniconda3")) (setq conda-env-home-directory (expand-file-name "~/miniconda3")) to user-config.
It's obvious what I was referring to if you read the source code https://github.com/syl20bnr/spacemacs/blob/2fd3eb3edbc7c09b825892ce53721120bb999504/layers/%2Btools/conda/packages.el#L30-L45
It's also okay if you just add them to :variables as you have done.
What's the shell you're using.
— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub, or unsubscribe.
What's the shell you're using.
Zsh But for python it’s just the default python interpreter.
Sent from my Mobile Device
On Jun 14, 2021, at 22:48, Lucius Hu @.***> wrote:
What's the shell you're using.
— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub, or unsubscribe.
need steps to reproduce
I'm not able to reproduce the behaviours described above. Can you list the steps, with keyboard input, needed to reproduce it?
@jsilve24 Does your python command work on the command line?
In that case, maybe you can just move/delete the .spacemacs.env file in your .emacs.d dir and restart Spacemacs.
I.e for fixing the
Error: (file-missing "Searching for program" "No such file or directory" "python")
if: Failed to start python shell properly
Hmmm, Yes, it does work on the command line, it even works in the Inferior Python buffer if I just type it out. It just doesn't work when I try to send the line/region/whatever from a python-mode buffer to the inferior python REPL.
Also I don't seem to have a .spacemacs.env file in .emacs.d...
Justin
Daniel Nicolai @.***> writes:
@jsilve24 Does your python command work on the command line? In that case, maybe you can just move/delete the .spacemacs.env file in your .emacs.d dir and restart Spacemacs.
— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub, or unsubscribe.
Ah, the .spacemacs.env is probably in your home folder then (I got a bit confused because I use a .spacemacs.d configuratoin directory which holds my .spacemacs.env file). Anyway, you can always find the file with locate (SPC f l), as long as you update your locate database first. Or even better with SPC h d v spacemacs-env-vars-file or SPC f e e.
Also I read that whenever you are trying to start the REPL with , s i then you get the error. So now it means that your , s i does work correctly? If not then try to find and delete that spacemacs.env file and restart Spacemacs.
So yup, .spacemacs.env was in home directory. Deleted,
no luck.
Still get the same behavior , python-shell-send-line gives "Sent 5+5..." in echo area, REPL shows extra " >>>" but no sign of recieving input or output.
Justin
Daniel Nicolai @.***> writes:
Ah, the .spacemacs.env is probably in your home folder then (I got a bit confused because I use a .spacemacs.d configuratoin directory which holds my .spacemacs.env file. Anyway, you can always find the file with locate SPC f l, as long as you update your locate database first).
Also I read that whenever you are trying to start the REPL with , s i then you get the error. So now it means that your , s i does work correctly? If not then try to find and delete dat spacemacs.env file and restart Spacemacs.
— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub, or unsubscribe.
Okay, your python is probably working alright already. So it turns out that when using most send-to-repl functions the ouput does not get printed automatically (like it would when you type in the repl directly). So you have to send print(5+5). Or, to get the output printed directly, you have to use spacemacs/python-shell-send-statement (, s e).
Btw, you might prefer to use the ipython interpreter by setting the python-shell-interpreter to ipython...
this is just strange behaviour....
I'm not able to reproduce this. @jsilve24 You need to select the region before send it.
I've tried both python and ipython and it works fine.
Interesting, it works here like I described, also in vanilla Emacs. Maybe it is an Emacs 28.0.50 thing. And I don't have to select anything before sending anything (except when using send-region of course), all functions work fine. It would be bad if you had to select regions before sending because then it would make no sense to have all the different send-to-repl functions...
@dalanicolai He's clearly talking about send region while not selecting anything
For example, I am having this weird problem where I try to send output to the REPL using python-shell-send-region
So I am not sure what is the cause of this problem. I have tested it also in vanilla Emacs 27.2 and there also, the REPL shows no output when using the send to repl functions. I asked my brother, who uses Emacs 26.3, to test it and there things work fine. Now I am not sure if it depends on the Emacs version, but this is the only difference I noticed.
@lebensterben @jsilve24 So which Emacs version are you using?
@lebensterben He wrote a lot more than only that line you refer to
Also need to check the python version.
For me, Python version 3.8.5 Emacs version 27.1
The issue is not that I have not highlighted 5+5, I tried that.
If I wrap 5+5 in a print statement then I see the output >>> 10 (again not showing input).
Perhaps this is my own naivety / familiarity with R/ESS over Pythong, but overall this is not the behavior I would expect from a REPL. I would expect it to send / show both the input and output as if I had entered the line directly into the interpreter, where a print statement would not be necessary.
I just switched to the ipython interpreter. Exact same behavior exept now instead of lines starting with >>> they start with In [#]
:shrug:
@jsilve24 I expect the same behavior as you expect and this is indeed how usually sending input to a comint buffer works. My brother has python 3.8.5 also, and again, for him the output gets printed without wrapping it in a print function, but still for him also the input is not printed (although, I agree, it should). So, I would say for python, sending code to the REPL does not work properly on any installation.
I guess you discovered an Emacs bug as the python (REPL) functionality is part of Emacs.
Always glad to hear that its not my own incompetence.
It so rarely is something else though :)
Daniel Nicolai @.***> writes:
@jsilve24 I expect the same behavior as you expect and this is indeed how usually sending input to a comint buffer works. My brother has python 3.8.5 also, and again, for him the output gets printed without wrapping it in a print function, but still for him also the input is not printed (although, I agree, it should). So, I would say for python, sending code to the REPL does not work properly on any installation.
I guess you discovered an Emacs bug as the python (REPL) functionality is part of Emacs.
— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub, or unsubscribe.
Haha... yeah that must be comforting. I have created a bug report upstream:
bug#49073: Acknowledgement (28.0.50; python-send-to-repl functions misbehave)
I have discovered that probably the output does get printed if you have e.g. 5+5 only as first line of the file. As soon as you have more lines things start to break (at least it looks like that here).
I have discovered that probably the output does get printed if you have e.g. 5+5 only as first line of the file. As soon as you have more lines things start to break
Oh this sounds like a bug
@jsilve24 @dalanicolai Try this
(defun spacemacs/python-shell-send-line ()
(interactive)
(let ((python-mode-hook nil)
(orig-string (buffer-substring-no-properties (point-at-bol) (point-at-eol))))
(with-temp-buffer
(insert orig-string)
(python-shell-send-region (point-min) (point-max)))))
I get the output fine
In [8]: Out[8]: 10
but still no input. Also, In and out are on the same line which is a bit weird.
Lucius Hu @.***> writes:
@jsilve24 @dalanicolai Try this
(defun spacemacs/python-shell-send-line () (interactive) (let ((python-mode-hook nil) (orig-string (buffer-substring-no-properties (point-at-bol) (point-at-eol)))) (with-temp-buffer (insert orig-string) (python-shell-send-region (point-min) (point-max)))))
— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub, or unsubscribe.
In and out should be on the same line. That's the correct behaviour. You need to send a feature request to emacs upstream to change that.
And there's indeed no input. That's also the correct behaviour.
Also, this doesn't work with multi line input. It only fixes single line evaluation.
Whenever it's multiline, emacs put the active region in a temp file and execute that file. If you've a file
# test.py
5+5
6+6
and you do a python test.py
Then there's no output for sure.
So the current behaviour of emacs is certainly NOT incorrect. It's just counterintuitive.