3

I am trying to get set up with the Bloomberg Python API. I have been following along with this tutorial. I am able to successfully python -m pip install — index-url=https://bloomberg.bintray.com/pip/simple blpapi, but then when I try to run import blpapi in the Python interpreter, I get the following error. How do I resolve this error (wondering if it has something to due with me using Python 3.8)?

ImportError:
---------------------------- ENVIRONMENT -----------------------------
Platform: Windows-10-10.0.17763-SP0
Architecture: ('32bit', 'WindowsPE')
Python: 3.8.0 (tags/v3.8.0:fa919fd, Oct 14 2019, 19:21:23) [MSC v.1916 32 bit (Intel)]
Python implementation: CPython

blpapi 64-bit will be loaded from: "C:\blp\API\blpapi_cpp_3.13.1.1\lib\blpapi3_64.dll"
blpapi 32-bit will be loaded from: "C:\blp\API\blpapi_cpp_3.13.1.1\lib\blpapi3_32.dll"
System PATH: (* marks locations where blpapi was found)
    "C:\Windows\system32"
    "C:\Windows"
    "C:\Windows\System32\Wbem"
    "C:\Windows\System32\WindowsPowerShell\v1.0\"
    "C:\Windows\System32\OpenSSH\"
    "C:\Program Files (x86)\Intel\Intel(R) Management Engine Components\DAL"
    "C:\Program Files\Intel\Intel(R) Management Engine Components\DAL"
    "c:\nx_dll"
    "C:\Program Files\nodejs\"
  * "C:\blp\API\blpapi_cpp_3.13.1.1\lib"
    "C:\Program Files\MiKTeX 2.9\miktex\bin\x64\"
    "C:\Users\cpage\AppData\Local\Programs\Python\Python38-32\Scripts\"
    "C:\Users\cpage\AppData\Local\Programs\Python\Python38-32\"
    "C:\Users\cpage\AppData\Local\Microsoft\WindowsApps"
  * "C:\blp\DAPI"
    "C:\blp\DAPI\DDE"
    "C:\Users\cpage\AppData\Roaming\npm"
    "C:\Program Files\Sublime Text 3"
    "C:\Users\cpage\AppData\Local\hyper\app-3.0.2\resources\bin"
    "C:\Users\cpage\AppData\Local\Programs\Microsoft VS Code\bin"
  * "C:\blp\API\blpapi_cpp_3.13.1.1\lib"

blpapi package at: "C:\Users\cpage\AppData\Local\Programs\Python\Python38-32\lib\site-packages"

Current directory: "C:\Users\cpage"

----------------------------------------------------------------------
No module named '_versionhelper'

Could not open the C++ SDK library.

Download and install the latest C++ SDK from:

    http://www.bloomberg.com/professional/api-library

If the C++ SDK is already installed, please ensure that the path to the library
was added to PATH before entering the interpreter.
cpage
  • 119
  • 6
  • 27
  • There are several similar questions: https://stackoverflow.com/search?q=%5Bbloomberg%5D+%22Could+not+open+the+C%2B%2B+SDK+library%22 One of them mentions creating an environment variable: `BLPAPI_ROOT`. – assylias Nov 27 '19 at 19:39
  • Yes, I have already set `BLPAPI_ROOT` to be `C:\blp\API\blpapi_cpp_3.13.1.1\`. – cpage Nov 27 '19 at 19:50
  • Running through the same problem on Python 3.8 and blpapi_cpp_3.14.3.1 – gt6989b Jul 21 '20 at 17:39
  • @gt6989b I'm also trying to use blpapi with Python 3.8. Tried by using pip to install it and by building from source (after setting BLPAPI_ROOT) from blpapi 3.14.3.1, blpapi 3.13.3.1, blpapi 3.12.3.1 and blpapi 3.12.2.1 but none of them seem to work. The error message is almost always the same (Import Error) – raphaeldavidf Jul 21 '20 at 21:24
  • @raphaeldavidf perhaps better to downgrade to Python 3.7, everything works out of the box. – gt6989b Jul 22 '20 at 19:12
  • 1
    @gt6989b the new version works on 3.8, give it a try – raphaeldavidf Sep 09 '20 at 21:16
  • @raphaeldavidf too late for us :) we were moving from 2.7 and ended up in 3.7 because of this and of some other problems. 3.8 is too recent I guess. – gt6989b Sep 10 '20 at 00:10

3 Answers3

3

You need to download the python blpapi package having the version matching your C++ lib.

In your case, since your C++ lib is 3.13.1.1, you can download the 3.13.1 python package:

pip install --index-url=https://bloomberg.bintray.com/pip/simple blpapi==3.13.1

Kevin Liu
  • 667
  • 5
  • 14
2

Just managed to make it run using version blpapi-3.15.2 using C++ API blpapi_cpp_3.15.0.1

To install run:

python -m pip install --index-url=https://bloomberg.bintray.com/pip/simple blpapi

to import use:

import os
with os.add_dll_directory('<...>\blpapi_cpp_3.15.0.1\lib'):
    import blpapi

or add '<...>\blpapi_cpp_3.15.0.1\lib' to PATH

raphaeldavidf
  • 103
  • 1
  • 3
  • 10
1

The following procedure works out of the box for CPython 2.7 and 3.7. A Bloomberg rep claims he verified it for CPython 3.5 as well:

  1. Download the C++ BLP API from the official Bloomberg repository. If this link breaks, use Bloomberg API Support homepage to find the up-to-date ones.
  2. Unpack the archive to C:\Programs\blpapi_cpp_3.14.3.1
  3. Exit from the shell.
  4. Set the environment variable BLPAPI_ROOT=C:\Programs\blpapi_cpp_3.14.3.1\. Note that the trailing slash is important.
  5. Start a new shell.
  6. Execute python -m pip install --index-url=https://bloomberg.bintray.com/pip/simple blpapi==3.14.0
  7. Check the installation by executing python -c "import blpapi", which should pass without displaying messages.
gt6989b
  • 4,125
  • 8
  • 46
  • 64
  • I hit this problem about once a year and every time i have to search for solution. Since I had all proper versions already I just added the trailing slash from step 4 and copied **blpapi3_32.dll** and **blpapi3_64.dll** to _C:\blp\DAPI_ folder. did not have to reinstall or download anything. it might be that terminals .dll in DAPI folder got automatically updated to older one screwing things up. – gregV Sep 24 '20 at 18:47
  • @Vrun this makes sense, and would work, but is hacky to me. In addition, you run the risk that Bloomberg Terminal software will have a backward-incompatible released, cause the Terminal not to work. – gt6989b Sep 24 '20 at 22:02