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.
621
questions
0
votes
1
answer
48
views
Setting correct flycheck checker with Python's poetry in Doom Emacs
I have a Python project managed with Poetry. Poetry creates virtual environments in ~/.cache/pypoetry/virtualenvs/ where all the dependencies are installed, including pylint. This means that if I want ...
0
votes
0
answers
23
views
How to auto indent?
Say I'm in foo.py and I want to paste something into the docstr of function f:
something:
foo
bar
def f():
"""
"""
My current workflow (evil normal mode, ...
0
votes
0
answers
31
views
Yasnippet returns Wrong type argument: listp
After inserting the snippet I'm able to type the function name.
But after tabbing to args, I get the error Wrong type argument: listp on typing
Is it python-args-to-docstring failing at it's job?
I've ...
1
vote
1
answer
43
views
Python Org Babel producing garbled result
I have the following settings on for org-babel
#+PROPERTY: header-args:python :python ~/env/pt/bin/python :session a :results drawer output replace
When I evaluate a code block, the results are some ...
1
vote
1
answer
34
views
Emacs: elpy-shell-send-region-or-buffer is not using Python virtualenv
I am using GNU Emacs 29.3 on Windows 11 and have configured Elpy manually. I am a beginner in Elpy. It seems to be working as expected. I can see the auto-completion and documentation hints.
However, ...
0
votes
0
answers
65
views
How to jump to definitions in different modules using `eglot`
I am using eglot (have tried both pyright and pylsp).
Jumping to definition at point works, but when I select a variable imported from a different package, or the package itself, nothing happens.
For ...
0
votes
0
answers
20
views
How to jump to a failed test while testing python?
I know this is a pretty broad question and maybe even non-emacs related.
However I don't know where to start but develop python using dap-mode
Usually I have two buffers: sometest.py and a terminal ...
0
votes
0
answers
28
views
every time I run python code I get message sent: and the first line
hello I am trying to run python application on Emacs as an IDE I installed pyel and pyright from pip and package installer but now some time the result is showing and sometime it is not trying to push ...
0
votes
1
answer
131
views
How to evaluate python code in org-mode when only python3 is provided by the package manager?
Recently I started to use guix as my operating system.
I installed python3 for my user via guix install python3.
python itself is not available in the package repository, which I verified by running ...
0
votes
1
answer
22
views
use output of python code block from other python code block
My emacs is 29.2 in linux. I try below code to use output from first python block, but the output in second block is None after press C- C-c.
#+name: testblock
#+begin_src python
print("hello&...
0
votes
0
answers
35
views
Python-mode code navigation
How can I navigate from an abstract class/method to the implementations of that class/method? Using the M-. I can jump to function definition but I can't find a way to easily find the implementation.
0
votes
0
answers
29
views
Org Mode Code Sessions Scope
I'm trying to use sessions within an org file to keep the code workspace as I need something similar in style to the Jupyter Notebooks. The issue I'm having is this isn't restricting the session to ...
0
votes
0
answers
67
views
Emacs Python Virtualenv Support
I am able to enable a virtual environment by adding these lines in .dir-locals.el in my project directory:
((python-mode . ((python-shell-virtualenv-root . "s:/.virtualenvs/default/"))))
...
0
votes
1
answer
192
views
Install elpy on emacs
I checked the elpy site but came across an error where the package cannot be found? I am new to emacs and need a little help reading the error message.
The specific code in the init file I tried to ...
0
votes
1
answer
40
views
fill-region fails as fill-forward-paragraph complains about argument type
I am trying to fill a region within a Python docstring. The function find-docstring-limits returns the limits of the docstring. Here is the function:
(defun indent-docstring-paragraph ()
"...
0
votes
1
answer
52
views
Defining custom Python skeletons
I'm trying to define a custom Python skeleton and have found there are two macros in python.el that might be of use here.
After poking around and looking at the value for python-skeleton-autoinsert it ...
0
votes
0
answers
56
views
Python parenthesis folding in doom emacs
I run into situations a lot where I have code that looks like
new_stuff = (
blah.blah ( stuff,
stuff,
stuff,
stuff,
).blah_two( [morestuff,
stuffstuffstuff,
stuffffff ] )
...
0
votes
0
answers
35
views
Python Code executes, but result screen shows a long line of characters
So my professor is obsessed with emacs and has encouraged us to set it up on our personal devices. Under his guidance I downloaded it, and he gave us some homework in a .org file. Inside this file, we ...
0
votes
1
answer
55
views
Org Babel: Possible to get Python shell with session?
When I make an Org Babel shell code block with for instance a :session a header argument, it automatically makes a buffer a with the shell for this session, so I can explore it interactively.
This is ...
0
votes
0
answers
18
views
Org Babel: Open Python shell on session?
When I run an Org Babel shell code block with e.g. :session a header argument, it automatically opens a buffer a with the shell for this session, so I can explore it interactively.
I love this feature!...
0
votes
0
answers
16
views
The same code prints two different results from python
I wrote a sample code to print the same dataframe two times, but the first and second time print two different results:
#+begin_src python :results output drawer
import pandas as pd
data1 = [['1','B',...
0
votes
1
answer
26
views
In Python buffer erase large output
Python buffers support comint-delete-output, but if I forget to do it before entering another command, I have a big hunk of text I can't easily erase.
In shell mode, I can set the mark and run comint-...
0
votes
0
answers
47
views
fill-paragraph for Google style docstrings
When editing an existing docstring in Google style you need to call a function like fill-paragraph to cut the long lines while preserving the proper indentation. However fill-paragraph will not work ...
0
votes
1
answer
76
views
No output in Python inferior buffer after C-c C-c
OS: Windows 11 (64 bit)
Python version: 3.12.0 (64 bit)
Emacs version: 29.1
I use LSP mode in Emacs for Python programming and I have in my Emacs init.el file the following:
(custom-set-variables
...
0
votes
1
answer
269
views
How to use eglot to set analyze path for python project?
I'm trying to use eglot on gem5, but I've noticed that I need to specify the analysis directory as src/python, and I understand that it seems to be possible to set this by setting eglot-workspace-...
0
votes
0
answers
56
views
How to reliably use run-python with venv in buffer-env?
I have a python project using venv under PROJECT_FOLDER/.venv. I wrote an .envrc file there to activate the environment. buffer-env-describe seems to know about it. However, when I am in a python ...
0
votes
1
answer
75
views
Why does adding a return value to my Python code stop it from printing?
Load up Emacs in the default modes, i.e. emacs -Q. After this, make a new .Org file with the following contents and run the Emacs Lisp code.
(setq org-babel-python-command "python3")
(setq ...
0
votes
0
answers
118
views
how to turn off python formatting in emacs
I have a python program that I edit in emacs. However, sometimes when I save it, it gets re-indented, and in doing so, messes up the indentation of sections, where I have some code and then some ...
3
votes
1
answer
139
views
org-babel python code block - not showing errors during execution
I have a python code block in an org-file that when executed results in some error. I was expecting to see that error in the #+RESULTS: block, but it doesn't show up. I have to navigate to the python ...
0
votes
0
answers
20
views
Weird behaviour on emacs with running django server in terminal
something weird is going on in my 'emacs-IDE'. I am editing some javascript files in a django project using spacemacs. Some tools I use are treemacs and lsp-mode.
In order to test my code I call up a ...
0
votes
1
answer
33
views
set the correct major mode for script files based on interpreter
I want to make a function that will set the correct major mode based on the interpreter used for a script.
I don't want to include extensions in my scripts (because that can be annoying if making cli ...
0
votes
2
answers
76
views
add a new line with the same indentation level as the current line
when python code block gets larger, it's hard to find the right indentation level
def foo():
for a in l: # l1
# l1-1
for b in k: # l2
print(a)
# (2)
print(b)
...
2
votes
0
answers
212
views
How do i I use a virtualenv with pylint in flycheck?
I use pylint in flycheck via the python-flycheck plugin. By default it uses emacs's virtualenv which lives here: ~/.emacs.d/.python-environments/default on my machine. I would prefer if it used the ...
0
votes
0
answers
52
views
Bad closing bracket indentation for electric-pair in python
I am getting the wrong indentation for closing braces when I use electric-pair mode in python.
For example, if I place the cursor (|) like so :
for i in range(10):
foo = [|]
and hit return, then ...
0
votes
1
answer
112
views
Configure lsp-mode to start the python server when in snakemake major mode
I would like to know if it's possible to configure LSP mode to start the Python server when I work on a snakemake file (snakemake-mode), as I use heavily use Python in this mode also.
0
votes
0
answers
40
views
company-mode with python inserts weird characters
Company mode suggests the right completions, but when I press RET I get weird characters, probably denoting the position, I was expecting to be able to cycle between each of these spots with tab or at ...
0
votes
1
answer
23
views
change the tag of the exported code
I want to change the exported tag of
#+begin_src python
..
#+end_src
exports to
\begin{verbatim}
...
\end{verbatim}
I want it to be export to
\begin{python}
\end{python}
Anyone has any idea ?...
0
votes
0
answers
44
views
auto-mode-alist for python files
Am doing the following for org files.
(add-to-list 'auto-mode-alist '("\\.org\\'" . org-mode))
What should I do for python ?
0
votes
1
answer
127
views
Using emacs for learning python with numpy
I would like to use emacs for learning python with numpy. How can I proceed ? Have seen other using Jupyter but would prefer using emacs instead.
Would it be possible to have a simple example using ...
0
votes
1
answer
49
views
OSC 8 links not working in the Comint mode
According to the NEWS for Emacs 28.1 (Ctrl-f "OSC 8, for hyperlinks"), the comint-mode supports the OSC 8 styled links. But when I compile (interpret) a file "test.py" with ...
3
votes
1
answer
291
views
python-shell-completion-complete-or-indent (Tab, in an inferior python mode shell) completes "__PYTHON_EL_eval_file"
On Emacs 29, Python 3.11.3, IPython 8.13.2
A strange behavior seems to have recently started. When opening a python shell with run-python and then python-shell-send-buffer or python-shell-send-file ...
1
vote
0
answers
230
views
Eglot/pyright on Windows is sending malformed paths to the server
I'm getting all kinds of strange behavior trying to run Eglot with Pyright on Windows with Emacs 29.0.60 ((build 1, x86_64-w64-mingw32) of 2023-03-10). The *Messages* buffer shows lots of attempts to ...
1
vote
1
answer
174
views
Why doesn't the ##* outline work with Python?
I have the following configuration for outlines in my init.el file:
(defvar my-outline-regexp-alist
'((emacs-lisp-mode . "\\s-*;;\\*+")
(js2-mode . "\\s-*//\\*+")
(...
1
vote
1
answer
124
views
Emacs 28 crashing when using triple quotes for docstrings
In Emacs 28, in python-mode, unbelievably, triple quotes causes emacs CPU utilization to hit 100% and freeze / crash. Apparently a known error related to jit-lock-mode.
I'm asking the question here, ...
0
votes
0
answers
30
views
`run-python` cannot hide *Python* buffer
When running
(defun my/run-python ()
(interactive)
(let ((buf (current-buffer)))
(with-current-buffer buf
(save-mark-and-excursion
(run-python (python-shell-calculate-...
0
votes
0
answers
33
views
Inferior Python mode seems to redirect some output back as input. How to fix?
I'm running a Python3 REPL in Inferior Python Mode.
When user input follows directly after some output, the next output seems to be redirected to the REPL, interpreted as user input, and evaluated. ...
0
votes
1
answer
55
views
do nothing more than syntax highlighting when spacemacs open python file(or any other source files)
I use spacemacs. Currently, when I open a python file, emacs will do a lot of things, it will check the syntax and give tips. This is what describe-mode gives:
Auto-Compression Auto-Encryption Bug-...
3
votes
6
answers
429
views
__PYTHON_EL_eval_file prints in interpreter when sending python file from buffer using C-x C-l
Whenever I send the a Python buffer to the interpreter via C-x C-l it prints the file eval call as shown below. While it does print the correct output, it's a bit annoying to see it every time and I'd ...
2
votes
2
answers
148
views
Python-mode Multi-line Conditional Indentation
Given the following somewhat silly Python code with a multi-line condition:
if ("VALUE" in my_uncessarily_long_dictionary and
some_other_long_condition_case):
do_something()
else:
...
2
votes
2
answers
364
views
IPython doesn't echo code input
Typically when I send code from a Python script using C-c C-e to IPython, IPython does not echo the code that I input. For example, sending a script with just the following in test.py
2 + 2
and ...