gophernotes/README.md

197 lines
7.2 KiB
Markdown
Raw Normal View History

2016-01-23 14:19:24 -06:00
![alt tag](https://raw.githubusercontent.com/gophergala2016/gophernotes/master/files/gophernotes2.jpg)
2016-01-23 06:11:05 -06:00
# gophernotes - Go in Notebooks
2016-01-23 22:28:14 -06:00
`gophernotes` is a Go kernel for [Jupyter](http://jupyter.org/) notebooks. Finally, we can have a reliable and maintained way to use Go interactively and code in the browser. Use `gophernotes` to create and share documents that contain live Go code, equations, visualizations and explanatory text. These notebooks, with the live Go code, can then be shared with others via email, Dropbox, GitHub and the [Jupyter Notebook Viewer](http://nbviewer.jupyter.org/). Go forth and do data science, or anything else interesting, with go notebooks!
2016-01-23 14:24:34 -06:00
2016-02-15 15:53:45 -06:00
This project came out of the [Gopher Gala](http://gophergala.com/) 2016. It is inspired by a REPL called [gore](https://github.com/motemen/gore) and by a, no longer maintained and self-described as limited, ipython kernel call [iGo](https://github.com/takluyver/igo).
2016-01-23 06:12:06 -06:00
2016-01-23 17:12:57 -06:00
## Screenshots/Examples
2016-01-23 15:48:35 -06:00
2016-01-23 22:18:57 -06:00
### Simple interactive use:
2016-01-23 17:06:28 -06:00
2016-01-23 15:48:35 -06:00
![alt tag](https://raw.githubusercontent.com/gophergala2016/gophernotes/master/files/screencast.gif)
2016-01-23 17:12:57 -06:00
### Story telling and pattern recognition with Markdown and Golang:
2016-01-23 17:06:28 -06:00
![alt tag](https://raw.githubusercontent.com/gophergala2016/gophernotes/master/files/pr-screenshot.png)
2016-01-24 07:07:48 -06:00
### Example Notebooks (dowload and run them locally, follow the links to view in Github, or use the [Jupyter Notebook Viewer](http://nbviewer.jupyter.org/)):
2016-01-23 17:18:54 -06:00
- [Simple Printing and Channels](https://github.com/gophergala2016/gophernotes/blob/master/examples/Simple-Example.ipynb)
2016-01-23 16:59:40 -06:00
- [Pattern Recognition with Golearn](https://github.com/gophergala2016/gophernotes/blob/master/examples/Pattern-Recognition.ipynb)
2016-01-23 21:55:50 -06:00
- [Feed Forward, Recurrent Neural Nets](https://github.com/gophergala2016/gophernotes/blob/master/examples/Feed-Forward-Recurrent-NN.ipynb)
2016-01-23 20:18:18 -06:00
- [Time Parsing, Formatting](https://github.com/gophergala2016/gophernotes/blob/master/examples/Time-Formatting-Parsing.ipynb)
2016-01-23 20:44:05 -06:00
- [Stateful Goroutines](https://github.com/gophergala2016/gophernotes/blob/master/examples/Stateful-Goroutines.ipynb)
2016-01-24 07:06:36 -06:00
- [Worker Pools](https://github.com/gophergala2016/gophernotes/blob/master/examples/Worker-Pools.ipynb)
2016-01-23 15:51:10 -06:00
2016-03-01 10:50:07 -06:00
## Installation
2016-03-01 10:50:07 -06:00
### Docker
- Pull down and run the [latest image](https://hub.docker.com/r/dwhitena/gophernotes/):
```
docker pull dwhitena/gophernotes:latest
docker run --name gophernotes --net host -d dwhitena/gophernotes:latest
```
Possible issues:
- For OSX Docker Machine / Dlite users, you may need to set the IP to `0.0.0.0` instead of the default `localhost` with:
2016-03-01 10:52:08 -06:00
```
docker run --net host -d dwhitena/gophernotes jupyter notebook --ip=0.0.0.0
```
2016-03-01 10:50:07 -06:00
*Note* - this is a pretty large image, because it contains a full distribution of [Anaconda](http://docs.continuum.io/anaconda/index) plus the add ons of gophernotes. However, with this image, you can create Go notebooks, Python notebooks, text files, run ipython in the shell, etc.
### Local, Linux
2016-01-23 16:02:31 -06:00
2016-02-07 13:10:01 -06:00
- Dependencies:
2016-02-20 14:13:25 -06:00
- [Go](https://golang.org/) (Tested with Go 1.5 and 1.6)
2016-02-07 13:10:01 -06:00
- Jupyter (see [here](http://jupyter.readthedocs.org/en/latest/install.html) for more details on installing jupyter)
- ZeroMQ 2.2.X
2016-02-20 14:13:25 -06:00
- Create a workspace and setup your `GOPATH`, see https://golang.org/doc/code.html#GOPATH
2016-01-24 06:22:49 -06:00
- Install `goimports` if you haven't already:
```
go get golang.org/x/tools/cmd/goimports
```
2016-01-23 16:02:31 -06:00
- Get the kernel:
2016-01-23 16:03:49 -06:00
2016-01-23 16:02:31 -06:00
```
go get github.com/gophergala2016/gophernotes
```
2016-01-23 16:03:49 -06:00
2016-01-23 16:02:31 -06:00
- Create a directory for the new kernel config:
2016-01-23 16:03:49 -06:00
2016-01-23 16:02:31 -06:00
```
mkdir -p ~/.ipython/kernels/gophernotes
```
2016-01-23 16:09:45 -06:00
- Copy the kernel config into the `.ipython` directory:
```
cp -r $GOPATH/src/github.com/gophergala2016/gophernotes/kernel/* ~/.ipython/kernels/gophernotes
```
2016-03-01 10:50:07 -06:00
### Local, OSX
2016-03-01 10:50:07 -06:00
- Assuming you're running with `homebrew`, install go:
2016-03-01 10:50:07 -06:00
```
brew install go
mkdir ~/go
export GOPATH=$HOME/go
export PATH=$PATH:/usr/local/opt/go/libexec/bin:$GOPATH/bin
```
2016-03-01 10:50:07 -06:00
- You'll probably want to add the above exports to your `.bashrc` or equivalent.
2016-03-01 10:50:07 -06:00
- Install ZeroMQ:
2016-03-01 10:50:07 -06:00
```
brew tap homebrew/versions
brew install zeromq22
brew link --force zeromq22
```
2016-01-23 16:09:45 -06:00
2016-03-01 10:50:07 -06:00
- Install gophernotes:
2016-01-24 15:31:56 -06:00
```
2016-03-01 10:50:07 -06:00
go get golang.org/x/tools/cmd/goimports
go get github.com/gophergala2016/gophernotes
2016-01-24 15:31:56 -06:00
```
2016-03-01 10:50:07 -06:00
- Copy the kernel config:
2016-01-24 15:31:56 -06:00
2016-03-01 10:50:07 -06:00
```
mkdir -p ~/.ipython/kernels/gophernotes
cp -r $GOPATH/src/github.com/gophergala2016/gophernotes/kernel/* ~/.ipython/kernels/gophernotes
```
2016-02-10 14:31:34 -06:00
2016-03-01 10:50:07 -06:00
- Update `~/.ipython/kernels/gophernotes/kernel.json` with the path to your $GOPATH installation. If you used the path above, your file will look like:
2016-02-10 14:31:34 -06:00
2016-03-01 10:50:07 -06:00
```
{
"argv": [
"/Users/<your username>/go/bin/gophernotes",
"{connection_file}"
],
"display_name": "Golang",
"language": "go",
"name": "go"
}
```
2016-01-24 17:24:18 -06:00
## Getting Started
- Start the jupyter notebook:
```
jupyter notebook
```
- Select `Golang` from the `New` drop down menu.
The gophernotes repo includes some sample notebooks.
If you start your Jupyter server in a parent directory of your $GOPATH, you can find these in
$GOPATH/src/github.com/gophergala2016/gophernotes/examples in the Jupyter interface.
You can also clone the gophernotes repo into a subdirectory that will be visible from the notebook interface.
- Have Fun!
## Troubleshooting
### gophernotes not found
- Depending on your environment, you may need to manually change the path to the `gophernotes` executable in `kernel/kernel.json` before copying it to `~/.ipython/kernels/gophernotes`. You can put the **full path** to the `gophernotes` executable here, and you shouldn't have any further issues.
### "Kernel error" in a running notebook
```
Traceback (most recent call last):
File "/usr/local/lib/python2.7/site-packages/notebook/base/handlers.py", line 458, in wrapper
result = yield gen.maybe_future(method(self, *args, **kwargs))
File "/usr/local/lib/python2.7/site-packages/tornado/gen.py", line 1008, in run
value = future.result()
...
File "/usr/local/Cellar/python/2.7.11/Frameworks/Python.framework/Versions/2.7/lib/python2.7/subprocess.py", line 1335, in _execute_child
raise child_exception
OSError: [Errno 2] No such file or directory
```
Stop jupyter, if it's already running.
Add a symlink to `/go/bin/gophernotes` from your path to the gophernotes executable. If you followed the instructions above, this will be:
```
sudo ln -s $HOME/go/bin/gophernotes /go/bin/gophernotes
```
Restart jupyter, and you should now be up and running.
2016-01-24 15:31:56 -06:00
## Custom Commands
2016-01-24 17:26:46 -06:00
Some of the custom commands from the [gore](https://github.com/motemen/gore) REPL have carried over to `gophernotes`. Note, in particular, the syntax for importing packages:
2016-01-23 18:07:24 -06:00
```
:import <package path> Import package
2016-02-15 15:53:45 -06:00
:print Show current source (currently prints to the terminal where the notebook server is running)
2016-01-23 18:07:24 -06:00
:write [<filename>] Write out current source to file
:help List commands
:containerize Build a Docker image that executes the compiled Go code (must have Docker installed)
2016-01-23 18:07:24 -06:00
```
2016-01-24 14:42:24 -06:00
## Licenses
2016-01-24 14:21:26 -06:00
2016-01-24 14:27:41 -06:00
`gophernotes` was created by [Daniel Whitenack](http://www.datadan.io/), and is licensed under an [MIT-style License](License.md).
2016-01-24 14:42:24 -06:00
The Golang Gopher image was created by [Takuya Ueda](http://u.hinoichi.net) and is licensed under the Creative Commons 3.0 Attributions license.