簡體   English   中英

在 Python2 上運行 jupyter notebook 有困難

[英]Difficulty running jupyter notebook on Python2

我的計算機上同時安裝了 Python 2 ( 2.7.14 ) 和 Python 3 ( 3.6.4 )
Linux rajarshi-x550cc 4.15.10-300.fc27.x86_64 #1 SMP Thu Mar 15 17:13:04 UTC 2018 x86_64 x86_64 x86_64 GNU/Linux

我還安裝了 Jupyter Notebook。 當我在 Jupyter Notebook 上運行新內核時,無論我選擇運行 Python-2 內核還是 Python-3 內核,都只運行 Python-3 內核。 我已經用print(sys.version)檢查了這一點。

我在 Stackoverflow 上得到了幾個不錯的答案,但沒有一個對我有用。 我使用以下代碼在/usr/share/jupyter/kernels/python2的 Jupyter 庫中創建了一個 JSON 文件:

{
 "display_name": "Python 2", 
 "language": "python", 
 "argv": [
  "python", 
  "-m", 
  "ipykernel_launcher", 
  "-f", 
  "{connection_file}"
 ]
}

但沒有明顯的區別。

然后我從 Python 3 中卸載了 Jupyter,如下所示: python3 -m pip uninstall jupyter但 Jupyter 仍然存在,它仍然只能識別 Python 3。

老實說,我無計可施。 我應該完全刪除 Python 3 嗎?

您可以使用ipykernel在同一筆記本環境中注冊不同版本的 python。

有關更多信息,請參閱以下文檔https://ipython.readthedocs.io/en/latest/install/kernel_install.html#kernels-for-python-2-and-3

如果我是你,我會完全卸載 python 並繼續如下:

  1. 使用 pythn 3.6 安裝 anaconda
  2. 使用 python 2.7 創建虛擬環境

    conda create -n python27 python=2.7 anaconda

  3. 如果我想要帶有 python 3.6 的 jupyter notebook,我會運行jupyter notebook

  4. 對於帶有 python 2.7 的 jupyter notebook 我將activate python27 python27 然后jupyter notebook 這將使用 python 2.7 啟動筆記本

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM