Skip to content

Instantly share code, notes, and snippets.

@sorig
Last active January 29, 2018 12:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sorig/24a36347dd97cbd626593d6410199014 to your computer and use it in GitHub Desktop.
Save sorig/24a36347dd97cbd626593d6410199014 to your computer and use it in GitHub Desktop.

Installing Shogun into a Python virtualenv

This uses ccmake. Vanilla cmake can also be used

  • Activate your virtualenv: source /path/to/env/bin/activate

  • Run ccmake configure as usual:

cd path/to/shogun
mkdir build
cd build
ccmake ..

Press c to configure

  • In ccmake set CMAKE_INSTALL_PREFIX to point to your virtual environment: /path/to/env/local

  • Turn PythonModular ON and hit configure again

  • Make sure the PYTHON_EXECUTABLE is pointing to the right python (press t in ccmake to see all options). I.e. /path/to/env/bin/python

    • ON macOS: cmake may have trouble finding the right PYTHON_LIBRARY and PYTHON_INCLUDE_DIR. You may therefore have to set them manually.
    • Make sure that PYTHON_INCLUDE_DIR points to your virtualenv, e.g. /path/to/env/include/python2.7.
    • Make sure that PYTHON_LIBRARY points to the libpythonX.Y.dylib corresponding to the python that your virtualenv was set up with (either the default virtualenv python or the python supplied with virtualenv --python=/path/to/python). You can check what the default python is by running virtualenv --help - it will be listed in the description of the --python= flag. Once you have established where the correct python is located, make sure that PYTHON_LIBRARY points to the corresponding libpythonX.Y.dylib, e.g. /usr/local/opt/python/Frameworks/Python.framework/Versions/2.7/lib/libpython2.7.dylib.
  • Now press g to generate and run make install

  • If this goes well, you now need to configure the $LD_LIBRARY_PATH (on macOS $DYLD_LIBRARY_PATH) environment variable to be configured correctly when you activate the virtual environment. This can be done by modifying the activate script of your virtual environment. Change /path/to/env/bin/activate file to include the following:

...

deactivate () {

    ... 

    if [ -z "$_OLD_LD_LIBRARY_PATH" ] ; then
        export LD_LIBRARY_PATH="$_OLD_LD_LIBRARY_PATH"
        unset _OLD_LD_LIBRARY_PATH
    fi

    ...
}

...

_OLD_LD_LIBRARY_PATH="$LD_LIBRARY_PATH"
export LD_LIBRARY_PATH=/path/to/env/local/lib

...
  • Now deactivate your virtual environment and re-activate it. Test that it is working by running import modshogun in Python.

    • If you get the error ImportError: libshogun.so.17: cannot open shared object file: No such file or directory, then try sudo ldconfig

Using the installation to compile C++ shogun programs

g++ -I /path/to/virtualenv/local -lshogun examples/meta/cpp/binary/kernel_support_vector_machine.cpp -std=c++14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment