Search code examples
pythonemacspdbpythonpathminiconda

Using pdb in emacs with a miniconda install


I am trying to use pdb as a python debugger in emacs

I'm getting the import error issues, as in:

https://emacs.stackexchange.com/questions/18190/missing-modules-when-debugging-python-code-in-emacs

How to specifiy path when using pdb in emacs?

the suggested solution, i.e.

(setenv "PYTHONPATH" "lib")

in .emacs or emacs.d/init.el

This seems very unsatisfactory as you are effectively duplicating the pythonpath data which will trip you up at some point when you update one but not the other.

How can one get the pythonpath as used by pdb to be exactly the same as that is used say if I open an ipython shell.

In other words I want pdb to reflect the path locations that get automatically loaded from my .bashrc and miniconda installation when I open ipython

also, how does ipython know which miniconda dirs to pull into the pythonpath? which file is that specified in?


Solution

    1. Find out where your miniconda install is, for me it was:

      ~/miniconda2

    2. Ensure that your .bashrc PATH is picking up the miniconda python install before any of the default linux installations, i.e. its looking in ~/miniconda2/bin prior to /usr/bin/

    3. Dired into ~/miniconda2/lib/python2.7

    4. 'S' to create a soft symlink to pdb.py, place the link in ~/miniconda2/bin and call it pdb2.7

    5. Dired into ~/miniconda2/bin

    6. 'S' to create a soft symlink to pdb2.7, place link in same dir and call it pdb

    7. Now when you run M-x pdb to invoke the python debugger it should pick up the correct version and not complain of any missing modules

    Prior to this it was picking up pdb from /usr/bin, hence all the module import failures. These steps just copy the set of symlinks found in that dir but using the miniconda equivalent files and dirs