A Docker container running NixOS with a Nix Shell

Development Environment

A Docker container running NixOS with a Nix Shell

Python 3.7 Interpreter:

docker run --rm --volumes-from=nix -it nixos/nix nix-shell -p python37Packages.pandas --run python3

Python 3.7 JupyterLab NixOs Container

  1. cd into your working project directory.
  2. mkdir .config && touch .config/python.nix
  3. Copy the contents of the Gist below to clip board.
    1. Linux: xclip -o > .config/python.nix
    2. Mac: pbpaste > .config/python.nix
  4. Build your NixOs Docker container with:
    docker run --rm --volumes-from=nix -it -v=$(pwd):/mnt -w=/mnt -e JUPYTER_ENABLE_LAB=yes -e HOME=/mnt -p=8080:8080 nixos/nix nix-shell /mnt/.config/python.nix
    
  5. GitHub Gist

Debugging

Testing

Code Snippets

Notebook Install Python Packages (Pip)

# Install python packages for a notebook.
import sys
from IPython.display import display_html

def restartkernel():
    display_html("<script>Jupyter.notebook.kernel.restart()</script>",raw=True)

!{sys.executable} -m pip install --user pymongo pyrogram tgcrypto voila
#!{sys.executable} -m pip install --user -r requirements.txt
# !{sys.executable} -m pip install --user plotly
# restartkernel()

# Used to display output generated by python code.
from IPython.display import display, Markdown, Latex

# Database connection tools.
mongo_client = pymongo.MongoClient("mongodb://mongo-mule:27017/")
db = mongo_client.<db_name>

Notebook install Python Package from GitHub

$ pip install git+https://github.com/heathdrobertson/toilethill_py.git

Numpy Save to CSV Text File

import numpy as np


x = np.arange(0.0,5.0,1.0)
np.savetxt('test.out', x, delimiter=',')

Reference