I do a lot of R coding on Emacs – on Windows – using the wonderfulESS package. What I particularly like is that I can:
- start an R session, and then send lines or regions of the script I'm working on to that session
- send the whole script to be evaluated
- switch back and forth between R session and script editing
ESS also provides some documentation when inputting an R function (for example which arguments it requires) and some autocompletion features. But these are less important to me than the above three.
Can you suggest an Emacs mode for working with python scripts, similar to ESS in the three points above? (I have an Anaconda Windows installation.)
I've exploredelpy,but it's extremely slow (often completely freezes Emacs) and doesn't seem to have the possibility of sending lines to the interpreter. It has the right functionality but can be too slow in its base configuration. Probably it tries to do too much; for example it gives information about imported packages but frankly I don't need that. No project-management help is needed either.
I've heard ofanaconda mode but it doesn't seem to provide interaction with an interpreter: only autocompletion and documentation. I've also heard ofpython mode but haven't understood if it provides interaction with a python interpreter. Finally, Jedi is a total mystery, and EIN doesn't seem to be designed for scripting.
It seems that with python part of the problem is also the choice of interpreter, if I understood correctly. In this case, which python interpreter would be best, to achieve something similar to the R+ESS seamless interaction?
Most related questions on StackExchange are 4–6 years old; presumably a lot has changed in the meantime.
Thank you all.
- 2There are plans to add python support to ESS in the not so distant future. Somewhere in the range of 6-12 months I would say.VitoshKa– VitoshKa2020-04-04 19:32:03 +00:00CommentedApr 4, 2020 at 19:32
- That's great news. Looking forward to it.pglpm– pglpm2020-04-05 12:22:15 +00:00CommentedApr 5, 2020 at 12:22
1 Answer1
I managed to set up something close to my requirements above. Here it is, for people who may have my same needs.
Let me stress that such requirements are very subjective, so the set-up below is not meant as a fit-all solution. It specifically addresses Windows users.
The setup involves the python distribution and Emacs's configuration:
Python distribution
I had to use the one frompython.org. I installed several packages throughpip – includingnumpy,jupyter,panda – and the install went smoothly.
I see most people recommend the Anaconda distribution, which is surely great owing to the possibility of working in "conda environments". But this possibility turned out to be a problem for me.
From what I saw, even if you only have thebase conda environment,you still need to activate it before using any python executables. This means that Emacs cannot simply call, say,ipython.exe: it needs first to callactivate base andthen to callipython. Alternatively you could open a command or cygwin prompt,activate base there, and then start Emacs from that prompt. This would be a hassle for me. I don't need conda environments, so I can do fine with the python.org distribution. (If you do need conda environments, maybe the remarks above may help you).
Emacs configuration
In my question (now edited) I was too harsh regardingelpy. It works smoothly if you unselect some of its modules.
So if you, like me, don't need elpy's full documentation and project-management capabilities, I recommend the following settings, through Emacs'scustomize-apropos:
Elpy Modules: I activate only:
- Inline code completion
- Show function signatures
- Show the virtualenv in the mode line
elpy-project-root is set to
nil. This is useful if you have many files and subdirectories, which otherwise elpy would scan, making Emacs freeze from time to time.Elpy Shell Starting Directory is set to
Current directory, for the same reason.Elpy Shell Use Project Root is toggled
off, for the same reason.
You can also specify the location of your python distribution in the customizable variablePython Shell Exec Path. In my case I set it toc:/ProgramData/Python38-32/ andc:/ProgramData/Python38-32/Scripts/. This way python doesn't need to be put in you PATH environment variable.
Finally, for the python shell interpreter I customized
- Python Shell Interpreter to
ipython
and
- Python Shell Interpreter Args to
-i --simple-prompt
according toelpy's documentation. I tried the other alternatives given there too, and all worked fine. I can also see plots made withmatplotlib.
Elpy provides several commands for sending lines, regions, or the whole buffer to the interpreter. Seethe documentation here.
I hope this set-up will help other Emacs-python-Windows users.
If you know of workarounds to Anaconda's "activate" problem, please do share them in the comments!
Explore related questions
See similar questions with these tags.
