问题描述
我在OS X 10.10中使用pip安装了iPython,它给了我ipython和ipython2命令,这些命令运行得很好,但它们使用OS X的默认python版本2.7.9。我下载并安装了最新版本的Python3.4并可以使用命令python3加载它,但找不到让iPython使用这个版本的python的方法。 iPython网站声明该软件包可以与python版本3.3及更高版本一起使用,但是我找不到任何关于如何更改所使用的默认python版本的说明。
I have installed iPython using pip in OS X 10.10, and it gave me the "ipython" and "ipython2" commands, which run great, but which use OS X's default python version 2.7.9. I downloaded and installed the latest release of Python3.4 and can load it with the command "python3," but cannot find a way to get iPython to use this version of python. The iPython Web site states the package can be used with python versions 3.3 and above, but I cannot find any instruction on how to change the default python version used.
到目前为止我发现iPython的jupyter包在/ usr / local / share / jupyter / kernels /中有一个内核规范,它只是一个名为python2的文件夹,其中包含指向系统的python 2.7.6的json文件,但是改变这一点指向新的python3.4安装不起作用。我猜这个配置适用于ipython笔记本。
So far I have found that the jupyter package for iPython has a kernel specification in /usr/local/share/jupyter/kernels/, which is just a folder called "python2" containing a json file that points to the system's python 2.7.6, but altering this to point to the new python3.4 installation does not work. My guess is this configuration is for the ipython notebook.
我也尝试过这种方法:
I've also tried the approach here: ipython reads wrong python version
这样做我在/ user中复制了ipython2命令/ local / bin /并编辑它以使用位于/Library/Frameworks/Python.framework/Versions/3.4/bin/python3的python3解释器,但是,这给了我一个错误ImportError:没有名为'IPython'的模块,这表明python3安装没有安装ipython。
In doing so I've duplicated the ipython2 command in /user/local/bin/ and edited it to use the python3 interpreter located at /Library/Frameworks/Python.framework/Versions/3.4/bin/python3, however, this gives me an error "ImportError: No module named 'IPython'," which suggests the python3 installation does not have ipython installed.
为了解决这个问题,我尝试卸载ipython并使用pip重新安装它,但它只针对系统的Python 2.7安装并没有为python3做任何事情。
To tackle this, I've tried uninstalling ipython and reinstalling it using pip, but it just targets the system's Python 2.7 installation and does nothing for python3.
有谁知道如何配置iPython使用不同的python版本,甚至为python3安装单独的ipython安装?最终根据我的需要快速来回切换会很好。
Does anyone know how to configure iPython to use a different python version, or even install a separate ipython installation for python3? Ultimately it would be nice to quickly switch back and forth depending on my needs.
推荐答案
我刚刚找到答案。本质上,这源于不了解python安装布局以及如何在已安装的解释器之间分离资源。看起来每个python版本都有自己的工具库,我在系统上安装的当前pip命令被映射为与python 2.7一起使用,所以它管理的所有库,工具和其他细节只能用于python 2.7。这包括iPython。
I just found the answer. In essence, this stems from not understanding the python installation layout and how resources are separated between installed interpreters. It appears each python version will have its own repository of tools, and the current "pip" command I had installed on the system was mapped for use with python 2.7, so all libraries, tools, and other details it managed where available only to python 2.7. This included iPython.
我认为安装python3默认情况下会让所有这些库都可用于新的解释器,但看起来系统将它们全部分开(这很有意义) )。这里的主要问题是继续使用针对旧安装的pip,而不是python3附带的新pip3命令。通过使用pip3重新安装iPython,我能够正确安装iPython3。
I thought that installing python3 would make all these libraries available to the new interpreter by default, but it appears the system keeps them all separate (which makes sense). The main issue here was continuing to use "pip" which targeted the old installation, instead of the new "pip3" command included with python3. By using pip3 to reinstall iPython, I was able to get iPython3 installed properly.
不幸的是,这个设置意味着需要重新下载其他库,但这并不太难。
Unfortunately this setup means needing to re-download other libraries, but that's not too difficult.
事后看来这似乎是一个微不足道的问题,但这让我完全陷入困境。我希望在这种情况下这有助于其他人。
It might seem like a trivial issue in hindsight, but this had me completely stuck. I hope this helps someone else in this situation.
这篇关于如何更改iPython的内核/ python版本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!