PyCharm, Vagrant, Fabric & Anaconda

Installing the whole development toolchain for Colour roughly means deploying:

I decided to see how I could make that setup a bit more portable and easier to deploy.

That's where Vagrant kicks in along PyCharm and Anaconda!

The following guide assume that you have that you have PyCharm installed and are using macOs, although it should pretty much be platform agnostic.

Development Workspace Creation

  • On your local filesystem, in your development workspace, create a directory colour-science and cd into it:
mkdir colour-science
cd colour-science
git clone git://github.com/colour-science/colour-vagrant.git
  • You should now have a colour-vagrant directory nested into the colour-science one.

    Let's open the colour-vagrant directory into PyCharm.

Vagrant Installation

We will loosely follow Jetbrain's PyCharm Documentation.

Note

Fabric does not support Python 3 yet thus if you want to use Python 3 you will need to switch to the fork.
  • Install XQuartz: This is the X11 display server for macOs. The virtual machine will export the display to it so that you can see the figures from Matplotlib.

  • VirtualBox directories syncing performance degrades quickly with large number of files.

    As a result the directories syncing is done with NFS.

    You will however be asked for your macOs password at each virtual machine spin up because Vagrant needs to modify configuration files on the macOs host.

    In order to avoid that and following the Vagrant Documentation, you can edit your macOs /etc/sudoers file and append the following content:

    Cmnd_Alias VAGRANT_EXPORTS_ADD = /usr/bin/tee -a /etc/exports
    Cmnd_Alias VAGRANT_NFSD = /sbin/nfsd restart
    Cmnd_Alias VAGRANT_EXPORTS_REMOVE = /usr/bin/sed -E -e /*/ d -ibak /etc/exports
    %admin ALL=(root) NOPASSWD: VAGRANT_EXPORTS_ADD, VAGRANT_NFSD, VAGRANT_EXPORTS_REMOVE
    

PyCharm Vagrant Configuration

The canonical way is to use Vagrant from the command line as described in Vagrant Documentation, but here we will leverage the PyCharm integration.

  • Set the Vagrant Executable field to your Vagrant executable, e.g. /usr/local/bin/vagrant. This should not be needed as vagrant should be enough, but I encountered issues lately.
  • Set the Instance Folder field to your colour-vagrant directory.
  • Add a new Vagrant box to PyCharm in the Boxes tab and use the following image: bento/ubuntu-16.04
  • Add the vagrant-fabric plugin to PyCharm in the Plugins tab.

Your configuration screen should be approximately as follows:

/images/Blog_PyCharm_Vagrant_001.png/images/Blog_PyCharm_Vagrant_002.png

Vagrant Up

With everything setup, hit the PyCharm ---> Tools ---> Vagrant ---> Up menu item to spin up the virtual machine.

You can go grab a coffee, the initial provisioning will take roughly 25-30 minutes.

If the provisioning ended smoothly, you should have the following elements available:

  • colour, colour-notebooks and colour-science.org repositories cloned into the colour-science directory right next to the colour-vagrant one.
  • Remote Python environments installed into the virtual machine at the following location with all the dependencies needed:
vagrant@vagrant:~$ cd /home/vagrant/miniconda/envs/
vagrant@vagrant:~/miniconda/envs$ ll
total 16
drwxrwxr-x  4 vagrant vagrant 4096 Apr 29 03:12 ./
drwxrwxr-x 13 vagrant vagrant 4096 Apr 29 03:02 ../
drwxrwxr-x 20 vagrant vagrant 4096 Apr 29 03:09 python2.7/
drwxrwxr-x 20 vagrant vagrant 4096 Apr 29 03:30 python3.5/
  • The colour-science.org website served from the virtual machine at the following address: http://localhost:8080/

PyCharm Environment Configuration

  • Add the various remote Python interpreters to PyCharm following the quickstart guide: Remote interpreter via virtual box: 2

    The remote Python interpreters paths are as follows:

    • /home/vagrant/miniconda/envs/python2.7/bin/python
    • /home/vagrant/miniconda/envs/python3.5/bin/python
  • Add the paths mappings from the macOs host to the virtual machine in the Defaults configurations, in my case the mappings are as follows:

    /Users/KelSolaar/Documents/Developement/colour-science = /colour-science

Your Run/Debug configuration screen should be approximately looking like that:

/images/Blog_PyCharm_Configurations_001.png/images/Blog_PyCharm_Configurations_002.png

Usage

SSH Connection & Display

Accessing the virtual machine is done by using PyCharm ---> Tools Start SSH session... menu item.

However if you want to be able to export the display and see the figures you will have to manually ssh into the virtual machine:

ssh -X vagrant@192.168.32.64

Password is vagrant.

You will also need to add the virtual machine to the X11 hosts by issuing the following command on the macOs host:

xhost + 192.168.32.64

Jupyter Notebooks

The Jupyter Notebooks server is started as follows:

cd /colour-science/colour-notebooks/notebooks
ipython notebook --pylab=inline --ip=0.0.0.0

Then you can access it on the macOs host at the following url: http://localhost:8888/

Remote Python Environments & Interpreters

You can activate the remote Python environments in the virtual machine by issuing those commands:

For python2.7:

source activate python2.7

For python3.5:

source activate python3.5

Comments

Comments powered by Disqus