Reputation: 5459
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 python3
instead)
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
Upvotes: 0
Views: 1036
Reputation: 5459
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!
Upvotes: 0
Reputation: 4827
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.
Upvotes: 1
Reputation: 986
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.
Upvotes: 2