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

查看:32
本文介绍了如何在 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 notebook 的方法,方法是为虚拟环境创建 kernelspecs,然后在 jupyter notebook 中选择 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 notebook.有没有对 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/share/jupyter/kernels/pythonX 中安装了 kernelspec pythonX

其中pythonX是virtualenv中python的版本.

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

4.) 将新的 kernelspec 复制到有用的地方.为您的新内核选择一个 kernel_name,它不是 python2 或 python3 或您之前使用过的内核名称,然后:

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.) 在 vi​​rtualenv 中运行 jupter/ipython 控制台.

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

jupyter console --kernel <kernel-name>

7.) 这将启动当前 virtualenv 的 jupyter 控制台/shell,您还可以在 IPython 笔记本菜单中看到内核:Kernel -> Change kernel 并能够切换到它(您可能需要刷新页面在它出现在列表中之前).从那时起,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天全站免登陆