ImportError _versionhelper when setting up Bloomberg Python API
Asked Answered
F

3

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.
Florella answered 27/11, 2019 at 19:23 Comment(7)
There are several similar questions: stackoverflow.com/… One of them mentions creating an environment variable: BLPAPI_ROOT.Regolith
Yes, I have already set BLPAPI_ROOT to be `C:\blp\API\blpapi_cpp_3.13.1.1`.Florella
Running through the same problem on Python 3.8 and blpapi_cpp_3.14.3.1Holmen
@Holmen 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)Thrombin
@Thrombin perhaps better to downgrade to Python 3.7, everything works out of the box.Holmen
@Holmen the new version works on 3.8, give it a tryThrombin
@Thrombin 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.Holmen
N
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

Nightgown answered 20/1, 2020 at 9:24 Comment(0)
T
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

Thrombin answered 9/9, 2020 at 21:14 Comment(0)
H
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.
Holmen answered 22/7, 2020 at 19:11 Comment(2)
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.Absorb
@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.Holmen

© 2022 - 2024 — McMap. All rights reserved.