Emacs中的Python模式:没有这样的文件或目录,pdb [英] Python mode in Emacs: No such file or directory, pdb
问题描述
我有一个python脚本,我想使用 python-mode 进行调试。我阅读了这个线程,我可以使用 Mx pdb
,但是我收到以下错误:
搜索程序:没有这样的文件或目录, pdb
我可以在提示中提供 python -m pdb my_source_file.py
在minibuffer中,但是如果Emacs可以直接从我运行的文件中推断出这个命令,那将是很好的。$ M $ p $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $
运行于:
- 红帽企业版Linux服务器版本5.1(Tikanga)
- Emacs 23.3.1
路径之间的差异
当我运行 M-:exec-path
,当我运行 M-时,我得到不同的路径: (getenvPATH)
(由 M-返回的那个(getenvPATH)
更长)
有了这个:
- 位于哪里
pdb
如何将其添加到Emacs路径? - 有没有办法让Emacs 还查看环境变量
PATH
?
在我之前的评论中,以及您以后对该问题的更新: p>
首先计算出在您的终端中有效的 $ PATH
的值。使用哪个pdb
找到 pdb
可执行文件所在的位置。
然后,在Emacs中显式设置 $ PATH
环境变量,并将其同步到 exec-path
如下:
(setenvPATH/ usr / local / bin:/ usr / bin:/ bin:/ some / other / dir)
(setq exec-path(split-string(getenvPATH)path-separator))
可能您还需要明确设置 PYTHONPATH
或类似的环境变量;您可以使用上述setenv行,或使用 exec-path -from-shell elisp包。
更新
,所以事实证明,Emacs的 pdb
命令不是由 python-mode
提供的,它期望找到一个可执行文件称为pdb。解决这个问题的简单方法是在$ PATH的目录中创建一个名为pdb的shell包装:
##/ bin / sh
exec python -m pdb$ @
我发现一条说明 here 表示这种技巧。)
Windows下的等效文件将是一个名为pdb.bat的文件,其中包含:
python -u -m pdb% 1
( -u
缓冲其输出。)
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:
Searching for program: no such file or directory, 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
Update:
Running on:
- 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 returned by M-: (getenv "PATH")
is longer).
With this:
- 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:
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.)
这篇关于Emacs中的Python模式:没有这样的文件或目录,pdb的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!