Why python's versions differ when called from Terminal and from Atom

后端 未结 3 834
醉梦人生
醉梦人生 2021-01-27 10:13

When I run Python from the terminal and from Atom, different versions of python are called. As a consequence, there are packages that I can call without problems fr

相关标签:
3条回答
  • 2021-01-27 10:40

    Ok, I had actually to change the Path in the .json file of the jupyter kernel. First I checked the list of jupyter kernel:

    $ jupyter kernelspec list
    julia-0.6    /Users/mymac/Library/Jupyter/kernels/julia-0.6
    julia-1.0    /Users/mymac/Library/Jupyter/kernels/julia-1.0
    python3      /Users/mymac/Library/Jupyter/kernels/python3
    

    I then cd the above python path and, I found the file kernel.json inside and opened it:

    {
     "argv": [
      "/path/to/python",
      "-m",
      "ipykernel_launcher",
      "-f",
      "{connection_file}"
     ],
     "display_name": "Python 3",
     "language": "python"
    }
    

    In that file, I then changed the line /path/to/python by the python path I got when typing the following in Terminal:

    $ which python
    /Users/mymac/anaconda3/bin/python
    

    Relaunched Atom and it finally worked!

    The hints of the github page of jupyter helped also a lot!

    0 讨论(0)
  • 2021-01-27 10:49

    If you have multiple versions of python you should be using virtual environments. The version of python used from the terminal will depend on which virtual environment you have activated. Atom will use the same then. Activate which version of python you want and then run Atom.

    If you are using Anaconda then install conda environments. Its very simple if you using Anaconda. A few additional steps are required if you are not using it.

    The internet is littered with directions to create virtual environments.

    I created an environment named py27 for python 2.7. When I activate this environment it shows up on the cursor line like so:

    .

    If you don't see this your environment has not been activated. To activate on a Mac type source activate py27. I don't think you need the word source on a pc but I can't test that.

    0 讨论(0)
  • 2021-01-27 10:53

    You must have multiple (different versioned) Python interpreters on your computer. Open the Command Palette in Atom and choose "Python: Select Interpreter". Select the Python version you wish to use.

    0 讨论(0)
提交回复
热议问题