在IPython Notebook中使用Python 2.x和Python 3.x. [英] Using both Python 2.x and Python 3.x in IPython Notebook
问题描述
我使用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 kernelspec来保持我的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。
- MacPorts is installed in the usual /opt directory
- python 2.7 is installed through macports
- python 3.4 is installed through macports
- Ipython is installed for python 2.7
- Ipython is installed for python 3.4
对于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屋!