OpenCV with Python3 for Vagrant

Dec 22, 2016

OpenCV from sources, with Python3 bindings, provisioned on a vagrant machine

I wanted to run OpenCV from the latest sources, with python3 bindings, on macos. I decided to use an ubuntu virtual machine, provisioned by Vagrant.
You can install vagrant and virtualbox easily by using brew

1 brew cask install virtualbox
2 brew cask install vagrant

Next step is to simply clone my project containing the Vagrantfile and the script for the provisioning.

1 git clone

Once in the opencv-vagrant directory, you can spin the virtual box with

1 vagrant up

This command will initialise the machine and run the provisioning script; which in turn will install all the dependencies, OpenCV from the latest sources, and configure a virtualenv with jupyter. It will take some time.

When the provisioning script will be over, you can access the box with

1 vagrant ssh

Once in the box shell, you can activate the virtualenv enviroment named cv and run jupyter

1 # commands to be issued within the virtual box
2 cd /vagrant/notebooks
3 workon cv
4 jupyter notebook


At this point you can direct your (host) browser to http://localhost:8888, leave empty the password field and access a demo notebook.


One more thing: if you want to update all the packages installed and OpenCV itself, it is a matter to start the virtual box and forcing the provisioning again, by using the command:

1 vagrant up --provision