如何在conda或virtualenv中启动ipython shell(不是笔记本) [英] How to start an ipython shell(not notebook) within a conda or virtualenv

查看:156
本文介绍了如何在conda或virtualenv中启动ipython shell(不是笔记本)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以在conda或virtualenv中启动ipython shell(在终端中)?
ipython shell应该属于相应的环境。

Is it possible to start an ipython shell(in terminal) within a conda or virtualenv ? The ipython shell should belongs to the respective environment.

我知道一种在env中启动jupyter笔记本的方法,为虚拟环境创建一个kernelspecs然后在jupyter笔记本中选择env内核。

I know a way to start jupyter notebook within the env, by creating a kernelspecs for the virtual env and then choosing the env kernel within the jupyter notebook.

这里是链接: http:// help.pythonanywhere.com/pages/IPythonNotebookVirtualenvs

但这只为当前环境设置了jupyter笔记本。有没有为ipython shell做同样的事情

But this only setup the jupyter notebook for the current environment. Is there a to do the same for ipython shell

推荐答案

Grisha Levit给出的答案几乎解决了这个问题。所以,我正在编写答案的完整细节,如何在特定环境中设置ipython控制台。

The answer given by Grisha Levit almost solved the problem. So, i am writing the complete details of the answer, how to setup a ipython console within a specific environment.

1。)激活虚拟环境:

1.) Activate the virtual env:

source activate <environment-name>

2。)在虚拟环境中:

2.) From within the virtual env:

jupyter kernelspec install-self --user

3 。)这将为你的虚拟环境创建一个kernelspec并告诉你它在哪里:

3.) This will create a kernelspec for your virtual env and tell you where it is:


  • 在home / username / .local中安装kernelspec pythonX / share / jupyter / kernels / pythonX

其中pythonX是virtualenv中python的版本。

Where pythonX is the version of the python in the virtualenv.

4。)将新的kernelspec复制到有用的地方。为你的新内核选择一个不是python2或python3的kernel_name,或者你之前使用的那个:

4.) Copy the new kernelspec somewhere useful. Choose a kernel_name for your new kernel that is not python2 or python3 or one you've used before and then:

mkdir -p ~/.ipython/kernels
mv ~/.local/share/jupyter/kernels/pythonX ~/.ipython/kernels/<kernel_name>

5.如果你想更改IPython向你显示的内核名称,你需要编辑〜/ .ipython / kernels // kernel.json并将名为display_name的JSON键更改为您喜欢的名称。

5.) If you want to change the name of the kernel that IPython shows you, you need to edit ~/.ipython/kernels//kernel.json and change the JSON key called display_name to be a name that you like.

6。)运行jupter / ipython控制台在virtualenv中。

6.) Running jupter/ipython console within the virtualenv.

jupyter console --kernel <kernel-name>

7。)这将启动当前virtualenv的jupyter控制台/ shell,你也可以看到内核在IPython笔记本菜单中:内核 - >更改内核并且能够切换到它(您可能需要在页面出现之前刷新页面)。 IPython将记住从那时起用于该笔记本的内核。

7.) This will start the jupyter console/shell for the current virtualenv and you can also see kernel in the IPython notebook menu: Kernel -> Change kernel and be able so switch to it (you may need to refresh the page before it appears in the list). IPython will remember which kernel to use for that notebook from then on.

这篇关于如何在conda或virtualenv中启动ipython shell(不是笔记本)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆