如何让 IPython Notebook 运行 Python 3?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/20360293/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How To Get IPython Notebook To Run Python 3?
提问by Anton
I am new to Python to bear with me.
我是 Python 新手,可以忍受。
- I installed Anaconda, works great.
- I setup a Python 3 environment following the Anaconda cmd line instructions, works great.
- I setup Anaconda's Python 3 environment as Pycharm's interpreter, works great.
- I launched the Anaconda "launcher.app"and launched IPython Notebook. However, iPython Notebook is running Python 2 not 3.
- 我安装了 Anaconda,效果很好。
- 我按照 Anaconda cmd 行说明设置了 Python 3 环境,效果很好。
- 我将Anaconda 的 Python 3 环境设置为 Pycharm 的解释器,效果很好。
- 我启动了Anaconda “launcher.app”并启动了 IPython Notebook。但是,iPython Notebook 运行的是 Python 2 而不是 3。
Over three hours of Googling later, I cannot figure out how to set IPython Notebook to run Python 3 instead of 2.
经过三个多小时的谷歌搜索,我无法弄清楚如何设置 IPython Notebook 以运行 Python 3 而不是 2。
回答by Orlando
Is there a package from your distro? If you're using ubuntu you must to install the ipython3-notebook package. If not, maybe you must to install ipython with python3.
你的发行版有包吗?如果您使用的是 ubuntu,则必须安装 ipython3-notebook 包。如果没有,也许您必须使用python3安装ipython。
If you've run (because it's python2 by default)
如果你已经运行了(因为它默认是 python2)
python setup.py
you must to run instead
你必须跑
python3 setup.py install
to install a package with python3 instead python2. This will be a new instalation of ipython3.
用python3而不是python2安装一个包。这将是 ipython3 的新安装。
回答by Andrzej Neugebauer
In Anaconda "launcher.app" there is “Environment:” pull down menu. The default environment is called "root". In order to launch application using another environment, just select the desired environment from the list, to make it active.
在 Anaconda 的“launcher.app”中有“环境:”下拉菜单。默认环境称为“root”。为了使用另一个环境启动应用程序,只需从列表中选择所需的环境,使其处于活动状态。
回答by Noha Elprince
To set IPython Notebook to run Python 3 instead of 2 on my MAC 10.9, I did the following steps
要将 IPython Notebook 设置为在我的 MAC 10.9 上运行 Python 3 而不是 2,我执行了以下步骤
$ sudo pip3 install ipython[all]
Then
然后
$ ipython3 notebook
回答by Paul
If you are running anaconda, then the preferred way to install notebook/jupyter is using conda:
如果您正在运行 anaconda,那么安装 notebook/jupyter 的首选方法是使用 conda:
conda install jupyter
回答by Arun Kumar Khattri
If you have both version available on jupyter notebook, you can change the kernel from menu.
如果您在 jupyter notebook 上有这两个版本,您可以从菜单中更改内核。
回答by Panos
For linux 16.04 Ubuntu you can use
对于 linux 16.04 Ubuntu,您可以使用
sudo apt-get install ipython3
and then use
然后使用
ipython3 notebook
to open the notebook in the browser. If you have any notebooks saved with python 2 then it will automatically convert them to Python 3 once you open the notebook.
在浏览器中打开笔记本。如果您有任何使用 python 2 保存的笔记本,那么一旦您打开笔记本,它就会自动将它们转换为 Python 3。
回答by Moitreyee Dasgupta
To use jupyter with python 3 instead of python 2 on my Windows 10 with Anaconda, I did the following steps on anaconda prompt:
要在带有 Anaconda 的 Windows 10 上使用 jupyter 和 python 3 而不是 python 2,我在 anaconda 提示符下执行了以下步骤:
pip3 install ipython[all]
Then,
然后,
ipython3 notebook
回答by Magaly Alonzo
Another solution would be to create a virtualenvwith python3:
另一种解决方案是使用 python3创建一个virtualenv:
From this environment, install tensorflow (the version you prefer) there:
在这个环境中,在那里安装 tensorflow(你喜欢的版本):
pip install tensorflow
Run your jupyter from there !
从那里运行你的 jupyter!
回答by CodeKid
Switch the role of 2 and 3 in this answer as appropriate.
根据需要切换此答案中 2 和 3 的角色。
Say you already have jupyter setup with a python 2 kernel and an anaconda environment with python 3. Activate the python 3 enviroment and then run
假设您已经安装了带有 python 2 内核的 jupyter 和带有 python 3 的 anaconda 环境。激活 python 3 环境,然后运行
conda install ipykernel
After that you can select both a 2 and 3 kernel when creating a new notebook, or in a running notebook from the kernels menu.
之后,您可以在创建新笔记本时选择 2 和 3 内核,或者从内核菜单中选择正在运行的笔记本。

