Using both Python 2.x and Python 3.x in IPython Notebook

后端 未结 11 2162
生来不讨喜
生来不讨喜 2020-11-22 02:27

I use IPython notebooks and would like to be able to select to create a 2.x or 3.x python notebook in IPython.

I initially had Anaconda. With Anaconda a global envi

11条回答
  •  长发绾君心
    2020-11-22 03:07

    With a current version of the Notebook/Jupyter, you can create a Python3 kernel. After starting a new notebook application from the command line with Python 2 you should see an entry „Python 3“ in the dropdown menu „New“. This gives you a notebook that uses Python 3. So you can have two notebooks side-by-side with different Python versions.

    The Details

    1. Create this directory: mkdir -p ~/.ipython/kernels/python3
    2. Create this file ~/.ipython/kernels/python3/kernel.json with this content:

      {
          "display_name": "IPython (Python 3)", 
          "language": "python", 
          "argv": [
              "python3", 
              "-c", "from IPython.kernel.zmq.kernelapp import main; main()", 
              "-f", "{connection_file}"
          ], 
          "codemirror_mode": {
              "version": 2, 
              "name": "ipython"
          }
      }
      
    3. Restart the notebook server.

    4. Select „Python 3“ from the dropdown menu „New“
    5. Work with a Python 3 Notebook
    6. Select „Python 2“ from the dropdown menu „New“
    7. Work with a Python 2 Notebook

提交回复
热议问题