在 IPython Notebook 中同时使用 Python 2.x 和 Python 3.x [英] Using both Python 2.x and Python 3.x in IPython Notebook

查看:29
本文介绍了在 IPython Notebook 中同时使用 Python 2.x 和 Python 3.x的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用 IPython 笔记本,希望能够选择在 IPython 中创建 2.x 或 3.x python 笔记本.

I use IPython notebooks and would like to be able to select to create a 2.x or 3.x python notebook in IPython.

我最初拥有 Anaconda.使用 Anaconda 时,必须更改全局环境变量以选择所需的 Python 版本,然后才能启动 IPython.这不是我想要的,所以我卸载了 Anaconda,现在使用 MacPorts 和 PiP 设置了我自己的安装.看来还是得用

I initially had Anaconda. With Anaconda a global environment variable had to be changed to select what version of python you want and then IPython could be started. This is not what I was looking for so I uninstalled Anaconda and now have set up my own installation using MacPorts and PiP. It seems that I still have to use

port select --set python <python version> 

在 python 2.x 和 3.x 之间切换.这并不比 anaconda 解决方案好.

to toggle between python 2.x and 3.x. which is no better than the anaconda solution.

在启动 IPython 笔记本后,有没有办法选择要使用的 Python 版本,最好使用我当前的 MacPorts 版本?

Is there a way to select what version of python you want to use after you start an IPython notebook, preferably with my current MacPorts build?

推荐答案

一个可用的解决方案允许我通过配置 Ipython 内核规范来保留我的 MacPorts 安装.

A solution is available that allows me to keep my MacPorts installation by configuring the Ipython kernelspec.

要求:

  • MacPorts 安装在通常的/opt 目录中
  • python 2.7 通过 macports 安装
  • python 3.4 通过 macports 安装
  • 为 python 2.7 安装了 Ipython
  • 为 python 3.4 安装了 Ipython

对于 python 2.x:

For python 2.x:

$ cd /opt/local/Library/Frameworks/Python.framework/Versions/2.7/bin
$ sudo ./ipython kernelspec install-self

对于 python 3.x:

For python 3.x:

$ cd /opt/local/Library/Frameworks/Python.framework/Versions/3.4/bin
$ sudo ./ipython kernelspec install-self

现在您可以打开一个 Ipython 笔记本,然后选择一个 python 2.x 或一个 python 3.x 笔记本.

Now you can open an Ipython notebook and then choose a python 2.x or a python 3.x notebook.

这篇关于在 IPython Notebook 中同时使用 Python 2.x 和 Python 3.x的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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