Questions tagged [python]
use for Python programming language in Emacs. Emacs supports several versions of the language implementation, versions, and coding styles. Python questions should augment with additional tags as appropriate as described in the description below.
630 questions
0
votes
0
answers
815
views
Blacken installed but is giving the error that is isn't installed
I am running Emasc 26.2 on Windows 10 and have installed black via pip and installed blacken via melpa but when I enable blacken-mode it doesn't change any of the formatting even when I intentionally ...
2
votes
1
answer
69
views
Include lines in tangled source code but not in executed code block
The title might be slightly confusing. What I mean is this. Let's say I have a code block which has some error checking code. If there is an error, the (tangled) program should not continue past that ...
0
votes
1
answer
2k
views
How can I start IPython from emacs
I deleted my old Python installation, so the only Python installation remaining is the one inside Anaconda. when I start Spyder I get:
Python 3.7.4 (default, Aug 9 2019, 18:34:13) [MSC v.1915 64 bit ...
2
votes
0
answers
96
views
How to move by defun without moving up a level?
I am attempting to navigate methods in a file. Typically these are javascript or python files, which have a classes at the "top level", which in turn have methods nested within those ...
4
votes
1
answer
4k
views
Automatically activating python virtual environments with pyvenv
I am using pyvenv with doom and am trying to have my python virtual environments automatically loaded when I enter a certain project.
I saw this relevant issue on pyvenv and have added the following ...
5
votes
0
answers
343
views
Python automatically add import statement
Is there a way to automatically add imports to python code within emacs?
def f(x: str) -> List[str]:
I want to be able to have my guess over "List" press a key binding and magically add ...
1
vote
1
answer
269
views
How do I make emacs indent relative to the beginning of the previous line?
Here's how emacs indents e.g. Python code:
a = myfun(b,
c)
I'd like it to be this way:
a = myfun(b,
c)
Reasoning? If I later replace myfun with myfunction, in the first case it becomes:...
1
vote
2
answers
637
views
Pandas data frame as table
I'm enjoying learning org-babel to write literate documents and am trying to include summary tables produced by Pandas describe().
I found an old thread with some answers but none of the provided ...
0
votes
0
answers
934
views
Python : name '__file__' is not defined
So as you can see, in my terminal, I was able to execute the file without error, but once I tried from the python shell, whether in the terminal or the one integrated in Emacs, there is an error, it ...
0
votes
0
answers
190
views
Unable to change emacs python indent
My Emacs's python-indent-offset is fixed at 2, even though I have the below code in my init.el to set it to 4. I used C-h v to describe the variable, it says its value is 2 and default is 4. I removed ...
0
votes
0
answers
28
views
virtualenv selection menu shows only the first few virtualenvs
I have a number of virtualenvs, currently 40, but when I try to select one via the drop-down menu in emacs, it shows only the first 30 or so. Is there a way to get a scrollbar attached to that menu, ...
0
votes
0
answers
458
views
How to use exuberant ctags with python?
I followed instructions here:
https://github.com/leoliu/ggtags
I've enabled the following:
(add-hook 'c-mode-common-hook
(lambda ()
(when (derived-mode-p 'c-mode 'c++-mode '...
2
votes
1
answer
393
views
How could I see the output of my Python code in the echo area?
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 ...
0
votes
0
answers
51
views
Why Jupyter console sometimes decide to output sometimes don't?
Problem
I don't know why my Jupyter console sometimes doesn't output anything. An example is this:
Notice that only the first line gets its output. I use C-enter to execute each line. Line 2, 3, 4, ...
2
votes
1
answer
2k
views
Problem with Flycheck and Python
I think that this is a newbie question, but here it goes:
I have installed Flycheck just as in the official page. Therefore, in my .emacs file I added the following lines (after installing):
(package-...
1
vote
1
answer
182
views
How could I disable all python shell interaction in emacs
How could I disable all python shell interaction in emacs on python-mode?
Such as:
C-c C-z open a python shell
C-c C-c run the content of the buffer in the opened python shell
C-c C-r ...
0
votes
1
answer
290
views
How to export an octave/matlab array for use by python in org-mode?
I am trying to pass the value of an octave/matlab array into a python code block in org-mode. But I can't get the python-end to receive the value.
With the answers in this question, I can generate an ...
1
vote
0
answers
125
views
How to run current buffer as python module from project root in Elpy mode?
Take for example I have the following project tree.
repo
|
+-root
|
+-__init__.py
+-__main__.py
+-packageA
|
+-__init__.py
+-__main__.py
My buffer is currently at root.packageA....
1
vote
1
answer
978
views
automatic prettier for python code? (as in javascript)
https://github.com/prettier/prettier-emacs does formatting for javascript
wonder if there's an equivalent for python code?
4
votes
2
answers
5k
views
Saving Python matplotlib figures with source-code blocks
So I am trying to create a Data Science workflow using org-mode source-blocks. Basically, I need to emulate the jupyter notebook functionality where you create a plot and it shows the figure.
Now, ...
3
votes
1
answer
165
views
Fira Code Ligatures: What is the flying trashcan icon replacing colons in Python buffers?
There is a strange icon appearing in place of colons (:) in my Python buffers. I cannot identify it easily using C-x = or any other command to inspect the character at the point because the icon ...
0
votes
1
answer
764
views
How to find usages of a variable/function etc in Python?
So going to the declaration is great. However I want frequently to go the other way. There used to be a way to do this with one of the older ada-modes, but I've not seen anything in the python support ...
2
votes
0
answers
598
views
Virtual environment management for python.el without changing the general PATH variable in Emacs
I try to use virtualenvwrapper.el with the build-in python.el and my virtual environments in a ./.venv directory inside each project.
Because all virtual envs have the same name .venv I cannot make a ...
0
votes
1
answer
1k
views
configuring spacemacs for python development
It's been really frustrating trying to get spacemacs to work so far. I've grown to really love it - coming from vim - for its capabilities in manipulating and navigating text, but it's just been so ...
1
vote
0
answers
89
views
auto intendation on newline doesn't stay at same indentation for python docstring
Ubuntu 19.10
emacs 26.3 from system repos
I do use elpy and evil-mode
In general when I am editing python code, indentation works just fine. However, when I am editing doc-strings, when I type enter ...
2
votes
2
answers
108
views
stop stripping result of :session for python print statement
Since default value for :result header is value print statement will only
show with :result output
#+BEGIN_SRC python :results output
print(' hello')
#+END_SRC
#+RESULTS:
: hello
but same ...
0
votes
1
answer
563
views
Working Around the OS X Catalina Conflict with Emacs 26.3
I'm struggling to workaround the problem discussed in this post. I'm working through the accepted solution (which also references this post, and getting what I think is close, but not quite there. The ...
1
vote
1
answer
2k
views
How to enable python-pylint for the all files by default?
I can enable python-pylint for a opened Python file doing:
M-x flycheck-select-checker and enter python-pylint
It think it says C-c ! s to enable it on all Python files.(the message hides itself so ...
1
vote
0
answers
261
views
How do I debug a flask application from within emacs?
I want to use something like pdbpp or ipdb to debug a flask application. I've tried but not understood how to set a breakpoint in a python file that's part of a wider application and see it hit. There ...
2
votes
1
answer
2k
views
"python3 -m venv" support in emacs
pyvenv and virtualenvwrapper emacs packages work well with virtualenv, but neither appears to support the core venv module which is now packaged with releases of Python.
Are there any actively ...
2
votes
0
answers
507
views
flycheck - elpy - flake8 - ein and .ipynb files
I have set up Emacs (on Mac Catalina) with Elpy to handle Python.
I also managed to get Jupyter notebooks (.ipynb files) working with Elpy via Ein.
Both .py and .ipynb compile and use Flycheck ...
3
votes
1
answer
664
views
Open buffer created by run-python in the current window
I recently started using spacemacs, and have a newbie question about modifying the way run-python works.
When I execute run-python, a new buffer is opened in a different window. I'd like to change it ...
1
vote
0
answers
364
views
Elpy: how to stop the underlying RPC process?
Whenever elpy-mode is activated upon visiting a python file, I see a py.exe executable start, with a subtree of processes. This should be the remote procedure call (thanks @al0 for the explanation). ...
1
vote
0
answers
258
views
Python debug mode in Emacs
I'm looking for a python debug debug mode in Emacs that allows me to start flask apps in debug mode and interact with them. Is there something that does this and and a step through on how to use it? I'...
5
votes
1
answer
910
views
Any equivalent of R+ESS for python?
I do a lot of R coding on Emacs – on Windows – using the wonderful ESS 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 ...
1
vote
1
answer
174
views
Emacs (ipython) inferior python shows strange input numbers
In emacs, I use ipython in the inferior python mode with config:
(setq python-shell-interpreter "ipython"
python-shell-interpreter-args "--simple-prompt -i")
When I edit my .py file, without any ...
0
votes
1
answer
81
views
Make buffer unreachable
This may be a silly question, but how can I make a buffer unreachable? I have enabled live-py-mode. Every time I try to edit my python file it evaluates the code, which is a well and good but it's a ...
1
vote
0
answers
45
views
org-babel python :session names matter
For example, I get
#+BEGIN_SRC python :session sdfjkl :results output
import numpy
#+END_SRC
#+RESULTS:
: Python 3.8.0 (default, Oct 23 2019, 18:51:26)
: [GCC 9.2.0] on linux
: Type "help", "...
2
votes
1
answer
131
views
Why needs syntax highlighting often a `revert-buffer`?
Quite frequently, syntax highlighting in a given buffer is broken (i.e., a big fraction of the code is not highlighted). This is definitely not due to syntax errors, and the point at which ...
1
vote
2
answers
2k
views
Emacs occasionally using wrong indent in python
I have a bunch of python files (ie .py files), which I use Emacs to edit. However I keep having the issue where sometimes emacs will indent regions with 8 spaces instead of 4, and I can't figure out ...
3
votes
1
answer
2k
views
"Backspace" key sometimes also deletes forward in python-mode
Start Edit 1
To answer questions.
Emacs Versions:
GNU Emacs 25.2.2 (x86_64-pc-linux-gnu, GTK+ Version 3.22.21) of 2017-09-22, modified by Debian
GNU Emacs 26.3 (build 1, x86_64-w64-mingw32) of 2019-...
-1
votes
1
answer
1k
views
Autocomplete suggestions after dot in python using company-mode
Jedi has support for auto-completion after dot
(setq jedi:complete-on-dot t)
=> Main goal is to Finding what methods a Python object has
[Q] Does company-mode has the same support (complete-on-dot)? ...
0
votes
1
answer
145
views
Elisp to get the language mode for the current ein cell?
When I'm using ein to run a python jupyter notebook, the major-mode variable is just "ein:notebook-multilang-mode" which makes it ambiguous what the current language is. I have elisp that only ...
1
vote
1
answer
170
views
How to disable hints for certain keywords in python elpy
I enabled elpy mode for python and I get hints when I type a keyword. Also I have yasnippets. Unfortunately, when I type "for" keyword, elpy gives me a useless hint, blocking <tab> key for ...
10
votes
1
answer
1k
views
How to highlight in different colors for variables inside `fstring` on python-mode
I am using python-mode which colors the parameters.
When I concatinate strings the variable color is represented as different:
On the other hand, if I use fstring, the variable is not represented as ...
3
votes
3
answers
1k
views
How to navigate to the next/previous python class?
I would like to navigate quickly between classes in Python code.
I'm looking for a command to go to the next / previous class so I
can bind that to a key sequence. This question is not about
...
1
vote
0
answers
313
views
How to read the python documentation offline in emacs?
Sometimes I use ctrl h i or M-x woman, though I almost always head to the web for basic queries like python find line in string. Do I need to download this[0], that[1] or something else before leaving ...
3
votes
1
answer
629
views
python interpreter within emacs fails on simple test on __main__ (syntax error)
This small program runs well in Terminal :
mac2011% cat bug.py
print(__name__ == "__main__")
#if True:
if __name__ == "__main__":
print("main")
else:
print("not main")
mac2011% python bug.py
...
0
votes
1
answer
630
views
how can I change the inferior Python process
I would like to be able to start Python 3 and ipython from Emacs in an inferior mode buffer. Currently start interpreter C-c C-p starts 2.7.
I know there must be a way to change to start another ...
0
votes
2
answers
2k
views
How to save and execute a python file?
I do not prefer python-mode. I would like a generic way so that I can understand emacs.
I wish the file be saved and python file command then be run as if in a shell.