如何使IPython Notebook运行Python 3?

问题:如何使IPython Notebook运行Python 3?

我是Python的新手。

  1. 我安装了Anaconda,效果很好。
  2. 我按照Anaconda cmd行说明设置了Python 3环境,效果很好。
  3. 我将Anaconda的Python 3环境设置为Pycharm的解释器,效果很好。
  4. 我启动了Anaconda“ launcher.app”,并启动了IPython Notebook。但是,iPython Notebook正在运行Python 2而不是3。

经过三个多小时的Google搜索,我无法弄清楚如何将IPython Notebook设置为运行Python 3而不是2。

I am new to Python to bear with me.

  1. I installed Anaconda, works great.
  2. I setup a Python 3 environment following the Anaconda cmd line instructions, works great.
  3. I setup Anaconda’s Python 3 environment as Pycharm’s interpreter, works great.
  4. I launched the Anaconda “launcher.app” and launched IPython Notebook. However, iPython Notebook is running Python 2 not 3.

Over three hours of Googling later, I cannot figure out how to set IPython Notebook to run Python 3 instead of 2.


回答 0

要将IPython Notebook设置为在MAC 10.9上运行Python 3而不是2,我执行了以下步骤

$ sudo pip3 install ipython[all]

然后

$ ipython3 notebook

To set IPython Notebook to run Python 3 instead of 2 on my MAC 10.9, I did the following steps

$ sudo pip3 install ipython[all]

Then

$ ipython3 notebook


回答 1

对于Linux 16.04 Ubuntu,您可以使用

sudo apt-get install ipython3

然后使用

ipython3 notebook

在浏览器中打开笔记本。如果您有任何笔记本用python 2保存,则打开笔记本后它将自动将其转换为Python 3。

For linux 16.04 Ubuntu you can use

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.


回答 2

要在带有Anaconda的Windows 10上将jupyter与python 3而不是python 2一起使用,我在anaconda提示符下执行了以下步骤:

pip3 install ipython[all]

然后,

ipython3 notebook

To use jupyter with python 3 instead of python 2 on my Windows 10 with Anaconda, I did the following steps on anaconda prompt:

pip3 install ipython[all]

Then,

ipython3 notebook

回答 3

您的发行版中有包装吗?如果您使用的是ubuntu,则必须安装ipython3-notebook软件包。如果没有,也许您必须使用python3安装ipython。

如果您已经运行(因为默认情况下是python2)

python setup.py

您必须改为跑步

python3 setup.py install

使用python3而不是python2安装软件包。这将是ipython3的新安装。

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.

If you’ve run (because it’s python2 by default)

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.


回答 4

在Anaconda的“ launcher.app”中,有“环境:”下拉菜单。默认环境称为“根”。为了使用其他环境启动应用程序,只需从列表中选择所需的环境以使其处于活动状态即可。

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.


回答 5

如果您正在运行anaconda,则安装笔记本/ jupyter的首选方法是使用conda:

conda install jupyter

If you are running anaconda, then the preferred way to install notebook/jupyter is using conda:

conda install jupyter

回答 6

如果在jupyter笔记本电脑上都有这两个版本,则可以从菜单中更改内核。

If you have both version available on jupyter notebook, you can change the kernel from menu.


回答 7

适当切换此答案中2和3的角色。

假设您已经安装了带有python 2内核的jupyter设置和带有python 3的anaconda环境。激活python 3环境,然后运行

conda install ipykernel

之后,您可以在创建新笔记本或从内核菜单中选择正在运行的笔记本中同时选择2和3内核。

Switch the role of 2 and 3 in this answer as appropriate.

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

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.


回答 8

另一个解决方案是使用python3 创建virtualenv

在此环境中,在此处安装tensorflow(您喜欢的版本):

pip install tensorflow

从那里运行您的jupyter!

Another solution would be to create a virtualenv with python3:

From this environment, install tensorflow (the version you prefer) there:

pip install tensorflow

Run your jupyter from there !