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
70
votes
5answers
45k 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 ...
31
votes
3answers
24k 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 ...
26
votes
10answers
17k 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 ...
25
votes
2answers
12k 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 ...
22
votes
2answers
4k 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-...
17
votes
2answers
3k 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 ...
16
votes
2answers
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 ...
16
votes
1answer
3k 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 ...
14
votes
3answers
11k 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-...
13
votes
3answers
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-...
12
votes
1answer
4k 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/...
11
votes
3answers
3k 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 ...
11
votes
1answer
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 ...
11
votes
4answers
8k 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. ...
10
votes
3answers
4k 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?
10
votes
3answers
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) ...
10
votes
1answer
907 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 ...
10
votes
3answers
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 ...
10
votes
3answers
912 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 ...
9
votes
3answers
32k 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 ...
9
votes
1answer
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 ...
9
votes
1answer
933 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 ...
9
votes
1answer
3k 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 ...
9
votes
1answer
495 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(['...
9
votes
1answer
409 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: ...
8
votes
3answers
8k 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 ...
8
votes
2answers
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?
8
votes
1answer
806 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 ...
7
votes
5answers
3k 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({...
7
votes
1answer
681 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 ...
7
votes
3answers
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 ...
7
votes
1answer
133 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', '...
7
votes
1answer
1k 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?
7
votes
1answer
764 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 ...
7
votes
2answers
489 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:...
7
votes
0answers
937 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 ...
7
votes
2answers
184 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, ...
6
votes
2answers
189 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 ...
6
votes
2answers
2k views

how to remove the red underline

Occasionally I have this ugly red underline in my python code. It seems not related to any flymake error/warnings. Does anyone know why it shows and how it can be removed? Thanks! I am using latest ...
6
votes
4answers
4k 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 ...
6
votes
1answer
4k 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 ...
6
votes
2answers
579 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 ...
6
votes
5answers
3k views

How to start python shell in appropriate working directory?

If I am editing a python file, and start a python shell using elpy-shell-switch-to-shell the process appears to set the working directory as the containing directory of the file. However, the file ...
6
votes
1answer
1k views

Ipython completion in elpy

My elpy uses ipython as the interactive interpreter. It does not, however, emulate ipython's history-informed autocomplete feature (for lack of a better term). That is: within an ipython session ...
6
votes
1answer
4k views

Running two IPython instances at the same time

I'd like to run two instances of IPython in Emacs at the same time, one with Python 2, and the other Python 3: is it something doable or there's something in the way python.el is designed that would ...
6
votes
2answers
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 ...
6
votes
1answer
1k views

Emacs 24's python.el + ipython cannot complete module names

I'm using Emacs 24.4.1 on OSX (installed with Homebrew), with the built in python.el, and Python 3 (also installed with Homebrew), along with IPython 2.3.0. I have this in my .emacs: (setq python-...
6
votes
1answer
2k views

How do I use a remote virtual environment with emacs?

My particular setup is that my code lives on my machine and is mounted via vagrant onto a linux container upon which the virtual env lives. I'd like to be able to edit all the code, including the ...
6
votes
1answer
544 views

Prevent electric-indent-mode from reindenting the current line on RET

I am using the Spacemacs configuration files. When I am typing code, electric-indent-mode reindents the current line whenever I press enter. This often causes the indentation to be incorrect when ...
6
votes
0answers
188 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. ...

1
2 3 4 5
11