Jupyter Notebooks

Adding kernel for Hydrogen in Atom

  1. Install the ipykernel in your virtual environment: pipenv install ipykernel

  2. Start shell with: pipenv shell

  3. Set name so Atom Hydrogen can recognize: pipenv run python -m ipykernel install --user --name=name-of-kernel

  4. Start Atom (from within pipenv shell) and when you run code (control-enter), Atom should list python kernels to use (including name-of-kernel)

Installing Modules

# Install a pip package in the current Jupyter kernel
import sys
!{sys.executable} -m pip install scipy

the last word is the name of the module to install

Capturing Output to File

You can use %%capture Jupyter notebook's magic command to catch output of cell and then paste it to your text file with

with open('output.txt', 'w') as out:
   out.write(cap.stdout)

if you want to cell code to specific file for example.txt you can use magic function %%writefile

%%writefile example.txt
ab = 'This is code'
a = 5
print(a+ 2)

Also if you want to append to file you must use -a parameter


Last updated