简体   繁体   English

Ipython3和Ipython2冲突

[英]Ipython3 and Ipython2 conflict

On Ubuntu 15.04, I had ipython2 installed correctly and working with notebook, under the condition that I added "/usr/local/lib/python2.7/dist-packages" to the PYTHONPATH. 在Ubuntu 15.04上,我已将ipython2正确安装并可以在Notebook上使用,条件是我在PYTHONPATH中添加了“ /usr/local/lib/python2.7/dist-packages”。

Now, I installed python3 and ipython3. 现在,我安装了python3和ipython3。 ipython3 notebook works perfectly (provided I remove the above reference from the pythonpath). ipython3 notebook可以完美运行(前提是我从pythonpath中删除了以上引用)。 But ipython2 notebook returns 但是ipython2 notebook返回

Could not start notebook. Please install ipython-notebook

regardless of the PYTHONPATH. 不管PYTHONPATH。

I have python2 and python3 installed in /usr/bin/ and ipython2 and ipython3 installed in /usr/local/bin. 我在/ usr / bin /中安装了python2和python3,在/ usr / local / bin中安装了ipython2和ipython3。 The ipythons were installed with pip and pip3. ipythons与pip和pip3一起安装。

Now, if I do install ipython-notebook , it installs (I think) another ipython in /usr/bin, which also doesn't work. 现在,如果我确实安装了ipython-notebook ,它将(我认为)在/ usr / bin中安装另一个ipython,这也不起作用。

This is a bit confusing, in other words I have a mess of python distributions. 这有点令人困惑,换句话说,我有一堆python发行版。 Next time I should use anaconda, I know. 下次我应该使用水蟒。 But at the moment I would like to stick to this. 但此刻,我谨坚持这一点。 How do I make it work? 我该如何运作?

It is rare that you should set PYTHONPATH at all except for advanced use cases, and you should never set PYTHONPATH to a standard directory that's already on sys.path for one version of Python. 除高级用例外,很少设置PYTHONPATH,并且永远不要将PYTHONPATH设置为一个版本的Python在sys.path上已经存在的标准目录。 The only thing that can do is break Python, especially versions other than the one for which that directory is already used. 唯一可以做的就是破坏Python,尤其是除已使用该目录的版本以外的其他版本。

How are you installing ipython-notebook ? 您如何安装ipython-notebook

To install the notebook with pip, do: 要使用pip安装笔记本,请执行以下操作:

pip3 install notebook
jupyter notebook

Take note of the paths where that command has installed files. 记下该命令已安装文件的路径。 It will likely be in /usr/local . 它可能在/usr/local

If you are getting a different version of IPython than you expect, then there could be an easy-install.pth messing up your import path. 如果您得到的IPython版本与您期望的版本不同,那么可能有一个easy-install.pth弄乱了您的导入路径。 A common problem caused by old and broken setuptools . 由老化和损坏的setuptools引起的常见问题。 You can test this with: 您可以使用以下方法进行测试:

python3 -c 'import IPython; print(IPython.__file__)'

and/or 和/或

python3 -m site # shows your sys.path

If you see lines starting with /usr/lib in usr/local/lib/pythonX.Y/dist-packages/easy-install.pth , remove them, they can cause the wrong versions of packages to be imported. 如果在usr/local/lib/pythonX.Y/dist-packages/easy-install.pth看到以/usr/lib开头的行,请将其删除,它们可能会导致导入错误版本的软件包。

Often, the easiest way to be sure is to remove all versions of a package and start again. 通常,确定的最简单方法是删除软件包的所有版本,然后重新开始。 You can try pip uninstall ipython , and keep repeating until it says there's no version installed. 您可以尝试pip uninstall ipython ,并不断重复操作直到提示未安装任何版本。 You may also have installed IPython with apt-get , in which case you can remove it with apt-get remove ipython . 您可能还使用apt-get安装了IPython,在这种情况下,可以使用apt-get remove ipython删除它。 Once you are confident that there is no IPython on your system, you can install again with 一旦确定系统上没有IPython,就可以使用

python2 -m pip install ipython
python3 -m pip install ipython

(if you want it for both Legacy Python and Python 3) (如果您想同时使用Legacy Python和Python 3)

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

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