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

后端 未结 7 1610
南旧
南旧 2020-12-14 11:30

I have a python script that I want to debug with python-mode. I read in this thread that I can debug my python script with M-x pdb, however I get the following

7条回答
  •  囚心锁ツ
    2020-12-14 11:49

    Further to my comment earlier, and your subsequent update to the question:

    First figure out a value for $PATH that 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 sync it to exec-path as follows:

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

    It's possible you would need to also explicitly set PYTHONPATH or similar environment variables; you can do that using lines like the "setenv" line above, or just use the exec-path-from-shell elisp package.

    Update

    Okay, so it turns out Emacs' pdb command isn't provided by python-mode, and it expects to find an executable called "pdb". The easy way to fix this, then is to create a shell wrapper called "pdb", in a directory on your $PATH:

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

    (I found a note here suggesting this technique.)

    The equivalent under Windows would be a file called pdb.bat, containing:

    python -u -m pdb %1
    

    (The -u prevents Python from buffering its output.)

提交回复
热议问题