简体   繁体   English

如何让 IPython Notebook 运行 Python 3?

[英]How To Get IPython Notebook To Run Python 3?

I am new to Python to bear with me.我是 Python 新手,可以忍受。

  1. I installed Anaconda, works great.我安装了 Anaconda,效果很好。
  2. I setup a Python 3 environment following the Anaconda cmd line instructions , works great.我按照 Anaconda cmd 行说明设置了 Python 3 环境,效果很好。
  3. I setup Anaconda's Python 3 environment as Pycharm's interpreter , works great.我将Anaconda 的 Python 3 环境设置为 Pycharm 的解释器,效果很好。
  4. I launched the Anaconda "launcher.app" and launched IPython Notebook.我启动了Anaconda “launcher.app”并启动了 IPython Notebook。 However, iPython Notebook is running Python 2 not 3.但是,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。

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

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。

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

Is there a package from your distro?你的发行版有包吗? If you're using ubuntu you must to install the ipython3-notebook package.如果您使用的是 ubuntu,则必须安装 ipython3-notebook 包。 If not, maybe you must to install ipython with python3.如果没有,也许您必须使用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.用python3而不是python2安装一个包。 This will be a new instalation of ipython3.这将是 ipython3 的新安装。

In Anaconda "launcher.app" there is “Environment:” pull down menu.在 Anaconda 的“launcher.app”中有“环境:”下拉菜单。 The default environment is called "root".默认环境称为“root”。 In order to launch application using another environment, just select the desired environment from the list, to make it active.为了使用另一个环境启动应用程序,只需从列表中选择所需的环境,使其处于活动状态。

如果您正在运行 anaconda,那么安装 notebook/jupyter 的首选方法是使用 conda:

conda install jupyter

如果您在 jupyter notebook 上有这两个版本,您可以从菜单中更改内核。

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 内核,或者从内核菜单中选择正在运行的笔记本。

Another solution would be to create a virtualenv with python3:另一种解决方案是使用 python3 创建一个virtualenv

From this environment, install tensorflow (the version you prefer) there:在这个环境中,在那里安装 tensorflow(你喜欢的版本):

pip install tensorflow

Run your jupyter from there !从那里运行你的 jupyter!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM