Python blpapi on Mac OS

To install blpapi library for python on Mac OS, first download the C++ sdk from bloomberg.

Then unpack the tarball to a path you prefer. Take /usr/local for example:

1
2
3
4
cd /usr/local
sudo tar xfv ~/Downloads/blpapi_cpp_3.15.0.1-macos.tar.gz
# create a symlink to make future updates a bit easier
sudo ln -s blpapi_cpp_3.15.0.1 blpapi

Next, try installing blpapi for python with pip, with env variable BLPAPI_ROOT pointing to the C++ sdk's path.

1
BLPAPI_ROOT=/usr/local/blpapi pip install --index-url=https://bloomberg.bintray.com/pip/simple --upgrade blpapi

If you have the lastest xcode CLT installed, you might see a compiler error though:

1
2
3
4
blpapi/internals_wrap.c:20050:19: error: implicit declaration of function 'blpapi_ZfpUtil_getOptionsForLeasedLines' is invalid in C99
[-Werror,-Wimplicit-function-declaration]
result = (int)blpapi_ZfpUtil_getOptionsForLeasedLines(arg1,(struct blpapi_TlsOptions const *)arg2,arg3);
^

In this case, you have to fix the error first, goto bintray and download the python source tarball, then unpack it.

1
2
3
4
cd ~/Downloads
wget https://bloomberg.bintray.com/pip/simple/blpapi/blpapi-3.15.2.tar.gz
tar xfv blpapi-3.15.2.tar.gz
cd blpapi-3.15.2

A quick search in the C++ sdk shows that the header file that defines the function in question is not included, just open blpapi/internals_wrap.c in the python source directory and add a line to include the header file will fix the error.

1
#include "blpapi_zfputil.h"

Then proceed to install:

1
python setup.py install

That should be it! For much older versions I had to modify the generated _internal.so using install_name_tool -change to help locate libblpapi3.so, which was not as pleasant an experience. Fortunately the newer versions have fixed the issue. It's worth mentioning that the installation on Linux is basically the same, with only one additional step to help locate libblpapi3.so, either by copying the file to /lib/ or add the path of C++ sdk to ld.so.conf.

Hope this helps.