我很欣赏上面的答案,并基于我写了这个答案。
如果 ipython 已经安装在您的 virtualenv 中,那么下面的任何命令都可以正常工作(在带有示例 sn 的命令之后已经显示-ps,逐点)。
python manage.py shell
python manage.py -i ipython
How I solved (steps with problem & solution)?
注意:确保您已经激活了您的virtualenv。
1) 我的 Django 项目中没有安装 ipython。以下是我在 ipython 环境中尝试运行 Django shell 时遇到的错误。
(venv3.6.7) Rishikeshs-MacBook-Air:src hygull$ python manage.py shell -i ipython
CommandError: Couldn't import ipython interface.
(venv3.6.7) Rishikeshs-MacBook-Air:src hygull$
接下来我使用以下命令安装了 ipython。
2)pip install ipython
(venv3.6.7) Rishikeshs-MacBook-Air:src hygull$ pip install ipython
Collecting ipython
Downloading https://files.pythonhosted.org/packages/05/d7/77b7a1988c99227f52402f93fb0f7e88c97239960516f53907ebbc44149c/ipython-7.11.0-py3-none-any.whl (777kB)
...
...
|████████████████████████████████| 102kB 524kB/s
Installing collected packages: ipython-genutils, six, decorator, traitlets, pygments, ptyprocess, pexpect, wcwidth, prompt-toolkit, backcall, parso, jedi, appnope, pickleshare, ipython
Successfully installed appnope-0.1.0 backcall-0.1.0 decorator-4.4.1 ipython-7.11.0 ipython-genutils-0.2.0 jedi-0.15.2 parso-0.5.2 pexpect-4.7.0 pickleshare-0.7.5 prompt-toolkit-3.0.2 ptyprocess-0.6.0 pygments-2.5.2 six-1.13.0 traitlets-4.3.3 wcwidth-0.1.7
(venv3.6.7) Rishikeshs-MacBook-Air:src hygull$
3.a) python manage,py shell -i ipython
(venv3.6.7) Rishikeshs-MacBook-Air:src hygull$ python manage.py shell -i ipython
Python 3.6.7 (v3.6.7:6ec5cf24b7, Oct 20 2018, 03:02:14)
Type 'copyright', 'credits' or 'license' for more information
IPython 7.11.0 -- An enhanced Interactive Python. Type '?' for help.
In [1]: exit()
3.b) python manage.py shell
(venv3.6.7) Rishikeshs-MacBook-Air:src hygull$ python manage.py shell
Python 3.6.7 (v3.6.7:6ec5cf24b7, Oct 20 2018, 03:02:14)
Type 'copyright', 'credits' or 'license' for more information
IPython 7.11.0 -- An enhanced Interactive Python. Type '?' for help.
In [1]:
谢谢。