Connecting Kivy with Anaconda (OSX) - uclatommy/kivy GitHub Wiki

Anaconda is a versatile tool for managing python packages, particularly those with scientific applications such as numpy, scipy, astropy, and scikit-learn. However, Anaconda comes with its own python distribution, and it's complicated to directly install Kivy into an Anaconda distribution.

However, using a method similar to the kivy shell script, we can bootstrap the kivy environment variables into an Anaconda environment pretty easily.

  • Follow the Anaconda install instructions for Mac OSX to install Anaconda, if you haven't done so already. Also make sure you have kivy installed (preferably via Kivy.app), of course.

  • Create a new conda environment, specifying Cython v0.21 (since kivy doesn't support >0.21). Also install any other packages you want into that environment, or get the whole shebang with anaconda itself:

    $ conda create -n kivy anaconda cython=0.21

  • Now, create a bootstrapping script in the same directory as the original kivy shell script. I called mine kivyconda, and simply duplicated then edited the script:

    $ cp /Applications/Kivy.app/Contents/Resources/script /Applications/Kivy.app/Contents/Resources/kivyconda
    $ vi /Applications/Kivy.app/Contents/Resources/kivyconda
    

    You want the final product to look something like this:

#!/bin/bash
SCRIPT_PATH="${BASH_SOURCE[0]}";
if([ -h "${SCRIPT_PATH}" ]) then
  while([ -h "${SCRIPT_PATH}" ]) do SCRIPT_PATH=`readlink "${SCRIPT_PATH}"`; done
fi
SCRIPT_PATH=$(python -c "import os; print os.path.realpath(os.path.dirname('${SCRIPT_PATH}'))")

# setup the environment to not mess with the system
export PYTHONPATH="${SCRIPT_PATH}/kivy:${PYTHONPATH}"
export DYLD_FALLBACK_LIBRARY_PATH="${SCRIPT_PATH}/lib"
export LD_PRELOAD_PATH="${SCRIPT_PATH}/lib"
export GST_REGISTRY="${SCRIPT_PATH}/gst.registry"
export GST_PLUGIN_SCANNER="${SCRIPT_PATH}/gst-plugin-scanner"
export GTK_PATH="${SCRIPT_PATH}/../Frameworks/GStreamer.framework/Versions/Current"
export GST_PLUGIN_SYSTEM_PATH="${SCRIPT_PATH}/../Frameworks/GStreamer.framework/Versions/Current/lib/gstreamer-1.0"
export GIO_EXTRA_MODULES="${SCRIPT_PATH}/../Frameworks/GStreamer.framework/Versions/Current/lib/gio/modules"
export KIVY_HOME="${SCRIPT_PATH}/.kivy"

# activate the conda environment
source activate kivy

if [ $# -ne 0 ]; then
	exec python "$@"
else
	exec python
fi
  • Finally, symlink your new script into /usr/local/bin, right next to the other kivy script:

     $ ln -s /Applications/Kivy.app/Contents/Resources/kivyconda /usr/local/bin/kivyconda
    

Now, from the command line, just do $ kivyconda in place of kivy, and you're all set.