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

旧巷老猫 提交于 2019-11-28 14:47:23

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.

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.

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!

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!