Skip to main content
Share Your Experience: Take the 2024 Developer Survey

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
71 votes
5 answers
48k views

How do you create a robust Python IDE with Emacs (as the Text editor)

Emacs is an excellent editor - however it is said "to program you first need an IDE" - so how would you build an IDE in the extensively customizable Emacs for PYTHON with all the features of modern ...
Serial Exchangist's user avatar
40 votes
3 answers
28k views

How to set up elpy to use python3?

When setting up my emacs for a new work environment, I am unable to get the elpy configuration to correctly use python 3. I have installed all of the required packages in /usr/local/bin and have ...
adam's user avatar
  • 501
31 votes
10 answers
21k views

How do use Emacs to look up a function in Python?

What is the easiest way to configure Emacs to be able to look up where a function is defined? I want to highlight it in Emacs and press a key combo to look up where the source of the function is. Can ...
Low Kian Seong's user avatar
27 votes
2 answers
17k views

Using conda environments in emacs

What is the best way to use conda environmets using emacs as a Python IDE? I have got different conda environments while programming in Python: $ conda info -e # conda environments: # django ...
PabloRdrRbl's user avatar
26 votes
2 answers
6k views

Python org-mode source block output is always ': None'

This is my source block: #+BEGIN_SRC python print "hello" #+END_SRC The output is always: #+RESULTS: : None This is my org-babel configuration: (org-babel-do-load-languages 'org-babel-load-...
Empty_Mind's user avatar
  • 1,361
20 votes
2 answers
4k views

Can I include a common code block in two different code blocks in Org mode?

I have an org-mode file containing a table of data and two Python code blocks to extract different summaries from it. I would like to share some common constants and functions between these two code ...
user avatar
19 votes
4 answers
14k views

Your ‘python-shell-interpreter’ doesn’t seem to support readline

I've got this problem with my 25.1 and Python 3.5 on Ubuntu 16.10, but I don't see it being solved anywhere. Wondering what the latest status was. Reproducing: > emacs -Q --eval '(setq python-...
147pm's user avatar
  • 2,969
18 votes
2 answers
1k views

Make fill-paragraph in python docstring leave the triple-quotes on separate line

I type a python docstring all on one line like this: """ This is a long docstring. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec a diam lectus. Sed sit amet ipsum mauris. Maecenas ...
bstpierre's user avatar
  • 290
18 votes
2 answers
5k views

Display errors and warnings in an org-mode code block

I would like to be able to report warnings and errors when evaluating a Python code block in an Org file. When a code block has Python syntax errors, Org helpfully pops them up in a separate ...
user avatar
14 votes
1 answer
5k views

org-mode: how can i point to python3.5 in my org-mode doc?

On: Aquamacs 3.3 GNU Emacs 25.1.1 (x86_64-apple-darwin14.1.0, NS appkit-1344.72 Version 10.10.2 (Build 14C109)) of 2016-09-19 in mac osx sierra I changed my ~/Library/Preferences/Aquamacs Emacs/...
Cy Bu's user avatar
  • 501
13 votes
3 answers
2k views

How to transpose two arguments of a function in Python?

How I can I swap two arguments in a call to a Python function? If I put point on the space between these two arguments: self.assertEqual(json.loads(some.data), json_data) and then M-t (transpose-...
Croad Langshan's user avatar
12 votes
3 answers
5k views

Is there a way to use python instead of elisp for extending emacs?

I'm interested in using languages other than elisp to write emacs extensions, is this possible at all? If python is not supported, what languages are?
nukeop's user avatar
  • 133
12 votes
3 answers
4k views

Two Python modes

I have been trying to configure Emacs to use the proper Python mode. To this end I have read a few tutorials. Most importantly this one. The tutorial uses the python-mode package. However, when I ...
Christophe De Troyer's user avatar
12 votes
4 answers
10k views

Library for automatically inserting python docstring in Google style

I'm looking for an elisp package that automatically inserts Python docstring for a method. I found a package, which is very close to my purpose. But it's in reStructured text, not in Google style. ...
sy2's user avatar
  • 123
11 votes
1 answer
4k views

python auto indent problem

I'm using Emacs 24.4. When writing Python code, Emacs behaves strangely with respect to indentation. For example: for i in range(10): print(i) for i in range(10) When I input :, Emacs adds a ...
Hunger's user avatar
  • 213
11 votes
3 answers
3k views

Emacs EIN vs IPython shell

I'm trying to make EIN work within Emacs, but right now (with IPython 2) it seems that it's not possible. This errors arise: REQUEST [error] Error from parser ein:json-read: (json-readtable-error) ...
El Diego Efe's user avatar
  • 1,631
11 votes
3 answers
4k views

Running ipython remotely

I am trying to run an ipython interpreter remotely (with Emacs 24.5 and native python.el), but I'm not sure I have the right approach: whenever I try to run such a command for instance (which gets ...
cjauvin's user avatar
  • 594
11 votes
1 answer
4k views

Exporting highlighted source code to pdf in Org-Mode

I'm trying to export some python code with syntax highlighted to a pdf, from org-mode. Even though I can export to html without any issues I could not find a way to export it to pdf. n.b. I'm using ...
user13328's user avatar
  • 111
11 votes
1 answer
817 views

How to control emacs externally?

I'm developing an app in python which sends commands to a running emacs instance. Currently, I start an emacs server and send the commands through the command line, like this: subprocess.call(['...
Jesse's user avatar
  • 1,994
10 votes
1 answer
1k views

Which class or method or function am I in?

When navigating a source file with incremental search, I often find myself jumping into some context that is taller than the window. This raises the question: "Which class am I in?". Or, if the ...
davidrmcharles's user avatar
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 ...
alper's user avatar
  • 1,390
10 votes
3 answers
10k views

Specifying python version in run-python

I'm trying to figure out how to specify which version of python to run when calling "run-python" (C-c C-p) in python-mode, and I've run into the following problem. These are the first few lines of the ...
user avatar
10 votes
3 answers
2k views

How can I make python-mode correctly indent python's match statement?

Python 3.10 added a match statement. When I try and type one in emacs 27.2, it does not indent it correctly, presumably because it does not yet have support for it. How do I get python-mode to ...
Rob Gilton's user avatar
10 votes
3 answers
2k views

How to syntax highlight Python f-strings so {...} uses regular code colors?

Update, Emacs 28 supports f-stings Python 3.6 supports F strings, eg: So: print(f'Test {} me!'.format(2 + 2)) Can be written as: print(f'Test {2 + 2} me!') Which print's Test 4 me, Is there a way ...
ideasman42's user avatar
  • 8,826
10 votes
1 answer
646 views

How can I make fill-paragraph regard the formatting rules of Python docstrings?

If I press M-q in a docstring like this, then the line breaks in the docstring get messed up: def foo(word): """ This is a function that does something. @param word: str, input. @returns: ...
Lenar Hoyt's user avatar
  • 1,173
9 votes
3 answers
34k views

How to force a Python shell to re-import modules when running a buffer?

I'm using C-c C-c to send a buffer to a Python shell. The buffer has an import at the beginning. I found that if I modify the module I'm importing, it doesn't reflect the changes if I run the buffer ...
El Diego Efe's user avatar
  • 1,631
9 votes
2 answers
12k views

How do I get Emacs to recognize my python 3 virtual environment

My system is macOS and I have both python 2 and 3 installed. I am currently working on a side project for which I want to use Django 1.8 and python 3.4. I have created a virtual environment with the ...
Napoleon's user avatar
  • 237
9 votes
1 answer
4k views

How to automatically run inferior process when loading major mode for the first time?

Let's say we are working with Python (or Matlab) with company. Without an inferior process company messages that Completion needs an inferior Python process running However, the obvious solution to ...
Pushpendre's user avatar
9 votes
1 answer
1k views

How do I disable python-help

I just upgraded to Emacs 26.1 on Linux (Ubuntu 18.04, but emacs26 from the kelleyk repo). python-mode is now bringing up a *Python-Help* window whenever the cursor in on a symbol or keyword. I'm ...
Dan Christian's user avatar
8 votes
5 answers
5k views

Get pandas data-frame as a table in org-babel

In the following example, I create a very simple pandas DataFrame and export results verbatim: #+BEGIN_SRC python :exports both :results verbatim :return test import pandas as pd test = pd.DataFrame({...
Daniel's user avatar
  • 3,653
8 votes
2 answers
2k views

Using virtualenvwrapper in Eshell

I noticed that I can't use virtualenvwrapper commands (like workon) in an eshell but they do work within a shell environment. Is there a virtualenvwrapper-like mode for Emacs?
calizarr's user avatar
8 votes
1 answer
3k views

Is there indentation in org src blocks?

I'm going kinda crazy trying to understand what's going on here... Asked this question on the r/emacs subreddit so apologies if any of you are seeing this again. Do org blocks allow TAB indentation ...
nonreligious's user avatar
8 votes
0 answers
1k views

show output from python-shell-send-region

Using python.el and ipython.exe (from Miniconda3), I'd like to highlight a portion of code and execute it in the associated inferior python buffer. Example: #!/usr/bin/python3 myvar = 100+200 ...
r2evans's user avatar
  • 275
7 votes
4 answers
5k views

Function to restart python console

I wrote a very simple function to properly restart ipython console with elpy when evaluating the buffer or region: (defun my-restart-python-console () "Restart python console before evaluate buffer ...
atevm's user avatar
  • 948
7 votes
1 answer
849 views

Multiple major modes in one buffer (e.g., python-mode & LaTeX-mode)

Using the LaTeX-package pythontex I one can insert python code into the latex document which is executed (and printed to your latex file if you want) if you run latex. I use auctex for editing latex ...
student's user avatar
  • 1,109
7 votes
3 answers
1k views

prettify-symbols-mode character replacement regex

I'm using the new emacs 24.4 prettify-symbols-mode, but it isn't behaving consistently. I turn it on with: (prettify-symbols-mode t) (global-prettify-symbols-mode t) And I'm trying to change the ...
mankoff's user avatar
  • 4,226
7 votes
1 answer
5k views

Python in org babel will not work

I've recently moved to a new computer and cannot get org babel to work with Python (it worked fine on my old machine). I'm using OS X 10.12.6 with Emacs for Mac OS X based on Emacs 25.3 with org-mode-...
Adrian Burd's user avatar
7 votes
1 answer
171 views

Library that converts a Python output string to an Elisp data structure?

Say that I evaluate the following Python code: import inspect import scipy.ndimage.filters list (inspect.getargspec (scipy.ndimage.filters.gaussian_filter1d)) # => [['input', 'sigma', 'axis', '...
abo-abo's user avatar
  • 14.1k
7 votes
1 answer
5k views

eldoc in python-mode

I'm trying to get eldoc-mode to work in python-mode. If I enter a python buffer and do M-x eldoc-mode M-x python-mode-switch-to-shell This seems to work for some built-in functions, but mostly ...
Nathaniel Flath's user avatar
7 votes
3 answers
853 views

org-src-mode send commands to repl in named python :session, not *Python*

Is there a method to set what buffer python-mode looks to for a running python process? I have a babel block in org-mode like #+BEGIN_SRC python :session session1 import os os.uname() #+END_SRC I ...
Will's user avatar
  • 203
7 votes
1 answer
3k views

Trouble adjusting tab-width

When I write Python code, I personally prefer indenting with 4 spaces instead of a tab. However, in my day job I work with a codebase that uses only tabs. When I open one of these files in emacs, ...
elethan's user avatar
  • 4,825
7 votes
1 answer
2k views

How to allow org-babel to play with python virtual environment?

I have virtual environment set on my system (actually virtualenvwrapper). I would like to direct org babel to use a specific environment in a single code block or on the whole buffer. How can I do it?
Dror Atariah's user avatar
7 votes
1 answer
1k views

How can I prevent python-mode from occasionally highlighting everything as string

I use python-mode for my Python code, and every once in a while the syntax highlighter gets confused and thinks everything in the buffer is a string literal. This typically seems to happen when I ...
abingham's user avatar
  • 927
7 votes
2 answers
612 views

How to make private python methods the last company-mode choices?

I'm using emacs with company-mode and I'd like the 'private' methods (method that start with underline) to be shown last, since they are kind of useless for imported libraries in python. See the image:...
Jesse's user avatar
  • 1,994
7 votes
1 answer
2k views

src python in org-mode: IndentationError: unexpected indent

mac 10.13.4 / emacs 25.3 (9.0) / org-version 9.1.12 / python 3.5.2 I am trying to understand why C-c C-c generate an IndentationError: unexpected indent when executing a simple code like the example ...
Cy Bu's user avatar
  • 501
7 votes
2 answers
1k views

hs-minor-mode with python.el - hide if statements, for/while loops, etc

Currently, I use the hs-minor-mode to collapse my python code and make it easier to work with - however, by default this only folds def my_function(): blocks. Is it possible to get it to work with if, ...
dieggsy's user avatar
  • 475
7 votes
2 answers
220 views

Syntax highlighting fails on clone-indirect-buffer-other-window

I normally use indirect buffers while I edit python code in python-mode, I create them by running clone-indirect-buffer-other-window. While the syntax highlighting of the main buffer looks just fine, ...
jmlorenzi's user avatar
  • 293
7 votes
0 answers
492 views

xref unsuccessful in python buffers: "no definition found"

The command xref-find-definitions is no longer working for me in Python buffers (with elpy-mode enabled. Its companions, such as xref-find-references, are also not working in Python buffers. ...
bashfuloctopus's user avatar
6 votes
3 answers
811 views

How to narrow to python class?

How can I narrow a buffer to the python class at point? narrow-to-region works but requires first selecting the class as a region, and it seems python-mode has moved on since this was written: http:/...
Croad Langshan's user avatar
6 votes
2 answers
251 views

Python cycling through indentation

Cycling through indentation levels in python.el 1 can be achieved by pressing <tab> repeatedly, which is bound to indent-for-tab-command. Now, consider: (defun malb/my-indent (&optional ...
Martin R. Albrecht's user avatar

1
2 3 4 5
13