ipdb is triggering ImportError
Question: ipdb is triggering an import error for me when I run my Django site locally.
I'm working on Python 2.7 and within a virtual environment.

`which ipdb` shows the path `(/usr/local/bin/ipdb)`, as does `which ipython`,
which surprised me since I thought it should show my venv path (but shouldn't
it work if it's global, anyway?). So I tried `pip install
--target=/path/to/venv ipdb` and now it shows up in `pip freeze` (which it
didn't before) but still gives me an import error.

`which pip` gives `/Users/myname/.virtualenvs/myenv/bin/pip/`

My path:
`/Users/myname/.virtualenvs/myenv/bin:/Users/myname/.venvburrito/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Users/myname/bin:/usr/local/bin`

Sys.path: `'/Users/myname/Dropbox/myenv',
'/Users/myname/.venvburrito/lib/python2.7/site-packages/pip-1.4.1-py2.7.egg',
'/Users/myname/.venvburrito/lib/python2.7/site-packages',
'/Users/myname/.venvburrito/lib/python2.7/site-
packages/setuptools-8.2-py2.7.egg',
'/Users/myname/.virtualenvs/myenv/lib/python27.zip',
'/Users/myname/.virtualenvs/myenv/lib/python2.7',
'/Users/myname/.virtualenvs/myenv/lib/python2.7/plat-darwin',
'/Users/myname/.virtualenvs/myenv/lib/python2.7/plat-mac',
'/Users/myname/.virtualenvs/myenv/lib/python2.7/plat-mac/lib-scriptpackages',
'/Users/myname/.virtualenvs/myenv/Extras/lib/python',
'/Users/myname/.virtualenvs/myenv/lib/python2.7/lib-tk',
'/Users/myname/.virtualenvs/myenv/lib/python2.7/lib-old',
'/Users/myname/.virtualenvs/myenv/lib/python2.7/lib-dynload',
'/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7',
'/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-
darwin',
'/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-
tk',
'/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-
mac',
'/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-
mac/lib-scriptpackages', '/Users/myname/.virtualenvs/myenv/lib/python2.7/site-
packages']`

If I run ipdb from the terminal, it works fine. I've tried restarting my
terminal.

Stacktrace:

    
    
    Traceback (most recent call last):
      File "/Users/myname/.virtualenvs/myenv/lib/python2.7/site-packages/django/core/handlers/base.py", line 149, in get_response
        response = self.process_exception_by_middleware(e, request)
      File "/Users/myname/.virtualenvs/myenv/lib/python2.7/site-packages/django/core/handlers/base.py", line 147, in get_response
        response = wrapped_callback(request, *callback_args, **callback_kwargs)
      File "/Users/myname/.virtualenvs/myenv/lib/python2.7/site-packages/django/views/generic/base.py", line 68, in view
        return self.dispatch(request, *args, **kwargs)
      File "/Users/myname/.virtualenvs/myenv/lib/python2.7/site-packages/django/views/generic/base.py", line 88, in dispatch
        return handler(request, *args, **kwargs)
      File "/Users/myname/.virtualenvs/myenv/lib/python2.7/site-packages/django/views/generic/base.py", line 157, in get
        context = self.get_context_data(**kwargs)
      File "/Users/myname/Dropbox/blog/views.py", line 22, in get_context_data
        import ipdb; ipdb.set_trace()
    ImportError: No module named ipdb
    


Answer: I just set up a whole virtual env just to try this out because it must be a
simple fix. I managed to set up `ipdb` in my virtual env and I will write what
I did step by step.

    
    
    $ virtualenv foo
    $ cd foo
    $ source ./bin/activate  # activate venv
    

... at this point `which python` and `which pip` gives me the right python
executable inside my virtual env. Then next:

    
    
    (venv: foo)$ pip install ipython
    

At this point, `which ipython` gives me the right ipython executable inside my
virtual env. **It's important to make sure that it points to the right
executables** , if it doesn't show the right executable, but the global one,
re-activate your virtual env. It is crucial that ipython (and all your
executables) point to the right executables inside your virtualenv.

Then I'm gonna try importing ipdb:

    
    
    (venv: foo)$ ipython
    In [1]: import ipdb
    ---------------------------------------------------------------------------
    ImportError                               Traceback (most recent call last)
    <ipython-input-1-2d6f026194dd> in <module>()
    ----> 1 import ipdb
    
    ImportError: No module named 'ipdb'
    

Module not found, because it hasn't been installed yet. Let's do it:

    
    
    (venv: foo)$ pip install ipdb
    

and try it again:

    
    
    (venv: foo)$ ipython                                                                                                          [ 16-05-24 22:28 ]
    Python 3.5.1 (default, Jan 29 2016, 19:58:36) 
    Type "copyright", "credits" or "license" for more information.
    
    IPython 4.2.0 -- An enhanced Interactive Python.
    ?         -> Introduction and overview of IPython's features.
    %quickref -> Quick reference.
    help      -> Python's own help system.
    object?   -> Details about 'object', use 'object??' for extra details.
    
    In [1]: import ipdb
    
    In [2]: 
    

It seems to work for me. I was using `zsh` and `python3` but it shouldn't
matter. Your issue is most likely that it's not being installed in the right
places, meaning is using global executables instead of the ones from the
virtualenv.

From within my virtualenv you could see that ipdb is installed:

    
    
    (venv: foo)$ find . -name ipdb
    ./lib/python3.5/site-packages/ipdb
    

I hope all this write up helps :)

