Wednesday, February 24, 2016

Neo4j and Python on Ubuntu

Isolation

Isolate your development environment with Vagrant and Ubuntu.

Initialize a vagrant machine by copying this Vagrantfile into a directory:
Vagrant.configure("2") do |config|
  config.vm.provision "shell", inline: "echo Initiate Provisioning ..."

  config.vm.box = "ubuntu/trusty64"
  config.vm.network "public_network", bridge: [ 'en0: Wi-Fi (AirPort)', 'en1: Thunderbolt 1', 'en2: Thunderbolt 2', 'bridge0' ]
  
  config.vm.synced_folder("scripts", "/home/vagrant/scripts")

  config.vm.provider "virtualbox" do |v|
    v.gui = false
    v.memory = "4096"
    v.customize ["modifyvm", :id, "--natdnshostresolver1", "on"]
    v.customize ["modifyvm", :id, "--natdnsproxy1", "on"]
  end

  config.vm.define "neo" do |neo|
    neo.vm.hostname = "neo"
    neo.vm.network "private_network", ip: "192.168.35.42"
    config.vm.network :forwarded_port, guest: 7474, host: 7474
  end

end


On the terminal, navigate to the directory with the Vagrantfile and type:
vagrant up && vagrant ssh

You may need to change the profiles in the section config.vm.network "public_network" to reference network adapters on your machine. You may also wish to change the IP address specified in this section neo.vm.network "private_network".


Prerequisites

Java must be installed first


Neo4j Installation

Installation:
$ sudo apt-get update -y

$ sudo su
$ wget -O - http://debian.neo4j.org/neotechnology.gpg.key | apt-key add -
$ echo 'deb http://debian.neo4j.org/repo stable/' > /etc/apt/sources.list.d/neo4j.list
$ exit

$ sudo apt-get update -y
$ sudo apt-get install -y neo4j
The digital ocean blog referenced below gives detail about each command.  Note that I was sudo su for the purpose of the first two commands.

Once the commands have been executed, Neo4J should be running.

Verify installation success with the following command:
vagrant@neo:~$ service neo4j status
 * neo4j is running


Also via the web browser at:
http://172.31.99.190:7474/browser/



Py2Neo with Twitter


Within a virtualenv, install py2neo.

The following works well as a template for simple py2neo interactions:
#!/usr/bin/env python 
# -*- coding: utf-8 -*- 

from py2neo import Graph, Path

graph = Graph('http://172.31.99.190:7474/db/data/')
tx = graph.cypher.begin()

# code goes here

tx.commit()


a populated graph



References

  1. [Digital Ocean] Installing Neo4j on Ubuntu
  2. [Py2Neo] Introduction to Py2Neo 2.0

No comments:

Post a Comment