Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Setting up Hydrogen and Atom with Anaconda on Windows

I would like to run python interactively in ATOM using the Hydrogen package. I am on Windows 10. I would like to be able to initiate an ATOM session by double-clicking the ATOM icon in my toolbar or double-clicking a .py file and not have to resort to initiating ATOM via the command line. I have installed Python 3.8 via the Anaconda distribution. I have used pip install to install the ipykernel.

I get a series of Traceback errors which seems to be common;

Traceback (most recent call last): File "C:\Users\BRB\anaconda3\lib\runpy.py", line 194, in _run_module_as_main return _run_code(code, main_globals, None, File "C:\Users\BRB\anaconda3\lib\runpy.py", line 87, in _run_code exec(code, run_globals) File "C:\Users\BRB\anaconda3\lib\site-packages\ipykernel_launcher.py", line 15, in from ipykernel import kernelapp as app File "C:\Users\BRB\anaconda3\lib\site-packages\ipykernel__init__.py", line 2, in from .connect import File "C:\Users\BRB\anaconda3\lib\site-packages\ipykernel\connect.py", line 18, in import jupyter_client File "C:\Users\BRB\anaconda3\lib\site-packages\jupyter_client__init__.py", line 4, in from .connect import File "C:\Users\BRB\anaconda3\lib\site-packages\jupyter_client\connect.py", line 21, in import zmq File "C:\Users\BRB\anaconda3\lib\site-packages\zmq__init__.py", line 47, in from zmq import backend File "C:\Users\BRB\anaconda3\lib\site-packages\zmq\backend__init__.py", line 40, in reraise(*exc_info) File "C:\Users\BRB\anaconda3\lib\site-packages\zmq\utils\sixcerpt.py", line 34, in reraise raise value File "C:\Users\BRB\anaconda3\lib\site-packages\zmq\backend__init__.py", line 27, in _ns = select_backend(first) File "C:\Users\BRB\anaconda3\lib\site-packages\zmq\backend\select.py", line 28, in select_backend mod = import(name, fromlist=public_api) File "C:\Users\BRB\anaconda3\lib\site-packages\zmq\backend\cython__init__.py", line 6, in from . import (constants, error, message, context, ImportError: DLL load failed while importing error: The specified module could not be found.

Things I have tried:

  1. I first added the Python3 executable to the system PATH (against the advice of Anaconda). This does work if I initiate ATOM via the command line, but if I double-click the ATOM icon or .py file, I get the usual traceback errors.

This answer https://discuss.atom.io/t/solved-how-to-use-the-hydrogen-package/30190 says it was a problem with Atom on macOS machines on older versions of Atom but has since been corrected for macOS. The answer was 4 years ago, so I assume it has been corrected for Windows, but I cannot find a soltion.

  1. This answer Setting up Hydrogen and Atom with Anaconda managing python installation says to (A) run:

    conda activate myenv python -m ipykernel install --user

and (B) clean up the PATH.

I did do both of these things. Removing the Python3 executable from PATH was a step backwards. Now it doesn't work even from the command line. I also don't understand why this is even bad in the first place...

  1. This guy Atom: Setting up Hydrogen Launcher for use with Python 3.7 has the same problems. But no solution.

Can someone point me in the right direction?

I am relatively new so would prefer not to complicate things by setting up multiple virtual environments etc at this stage (I don't yet have a need and I want simple).

like image 687
brb Avatar asked Nov 06 '20 09:11

brb


People also ask

Can I use Atom with anaconda?

' platformio will execute this command every time you start Atom, and it will use the default anaconda python, as specified in the new PATH. You can then type "conda activate myenvironment" in the platformio terminal and it will work like normal (switch between environments, install packages, etc.). Hope this helps.

How do you set up hydrogen Atom?

In Atom, go to Settings ( Ctrl+Comma ) and in the Install pane look for hydrogen and install it. If you hit Ctrl+Enter in any line, Hydrogen should evaluate it in the appropriate kernel (Python, in this case) and output the result inline.

What is the difference between anaconda and Atom?

Anaconda is a way to distribute Python, where Jupyter and Atom are ways to interact with a python interpreter.

What is anaconda window?

Anaconda is an open-source software that contains Jupyter, spyder, etc that are used for large data processing, data analytics, heavy scientific computing. Anaconda works for R and python programming language. Spyder(sub-application of Anaconda) is used for python.


Video Answer


1 Answers

I use Atom + Hydrogen extensively. And it is works which whatever python version and if it uses Anaconda, Miniconda, or simply python. Please do not mess with the system environment PATH.

Maybe you are confused about which python executable is which. Or, is Atom.exe and Hydrogen using the same version, same path, of python executable?

Atom thingy

I am sure that Atom.exe uses the default python version that exists system-wide or a virtual environment. If you run Atom.exe without a virtual environment from the terminal, or simply double click the icon from the desktop, Atom.exe will use python available in the system.

But if you run Atom.exe from a virtual environment-activated terminal/cmd, then Atom.exe will use python that is available in the virtual environment.

Why does it matters? If you use an Atom.exe package, for example, python-import-magic, Atom.exe will ask you for a python package named isort. If you installed isort in a virtual environment named work, Atom.exe will always tell you that isort is not available, unless you start Atom.exe from the work virtual environment.

Then, should I start Atom.exe from a virtual environment-activated terminal? I think that is not a good idea.

Hydrogen thingy

It doesn't matter how many pythons are installed or virtual environments are created, Hydrogen will use installed/registered kernels of python executables. For example, I installed several python versions (Yup, sorry I don't use pipenv) that located in:

  • python37 in D:\python\python37\python.exe
  • python38 in D:\python\python38\python.exe

And then I want to use Hydrogen with a kernel that uses python37, I should install the kernel once with:

D:\python\python37\python.exe -m ipykernel install --name "python37_something"

or if I need python38

D:\python\python38\python.exe -m ipykernel install --name "python38_something"

or I just want to install a kernel with whatever python is available system-wide:

python.exe -m ipykernel install --name "python_for_the_win"

After that, the installed kernel will appear in the Hydrogen (or even Jupyter Notebook/Lab) kernel selection. Screenshot below.

But how if I use a virtual environment? Just switch to the virtual environment and install the kernel. For example, if I want to use a virtual environment named work with Hydrogen, I should activate the virtual environment and install the kernel once for the first time:

workon work
python -m ipykernel install --name "work_venv"

or if you are using conda:

conda activate work
python -m ipykernel install --name "work_env"

The work virtual environment will appear in Hydrogen kernel selection. Here is my installed kernels as an example:

enter image description here

The important thing is, you should name the installed ipykernel with a --name argument and then choose a more meaningful name, such as work, flask development or anything you like, but not python or python3. The --user argument depends on your needs.

Why can't I use 'python' or 'python3' as a kernel name?

If you insist to run:

python -m ipykernel install --name "python"

or

python -m ipykernel install --name "python3"

or even the instruction from official nteract page:

python -m ipykernel install

from the virtual environment or not, the kernel will be installed, but the location of the kernel will be different depending on the virtual environment or system python path. Please take a look at my screenshots.

enter image description here

The terminal in the back is without activating a virtual environment and the terminal in the front is using a virtual environment named work. When I run jupyter kernelspec list from both terminals, all the installed kernels are listed, and the file paths to them are the same on both terminals. Except for the python3, I do not know why, but it seems that python or python3 is a default name for ipykernels kernel and also when installing a kernel without a name.

And you cannot choose which python3 to run from Atom+Hydrogen without, MAYBE, running atom.exe from virtual environment activated terminal.

Bonus

You may notice that in my last screenshot above, 'domainopsy' and 'javascript' are installed in C:\Users\faruq directory, it seems because I passed --user when I installed the kernel, while 'gym' and 'work' are not. I think, 'domainopsy' and 'javascript' are not accessible if I log in with another username.

Please pardon my English, and this writing is based on my experience, so please correct me if I am wrong.

like image 197
Sandi Avatar answered Oct 10 '22 03:10

Sandi