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.

Filter by
Sorted by
Tagged with
0 votes
0 answers
5 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 ...
mor3dr3ad's user avatar
0 votes
1 answer
22 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 ...
Hackerman's user avatar
0 votes
1 answer
33 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) ...
eugene's user avatar
  • 489
0 votes
0 answers
32 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 ...
Att Righ's user avatar
  • 725
0 votes
0 answers
13 views

python, open parenthesis at beginning of line inserts a space

Python code snippet (imin_f, jmin_f), (imax_f, jmax_f) = island_f non_overlap =set() n of non_overlab is behind ( , I can't tell which mode is doing it.. c-h k ( gives. ( runs the command ...
eugene's user avatar
  • 489
0 votes
0 answers
20 views

Prevent deletion of blank lines when tangling code blocks

The Python style guide asks for two blank lines surrounding class and function definitions (see PEP 8). When those blank lines are added in Org-Mode source blocks, they are removed during tangling. ...
Ben Bkhdt's user avatar
0 votes
0 answers
29 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 ...
SLesslyTall's user avatar
0 votes
0 answers
18 views

Polymode in org-edit-special

I use (add-hook 'python-mode-hook 'poly-python-sql-mode) where poly-python-sql-mode is a special polymode that correctly highlights SQL queries that are used within strings in a Python file. When this ...
guibor's user avatar
  • 111
0 votes
1 answer
35 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.
R-addict's user avatar
0 votes
0 answers
35 views

python source code with using realgud:gdb and pdb

Following invokes pdb in shell. I have to type list to look at the python source. Instead is there a way to open the python source file, just like how the c++ source file is opened when a gdb ...
user40923's user avatar
0 votes
0 answers
26 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 ...
geckos's user avatar
  • 141
0 votes
1 answer
14 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 ?...
barak diker's user avatar
0 votes
0 answers
32 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 ?
Dilna's user avatar
  • 1,183
0 votes
0 answers
26 views

Display Pillow image object in Babel Org Mode directly without saving into a file?

I wonder if there is any way for Babel in Org Mode to display images (from libraries like Pillow or matplotlib) "directly" without saving them into a file: #+begin_src python from PIL import ...
Daniel Krajnik's user avatar
0 votes
1 answer
45 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 ...
Dilna's user avatar
  • 1,183
0 votes
0 answers
77 views

How can I get Emacs in Windows to interactively communicate with Python matplotlib?

I am using Anaconda Python on Windows 11 and WSL2. In VS Code (Windows) and Emacs/Eglot (WSL2), the following code runs fine when I run it interactively: import matplotlib import matplotlib.pyplot as ...
hatmatrix's user avatar
  • 1,046
0 votes
1 answer
17 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 ...
scribe's user avatar
  • 950
2 votes
0 answers
83 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 ...
Metropolis's user avatar
1 vote
0 answers
99 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 ...
Rodney Price's user avatar
0 votes
0 answers
46 views

elpy can't find new python version (upgraded from 3.9 to 3.11)

I've upgraded from python 3.9 to 3.11 on my windows machine (on that I don't have admin rights). I used emacs (elpy) before to manage my python projects. Unfortunately, after the upgrade it seems elpy ...
swissy's user avatar
  • 77
0 votes
1 answer
80 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-*//\\*+") (...
raylight's user avatar
  • 217
1 vote
1 answer
70 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, ...
Marc Cenedella's user avatar
0 votes
0 answers
26 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-...
phoxd's user avatar
  • 231
0 votes
0 answers
23 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. ...
henning's user avatar
  • 82
0 votes
1 answer
30 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-...
Tokubara's user avatar
  • 177
3 votes
5 answers
154 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 ...
Ricardo's user avatar
  • 131
0 votes
0 answers
11 views

org-mode errors when trying to export a python code block to html

Org mode errors out when trying to export a python code block to html. This error seems to be specific to python, as json and bash src blocks work. Furthermore, I can export to latex, markdown and ...
Ashton Honnecke's user avatar
2 votes
2 answers
68 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: ...
Xaldew's user avatar
  • 1,181
0 votes
0 answers
15 views

How to python-execute-file a django custom command

How can I C-c C-c or python-execute-file a django custom command? Currently I get this error (using the emacs settings at the bottom): -*- mode: compilation; default-directory: "~/src/django/&...
jjk's user avatar
  • 749
1 vote
2 answers
187 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 ...
cdd's user avatar
  • 195
0 votes
1 answer
26 views

How to move out of a python string with C-M-u

I'm used to using backward-up-list to go to the front of a string in most every programming mode, but for some reason it doesn't work in python-mode. python-mode rebinds C-M-u to its own python-nav-...
Cristian's user avatar
  • 233
0 votes
0 answers
46 views

Polymode support for Reticulate-library for mixing R and Python

Polymode work well with Rmarkdown using ESS in R analyses. There is a R package reticulate that allows running python within R either interactively with reticulate::repl_python() or by line or file ...
jpf's user avatar
  • 11
0 votes
0 answers
25 views

List all occurrences of a keyword with click

I would like to click on a keyword (def, class, variable, ...) with shift pressed and have the occurrences/origins listed. When clicked I would like to jump to that occurrence. I used to have it done ...
Qohelet's user avatar
  • 185
0 votes
0 answers
43 views

Org mode session inferior process

In Python org mode source blocks, the company code completion works only if there is inferior buffer called *Python*. When I use file-wide session inferior buffer with a different name the ...
Arktik's user avatar
  • 932
1 vote
1 answer
52 views

Presenting Python function arguments in minibuffer for selection

I have written a Python function that takes a string input and performs a semantic search in my org-roam-directory and outputs the results in the following format after 2 seconds of computation: [{'...
user39819's user avatar
0 votes
1 answer
116 views

elpy/pyvenv: "JSON readtable error: 80"

Trying to use elpy, I cannot get to run neither elpy-config nor pyvenv-workon commands that I get this error message in the minibuffer. Steps: open a python file M-x pyvenv-workon RET dev RET where ...
erpreciso's user avatar
0 votes
1 answer
53 views

How can I add custom keywords into Builtin Exceptions in python-mode to color them?

In python-mode, Exception keyword has font-lock-type-face for coloring. Example output of the coloring: If possible, I want to add custom keywords into Builtin Exceptions such as QuietExit, Terminate ...
alper's user avatar
  • 1,238
1 vote
1 answer
290 views

How to autocomplete dynamically created objects in python code?

Is anybody able to get suggestions after typing x. using code below? E.g. name import json from types import SimpleNamespace data = '{"name": "John Smith", "hometown": {&...
jjk's user avatar
  • 749
0 votes
0 answers
39 views

How can I suppress signatures for specific functions in lsp-mode?

In lsp-mode lsp-signature-activate (12. Signature help) is activated by default. Sometimes some signatures are so long where they took large space. Is it possible to black-list some specific function ...
alper's user avatar
  • 1,238
0 votes
1 answer
75 views

ipython shell syntax error with "?" in string in `python-shell-send-string`

When in the IPython shell, ?open returns help on the "open" function. But when I send it with python-shell-send-string it throws a syntax error saying "?" is not recognised. I can ...
Arktik's user avatar
  • 932
0 votes
1 answer
32 views

How to have an elpy breakpoint in a different file

When running tests or scripts using elpy, I would like to set a breakpoint in a different file than the file that is the start of execution. However, from documentation, I see I can only set a ...
Paul Weibert's user avatar
0 votes
0 answers
10 views

+eval/buffer doesn't run current buffer

when I run +eval/buffer, I get the following output Traceback (most recent call last): File "qr_9TTN6Y.py", line 1, in <module> import numpy ImportError: No module named numpy 2 ...
A-nak Wannapaschaiyong's user avatar
0 votes
0 answers
41 views

Python matplotlib interactive mode on emacs python shell interpreter(ipython3)

I want to run matplotlib in interactive mode on Emacs python-shell-interpreter(ipython). However, when I run matplotlib in the interactive mode (e.g. by running plt.figure()), it freezes after showing ...
R. Yanagihara's user avatar
1 vote
2 answers
147 views

Send to python-shell-interpreter from the project root

How can I tell the shell to always open relative to my project root? I have the following python project structure: mypyjunk ├── mypyjunk │   ├── common.py │   ├── __init__.py │   └── jitter.py ├── ...
Mittenchops's user avatar
3 votes
2 answers
106 views

Python on Emacs taking space on disk

I'm kind of a newbie and want to use Python on Emacs. I noticed that there is a folder rpc-venv here: /Users/user/.emacs/elpy/rpc-venv/lib/python3.7/site-packages Where all python packages are ...
Adelita's user avatar
  • 155
0 votes
1 answer
90 views

Disable blacken-mode on certain projects

I have blacken-mode enabled on all python buffers like this: (add-hook 'python-mode-hook (lambda () (blacken-mode 1) ;; other config )) But on some ...
suvayu's user avatar
  • 1,568
0 votes
0 answers
61 views

Trying to understand how to use python-mode's virtualenv support

I am trying to figure out how to actually use the Python major mode's Shell virtualenv support. I might be a little slow, this doesn't make much sense to me. It seems there are two options. You can ...
mislyde_alfabetisk's user avatar
0 votes
1 answer
870 views

python language server with eglot - can't get it working

emacs version: 28.2 eglot version: 20221020.1010 After successfully using eglot with eglot-jl for some time when programming in julia, I now have to use python for a few small tasks, and I was looking ...
Tom's user avatar
  • 1
0 votes
0 answers
311 views

org babel not working for python

I am a new emacs user. My laptop is macOS Monterey Version12.6, and my Emacs is 28.2, org version 9.5.5. I installed my python through homebrew and it's located in /opt/homebrew/bin/python3. At first ...
JoZ's user avatar
  • 131
1 vote
2 answers
217 views

Evaluate Single Python Code Blocks in a Quarto File like in R Studio or Jupyter Lab

Quarto is a literate programming framework. It allows you to combine in a single file code (in various programming languages) and text (in markdown).* When a Quarto document is rendered, the output ...
henning's user avatar
  • 82

1
2 3 4 5
13