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-shelluses variablepython-default-interpreterto determine which python interpreter to use. When the value of this variable iscpython, the variablespython-python-commandandpython-python-command-argsare consulted to determine the interpreterand arguments to use. Those two variables are manipulated by
virtualenv.elto set the current virtual environment.So when you use
python-shellcommand, it uses your virtual environments without any problem.But, when you do M-!
python, you’re not using the variablespython-python-commandandpython-python-command-args. So it uses the python tools it finds in your path.When you call M-x
pdbit 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 :To have pdb in your virtual environment, do the following :
Then edit the first line of /path/to/virtual/env/bin/pdb to have :
Reactivate your env and Pdb should now use your virtualenv python instead of the system-wide python.