作者:刁琼婉 | 来源:互联网 | 2023-05-17 18:08
(myvenv)me:srcorokusaki$pythonmanage.pyshell-iipythonPython2.7.2(default,Jun162012,12:3
(myvenv)me:src orokusaki$ python manage.py shell -i ipython
Python 2.7.2 (default, Jun 16 2012, 12:38:40)
[GCC 4.2.1 Compatible Apple Clang 4.0 (tags/Apple/clang-418.0.60)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
(InteractiveConsole)
>>> while True:
... pass # :(
...
I have IPython installed globally, and it works while this myvenv
virtualenv is activated just fine. However, if I start the Django shell (with or without -i
), it won't use IPython. I've never had this problem before.
我在全球范围内安装了IPython,它可以正常激活这个myvenv virtualenv。但是,如果我启动Django shell(带或不带-i),它将不会使用IPython。我以前从未遇到过这个问题。
Note: django-admin.py
vs manage.py
won't make a difference.
注意:django-admin.py vs manage.py不会产生任何影响。
3 个解决方案
1
In my case, I really want to run IPython in multiple virtual environments (created using the default --no-site-packages) each used for a different Django project. I did not want to install IPython in each env.
在我的例子中,我真的想在多个虚拟环境中运行IPython(使用默认的--no-site-packages创建),每个环境都用于不同的Django项目。我不想在每个环境中安装IPython。
As @Arash mentioned, exporting the DJANGO_SETTINGS_MODULE
works but it's difficult to manage it when you have multiple projects.
正如@Arash所提到的,导出DJANGO_SETTINGS_MODULE可以工作,但是当你有多个项目时很难管理它。
I finally solved this issue in two parts.
我终于分两部分解决了这个问题。
First I added the directories "/usr/lib/python2.7/dist-packages" and "/usr/lib/pymodules/python2.7"to sys.path in the /usr/bin/ipython script as mentioned here.
首先,我在/ usr / bin / ipython脚本中添加了目录“/usr/lib/python2.7/dist-packages”和“/usr/lib/pymodules/python2.7”到sys.path,如下所述。
Next, I use a manage_to_ipython.py
script to create a django-project-specific script called runipython.py
leveraging the manage.py
file created by django-admin.py
接下来,我使用manage_to_ipython.py脚本创建一个名为runipython.py的django-project特定脚本,利用django-admin.py创建的manage.py文件
Once in each Django project, $cd
then run python manage_to_ipython.py
在每个Django项目中,$ cd
然后运行python manage_to_ipython.py
Now, to run IPython simply type ./runipython.py
现在,要运行IPython,只需输入./runipython.py即可
The modified /usr/bin/ipython and the manage_to_ipython.py scripts can be found here.
可以在此处找到修改后的/ usr / bin / ipython和manage_to_ipython.py脚本。