Emacs 中的 Python 模式:没有那个文件或目录,pdb [英] Python mode in Emacs: No such file or directory, pdb

查看:21
本文介绍了Emacs 中的 Python 模式:没有那个文件或目录,pdb的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 python 脚本,我想用 python-mode 进行调试.我在这个线程中读到,我可以使用Mx pdb调试我的python脚本,但是我收到以下错误:

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 error:

搜索程序:没有那个文件或目录,pdb

Searching for program: no such file or directory, pdb

我可以在 minibuffer 的提示中提供 python -m pdb my_source_file.py,但是如果 Emacs 可以直接从我运行 Mx 的文件中推断出这个命令就好了pdb

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

  • 红帽企业 Linux 服务器 5.1 版 (Tikanga)
  • Emacs 23.3.1

当我运行 M-: exec-path 和当我运行 M-: (getenv "PATH") 时,我得到不同的路径(由 M-: (getenv "PATH") 更长).

I get different paths when I run M-: exec-path and when I run M-: (getenv "PATH") (the one returned by M-: (getenv "PATH") is longer).

有了这个:

  • pdb 在哪里?如何将其添加到 Emacs 路径?
  • 有没有办法让 Emacs 查看环境变量 PATH 保存的路径?
  • Where is pdb located? How can I add it to the Emacs path?
  • Is there a way to ask Emacs to also look into the paths held by the environment variable PATH?

推荐答案

进一步了解我之前的评论,以及您对问题的后续更新:

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

首先找出在您的终端中工作的 $PATH 的值.使用 which pdb 查找 pdb 可执行文件所在的位置.

First figure out a value for $PATH that works in your terminal. Use which pdb to find where the pdb executable is located.

然后,在 Emacs 中显式设置 $PATH 环境变量,并将其同步到 exec-path 如下:

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))

您可能还需要显式设置 PYTHONPATH 或类似的环境变量;你可以使用上面的setenv"行来做到这一点,或者只使用 exec-path-from-shell elisp 包.

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.

更新

好的,结果证明 Emacs 的 pdb 命令不是由 python-mode 提供的,它希望找到一个名为pdb"的可执行文件.解决此问题的简单方法是在 $PATH 上的目录中创建一个名为pdb"的 shell 包装器:

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.)

Windows 下的等效文件是一个名为 pdb.bat 的文件,其中包含:

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

python -u -m pdb %1

(-u 阻止 Python 缓冲其输出.)

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

这篇关于Emacs 中的 Python 模式:没有那个文件或目录,pdb的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆