0

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 from the terminal but that I cannot call from Atom. Here are the details:

When calling python from the terminal, I get version 3.7.1

$ python
Python 3.7.1 | packaged by conda-forge | (default, Nov 13 2018, 09:50:42) 
[Clang 9.0.0 (clang-900.0.37)] :: Anaconda custom (64-bit) on darwin

(I get exactly the same if I type python3instead)

Now when looking at the python version from Atom i get version 3.6.5 with

>>> import sys
>>> print(sys.version
3.6.5 | packaged by conda-forge | (default, Apr  6 2018, 13:44:09) 
[GCC 4.2.1 Compatible Apple LLVM 6.1.0 (clang-602.0.53)]

how come? how can I make Atom get the same version as the version the Terminal is getting?

Failed attempts

Looking at the PATH with the command import sys and then print(sys.path) here is what I get:

From Atom:

['', '/anaconda3/lib/python36.zip', '/anaconda3/lib/python3.6', 
'/anaconda3/lib/python3.6/lib-dynload', '/anaconda3/lib/python3.6/site-packages',
'/anaconda3/lib/python3.6/site-packages/aeosa', '/anaconda3/lib/python3.6/site-packages/cycler-0.10.0-py3.6.egg', 
'/anaconda3/lib/python3.6/site-packages/IPython/extensions', '/Users/mymac/.ipython']

From the Terminal:

['', '/Users/mymac/anaconda3/lib/python37.zip', 
'/Users/mymac/anaconda3/lib/python3.7', 
'/Users/mymac/anaconda3/lib/python3.7/lib-dynload', 
'/Users/mymac/anaconda3/lib/python3.7/site-packages', 
'/Users/mymac/anaconda3/lib/python3.7/site-packages/aeosa']

It seems Atom is using the version of Python of pyenv given the following command and output:

$ pyenv versions
* system (set by /Users/mymac/.pyenv/version)
  3.6.5

according to the github page of pyenv. I entered pyenv virtualenv 3.7.1. Then when entering $ pyenv versions at least the version 3.7.1 was in the list:

* system (set by /Users/mymac/.pyenv/version)
  3.6.5
  3.7.1

But that didn't solve the problem with Atom

I then visited the conda page aboute managing environment and ran the following commands:

$ conda create --name myenv

It ran without problem, but the problem persists

I then tried to run more specifically $ conda create -n myenv python=3.7.1 but got: CondaValueError: prefix already exists: /Users/mymac/anaconda3/envs/myenv

As pointed by @jmh Then I tried: $ source activate 3.7.1 and got the following prompt: (3.7.1) user:~ user$

I could successfully choose the correct the correct virtualenv. But then upon opening Atom the problem persisted

ecjb
  • 5,169
  • 12
  • 43
  • 79

3 Answers3

2

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.

RealPawPaw
  • 988
  • 5
  • 9
  • Many thanks for your comment @RealPawPaw. I tried to look for what you pointed to but couldn't find it. I added the screenshots of what I'm seeing in `Atom`. It's probably very silly but what am I doing wrong? – ecjb Dec 18 '18 at 11:12
1

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:

enter image description here.

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.

Natsfan
  • 4,093
  • 3
  • 22
  • 29
  • Many thanks for your comment @jmh, I tried to look at the documentation for virtual environments, and wrote the corresponding websites that I visited as welle as the different commands that I tried, but I still couldn't resolve the problem. do you have any other hints? – ecjb Dec 18 '18 at 17:01
  • i did add a few more comments to my answer? If that doesn't help, let me know. After you activate a virtual environment does it leave you any messages? Do all this from same terminal window. I have time to help you if this doesn't work. – Natsfan Dec 18 '18 at 17:42
  • Are you using a Mac or PC? – Natsfan Dec 18 '18 at 17:43
  • many thanks for your time @jmh. I also updated my question accordingly. I could successfully choose the correct the correct virtualenv. But then upon opening `Atom` the problem persisted – ecjb Dec 18 '18 at 17:58
  • i'll have to think on this. I just tried again and it works fine for me.. i'll get back to you when/if I can come up with something... – Natsfan Dec 18 '18 at 18:28
  • It maybe not have to do with the virtualenv but rather with the installed jupyter kernel installed: https://stackoverflow.com/questions/28831854/how-do-i-add-python3-kernel-to-jupyter-ipython – ecjb Dec 18 '18 at 18:43
0

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!

ecjb
  • 5,169
  • 12
  • 43
  • 79
  • Alright! Good catch! I was so focused on virtual environments that is all I thought about! Glad you got it fixed, Sorry if I lead you down a dead end. – Natsfan Dec 18 '18 at 20:06