Skip to content

Instantly share code, notes, and snippets.

@wonderbeyond
Last active December 4, 2020 18:50
Show Gist options
  • Save wonderbeyond/826894a66aa11a828fb68a8a08020e4c to your computer and use it in GitHub Desktop.
Save wonderbeyond/826894a66aa11a828fb68a8a08020e4c to your computer and use it in GitHub Desktop.
Install RDKit with non-standard python location, visible from a virtualenv.

Install RDKit

Reference: http://www.rdkit.org/docs/Install.html#building-from-source

Download & build (with a non-standard python installation)

$ sudo apt-get install build-essential cmake libboost-all-dev

# NOTE: don't use a temporary dir, since we'll reference `$RDBASE` afterwards.
$ wget https://github.com/rdkit/rdkit/archive/Release_2018_03_2.tar.gz
$ tar -xvzf Release_2018_03_2.tar.gz
$ cd rdkit-Release_2018_03_2
$ export RDBASE=`pwd`  #  the root directory of the RDKit distribution

$ PYTHON_PREFIX=~/.pyenv/versions/some-env  # bind to target python environment
$ mkdir build && cd build
$ cmake -D PYTHON_LIBRARY=$PYTHON_PREFIX/lib/python2.7/config/libpython2.7.a \
        -D PYTHON_INCLUDE_DIR=$PYTHON_PREFIX/include/python2.7 \
        -D PYTHON_EXECUTABLE=$PYTHON_PREFIX/bin/python2.7 \
        -D RDK_BUILD_INCHI_SUPPORT=ON \
        ..

$ make -j4
$ make install  # copy things to "$RDBASE/lib"

Make rdkit's dynamic libs findable:

# for temporary
$ export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$RDBASE/lib

# or for permanent
$ echo $RDBASE/lib | sudo tee /etc/ld.so.conf.d/rdkit.conf
$ sudo ldconfig

Copy/Link python packages into virtualenv:

$ ln -s $RDBASE/rdkit $PYTHON_PREFIX/lib/python2.7/site-packages/

Test whether installed OK

$ $PYTHON_PREFIX/bin/python
>>> from rdkit import Chem
>>> from rdkit.Chem import rdinchi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment