Python mode in Emacs: no such file or directory, pdb

I have a python script that I want to debug using python-mode . I read in this thread that I can debug my python script using Mx pdb , however I get the following error:

Search for a program: no such file or directory, pdb

I can provide python -m pdb my_source_file.py at the minibuffer prompt, but it would be nice if Emacs could output this command directly from the file on which I run Mx pdb

Update:

Launch:

  • Red Hat Enterprise Linux Server release 5.1 (Tikanga)
  • Emacs 23.3.1

Differences between paths

I get different paths when I run M-: exec-path , and when I run M-: (getenv "PATH") (the one that returns M-: (getenv "PATH") more).

Wherein:

  • Where is pdb located? How to add it to Emacs path?
  • Is there a way to ask Emacs and see the paths that are stored in the PATH environment variable?
+9
python debugging emacs
Feb 06 2018-12-12T00:
source share
5 answers

In addition to my comment earlier and your subsequent update to the question:

First print the value for $PATH , which works in your terminal. Use which pdb to find where the pdb executable is located.

Then set the $PATH environment variable explicitly in Emacs and synchronize it with exec-path as follows:

 (setenv "PATH" "/usr/local/bin:/usr/bin:/bin:/some/other/dir") (setq exec-path (split-string (getenv "PATH") path-separator)) 

You may also need to explicitly specify PYTHONPATH or similar environment variables; you can do this using lines like the "setenv" line above, or just use exec-path-from-shell elisp package .

Update

Ok, so the Emacs pdb command is not provided by python-mode , and it expects to find an executable file called "pdb". An easy way to fix this, then create a shell wrapper called "pdb" in your $ PATH directory:

 #!/bin/sh exec python -m pdb "$@" 

(I found a note here suggesting this technique.)

Equivalent for Windows would be a pdb.bat file containing:

 python -u -m pdb %1 

( -u prevents Python output buffering).

+6
Feb 07 2018-12-12T00:
source share

To start Python Debugger, Mx pdb expects to find an executable file called pdb . Although the pdb executable may exist on some Python distributions, it does not exist on all of them.

Suggestion to fix this in GNU Error Report # 21521: Proposed default pdb command .

Until the error is fixed, you can set the variable gud-pdb-command-name to determine the command used to run pdb. In .emacs add ...

 (setq gud-pdb-command-name "python -m pdb") 
+5
Nov 19 '15 at 18:04
source share

At the command prompt

 which pdb 

In Emacs, enter Mx customize . Choose Programming> Tools> Hood. Set the gud-pdb-command-name value to the path returned by which pdb .

If your version of Emacs represents a different organization for the setup menu, you can also try

 Ch v gud-pdb-command-name 

Then click the customize link and set the path to pdb .

Although the above instructions are different from each other, I found this by reading "Running pdb under emacs" .

+3
Feb 08 '12 at 11:17
source share

You can create a custom command as follows:

 ;; PDB command line (defun user-python-debug-buffer () "Run python debugger on current buffer." (interactive) (setq command (format "python -u -m pdb %s " (file-name-nondirectory buffer-file-name))) (let ((command-with-args (read-string "Debug command: " command nil nil nil))) (pdb command-with-args))) 
+2
Feb 07 2018-12-12T00:
source share

In Emacs 23.3.1 and, presumably above, another option is to use the Emacs shell, Eshell ( Mx eshell ). Within Eshell, there is an existing, Lisp pdb definition. These Lisp functions work in Eshell like normal shell commands.

So pdb "./manage.py runserver" will start the Django server, for example.

0
Jun 20 2018-12-12T00:
source share



All Articles