当我在本地运行 Django 站点时,ipdb 为我触发了导入错误。我正在使用 Python 2.7 和虚拟环境。
which ipdb
显示 path (/usr/local/bin/ipdb)
,which ipython
这让我感到惊讶,因为我认为它应该显示我的 venv 路径(但如果它是全局的,它不应该工作吗?)。所以我尝试pip install --target=/path/to/venv ipdb
了,现在它出现了pip freeze
(以前没有),但仍然给我一个导入错误。
which pip
给/Users/myname/.virtualenvs/myenv/bin/pip/
我自己的路: /Users/myname/.virtualenvs/myenv/bin:/Users/myname/.venvburrito/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Users/myname/bin:/usr/local/bin
系统路径:
'/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']
如果我从终端运行 ipdb,它工作正常。我试过重新启动我的终端。
堆栈跟踪:
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