在Emacs中获取pdb以使用当前virtualenv的Python进程 [英] Getting pdb in Emacs to use Python process from current virtualenv

查看:434
本文介绍了在Emacs中获取pdb以使用当前virtualenv的Python进程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用pdb调试emacs中的一些python代码,并获得一些导入问题。依赖关系安装在我定制的virtualenv环境之一中。



Pdb固执地使用/ usr / bin / python,而不是我的virtualenv的python进程。



我使用virtualenv.el来支持emacs中的环境切换,并通过



中描述的postactivate钩子a href =http://jesselegg.com/archives/2010/03/14/emacs-python-programmers-2-virtualenv-ipython-daemon-mode/ =noreferrer> http://jesselegg.com / archives / 2010/03/14 / emacs-python-programmers-2-virtualenv-ipython-daemon-mode /



运行Mx时运行良好python-shell

 >>>导入sys 
>>>> print sys.path

这指向我所有的virtualenv库,表明python-shell是我的virtualenv。



然而,M-!哪个python,它给了 / usr / bin / python



有谁知道我怎么能告诉Mx pdb从目前采用的python进程active virtualenv?

解决方案

python-shell 使用变量 python -default-interpreter 来确定使用哪个python解释器。当该变量的值为 cpython 时,变量 python-python-command python参考-python-command-args 来确定解释器
和要使用的参数。这两个变量由 virtualenv.el 操纵,以设置当前的虚拟环境。



所以当你使用 python-shell 命令,它使用您的虚拟环境没有任何问题。



但是,当您执行 M-你不使用变量 python-python-command 蟒-蟒-命令ARGS 。所以它使用它在您的路径中找到的python工具。



当您调用 Mx pdb 它使用gud-pdb-command-name作为默认的pdb工具。要重新定义此变量,每次激活环境时,都可以执行以下操作:

 (defadvice virtualenv-activate virtual-pdb)
(custom-set-variables
'(gud-pdb-command-name
(concat virtualenv-active/ bin / pdb))))

(ad-activate'virtualenv-activate)

要在您的虚拟环境中拥有pdb,执行以下操作:

  cp / usr / bin / pdb / path / to / virtual / env / bin 

然后将/ path / to / virtual / env / bin / pdb的第一行编辑为:

 #! / usr / bin / env python 

重新启动你的env和Pdb现在应该使用你的virtualenv python而不是系统范围的python。


I am debugging some python code in emacs using pdb and getting some import issues. The dependencies are installed in one of my bespoked virtualenv environments.

Pdb is stubbornly using /usr/bin/python and not the python process from my virtualenv.

I use virtualenv.el to support switching of environments within emacs and via the postactivate hooks described in

http://jesselegg.com/archives/2010/03/14/emacs-python-programmers-2-virtualenv-ipython-daemon-mode/

This works well when running M-x python-shell

>>> import sys
>>> print sys.path 

This points to all of my virtualenv libraries indicating that the python-shell is that of my virtualenv.

This is contradicted however by M-! which python, which gives /usr/bin/python

Does anyone know how I can tell M-x pdb to adopt the python process from the currently active virtualenv?

解决方案

python-shell uses variable python-default-interpreter to determine which python interpreter to use. When the value of this variable is cpython, the variables python-python-command and python-python-command-args are consulted to determine the interpreter and arguments to use. Those two variables are manipulated by virtualenv.el to set the current virtual environment.

So when you use python-shell command, it uses your virtual environments without any problem.

But, when you do M-! python, you're not using the variables python-python-command and python-python-command-args. So it uses the python tools it finds in your path.

When you call M-x pdb it uses gud-pdb-command-name as the default pdb tool. To redefine this variable, each time you activate an environment, you could do something like this :

(defadvice virtualenv-activate (after virtual-pdb)
  (custom-set-variables
     '(gud-pdb-command-name
        (concat virtualenv-active "/bin/pdb" ))))

(ad-activate 'virtualenv-activate)

To have pdb in your virtual environment, do the following :

cp /usr/bin/pdb /path/to/virtual/env/bin

Then edit the first line of /path/to/virtual/env/bin/pdb to have :

#! /usr/bin/env python

Reactivate your env and Pdb should now use your virtualenv python instead of the system-wide python.

这篇关于在Emacs中获取pdb以使用当前virtualenv的Python进程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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