When importing Bloomberg’s blpapi
package using PyXLL, you may encounter the following error:
ImportError: No module named '_internals'
Mismatch between C++ and Python SDK libraries.
Python SDK version 3.12.1
Found C++ SDK version 3.11.6.1
Download and install the latest C++ SDK from:
http://www.bloomberg.com/professional/api-library
This is because both the Bloomberg Python API and the Bloomberg Excel Add-In are loading the same Bloomberg C++ SDK, but they require different versions.
The recommendation from Bloomberg is to install the same version of the Bloomberg SDK as the Bloomberg Python API so there is no version conflict.
You can find the relevant downloads and install instructions for the Bloomberg SDK and Python API on Bloomberg's website here http://www.bloomberg.com/professional/api-library.
To download a specific version of the Bloomberg Python API you can use the command:
pip install "blpapi==<version>" --index-url=https://bcms.bloomberg.com/pip/simple/
For more help with this error please contact Bloomberg Support.
Alternative Suggestions
Prior to Bloomberg addressing this issue with the advice above, the following workarounds were recommended. If you are not able to follow the recommendation above, and Bloomberg Support are not able to help you, these following suggestions may help but where possible the advice is to update both the Bloomberg SDK and Python API to the same version as outlined above.
- Download a fork of blpapi with a fix for this problem
- Build the Bloomberg Python API with the matching C++ SDK
Download a fork of blpapi with a workaround for this problem
As this is a common problem, we have put a fork of Bloomberg’s Python API on github that builds the Python Bloomberg package in such a way as to not share the same DLL as the Excel add-in.
You can either build it from source, or use one of the pre-built releases.
To install one of the pre-built releases:
-
Download the latest .whl file for your version of Python from https://github.com/pyxll/blpapi-python/releases.
-
Uninstall any previous version by running:
pip uninstall blpapi
If you are using Anaconda, also run
conda uninstall blpapi
. -
Install the .whl file downloaded previously by running:
pip install "downloaded .whl filename"
To install from source clone the repo from https://github.com/pyxll/blpapi-python and follow the instructions in the README file.
Build the Bloomberg Python API with the matching C++ SDK
To use the official Bloomberg Python API, if there is no pre-built version using the same Bloomberg SDK that you require, you will need to build it yourself using that version of the Bloomberg SDK.
- Make a note of the version of the C++ SDK from the error message that is printed when trying to import the blpapi package.
- Download that version of the C++ SDK from Bloomberg’s website.
- Build the Bloomberg Python API using that C++ SDK.
- Ensure that any previously installed versions of the blpapi package are uninstalled and install the one just built.