Install error for blpapi in python for bloomberg API
Asked Answered
A

15

10

I am a Bloomberg terminal user and am trying to get the API to work via Python.

I have Python 3.7.0 64-bit on my Windows 7 64-bit computer installed to: C:\Users\gp\AppData\Local\Programs\Python\Python37

I downloaded the C/C++ Supported Release (v3.8.18.1) from the Bloomberg API Library. I unzipped contents to C:\blp\API\cpp (I am a terminal user so I already had C:\blp\API and I added a new folder "CPP").

I then installed the Python API through pip as stated at the bottom of this page: API Library Support and received a Successfully installed blpapi-3.12.2 message. I noticed this got installed to C:\Users\gp\AppData\Local\Programs\Python\Python37\Lib\site-packages

In Idle I then import blpapi and I get the following errors:

Traceback (most recent call last):
  File "C:\Users\gp\AppData\Local\Programs\Python\Python37\lib\site-packages\blpapi\internals.py", line 39, in swig_import_helper
return importlib.import_module(mname)
  File "C:\Users\gp\AppData\Local\Programs\Python\Python37\lib\importlib\__init__.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 1006, in _gcd_import
  File "<frozen importlib._bootstrap>", line 983, in _find_and_load
  File "<frozen importlib._bootstrap>", line 967, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 670, in _load_unlocked
  File "<frozen importlib._bootstrap>", line 583, in module_from_spec
  File "<frozen importlib._bootstrap_external>", line 1043, in create_module
  File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
ImportError: DLL load failed: The specified procedure could not be found.

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:\Users\gp\AppData\Local\Programs\Python\Python37\lib\site-packages\blpapi\__init__.py", line 4, in <module>
from .internals import CorrelationId
  File "C:\Users\gp\AppData\Local\Programs\Python\Python37\lib\site-packages\blpapi\internals.py", line 42, in <module>
_internals = swig_import_helper()
  File "C:\Users\gp\AppData\Local\Programs\Python\Python37\lib\site-packages\blpapi\internals.py", line 41, in swig_import_helper
return importlib.import_module('_internals')
  File "C:\Users\gp\AppData\Local\Programs\Python\Python37\lib\importlib\__init__.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
ModuleNotFoundError: No module named '_internals'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "<pyshell#1>", line 1, in <module>
import blpapi
  File "C:\Users\gp\AppData\Local\Programs\Python\Python37\lib\site-packages\blpapi\__init__.py", line 9, in <module>
raise debug_load_error(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

If a recent version of the C++ SDK is already installed, please ensure that the
path to the library is added to PATH before entering the interpreter.

I searched through answers on this site and attempted the following:

  • set the 'path' variable in both "User variables for gp" and "system variables" in system properties to: C:\blp\DAPI;C:\blp\DAPI\DDE;C:\blp\API\cpp;C:\blp\API\cpp\bin (DAPI and DDE folders were already there)
  • added a 'BLPAPI_ROOT' variable of: C:\blp\API\cpp in the "User variables for gp" and "system variables" in system properties
  • tried placing a copy of blpapi3_64.dll from the C:\blp\API\cpp\bin folder into C:\Users\gp\AppData\Local\Programs\Python\Python37\Lib\site-packages and tried placing it in subfolder "blpapi" and added those locations to the path variable mentioned above and it still did not work.
  • ensured I have downloaded Visual Studio Build Tools 2017

Any other ideas?

Achlamydeous answered 19/10, 2018 at 17:47 Comment(0)
M
10

The problem of mismatch comes from the fact that you need to download version 3.12 of the SDK. Currently it corresponds to the "Experimental release" (and not Supported release !) that you can find here:

https://www.bloomberg.com/professional/support/api-library/

enter image description here

Other remarks:

  1. I advice you to download the BloombergWindowsSDK via the Bloomberg Terminal because you'll get python codes also.
  2. No needs to play with system path, you can just copy and past blpapi3_64.dll blpapi3_32.dll to the same folder as the one where your python code is located.
Motorbus answered 15/11, 2018 at 16:15 Comment(0)
E
4

Solution that worked for me with Python 3.7 on Windows 10:

1/Download the Bloomberg experimental C++ 3.12 SDK from WAPI<GO> or https://www.bloomberg.com/professional/support/api-library/

2/Extract, look for the lib folder, there are four files, blpapi3_32.dll, blpapi3_32.lib, blpapi3_64.dll, blpapi3_64.lib.

3/in the windows shell I typed where blpapi3_32.dll and replaced all of these locations with the new files above. In my case it was at least C:\blp\DAPI and C:\Users\MyName\AppData\Local\Continuum\anaconda3\Library\bin\blpapi3_32.dll (you will need to close the Bloomberg desktop before overriding these files as they're used by the desktop application)

Extensor answered 14/1, 2019 at 17:15 Comment(0)
S
3

The problem is that you have the same libraries (DLL files) installed in the C:\blp\DAPI and the cpp folder. However, the version of these files is not the same, and that is why the error message appears. A simple fix is to copy and paste all libraries from the c:\lib\blpapi_cpp_3.12.2.1\lib folder into C:\blp\DAPI. This fixes the problem.

Spandau answered 5/1, 2019 at 12:28 Comment(0)
C
2

Actually the clue is hidden at the end of the error message, but it wasn't entirely clear.

You need to download the Bloomberg C++ library as well. Unzip into a folder, let's call it c:\lib\blpapi_cpp_3.12.2.1

What you need to do is add c:\lib\blpapi_cpp_3.12.2.1\lib into you PATH environment variable. The important bit is to include the lib sub folder.

This solved my issue with python 3.7.

Crowther answered 7/11, 2018 at 21:37 Comment(0)
P
2

As @Malick points out in his answer, currently Bloomberg has a mismatch in their versioning on https://www.bloomberg.com/professional/support/api-library/ where the stable version of blpapi for python requires the experimental version of the C++ SDK (i.e. v3.12.2.1 instead of v3.8.18.1). This seems inconsistent with what they are releasing via WAPI in the terminal.

Another option, provided you can find a build for your desired platform and python version, is to use conda. You can see what is available on https://anaconda.org/ via anacoda search blpapi

$ anaconda search blpapi
Using Anaconda API: https://api.anaconda.org
Packages:
     Name                      |  Version | Package Types   | Platforms       | Builds    
     ------------------------- |   ------ | --------------- | --------------- | ----------
     conda-forge/blpapi        |    3.9.2 | conda           | linux-64, win-64, osx-64 | py36he980bc4_0, py36_blpapicpp3.8.18.1_1, py36_blpapicpp3.8.1.1_1, py27h2d50403_0, py27_blpapicpp3.8.18.1_1, py27hdc96acc_0, py36h2d50403_0, py27_blpapicpp3.8.1.1_1
                                          : Python SDK for Bloomberg BLPAPI (<=3.9)
     dsm/blpapi                |    3.9.0 | conda           | linux-64, win-64 | py36_0, py27_0
     josh/blpapi               |    3.5.5 | conda           | linux-64        | py27_0    
     macinv/blpapi             |    3.9.0 | conda           | linux-64, win-64 | py36_0, py27_0, py35_0, py34_0
     mbonix/blpapi             |    3.9.0 | conda           | win-64          | py36_0    
                                          : Bloomberg's Open Market Data Initiative is part of the company's ongoing effort to foster open solutions for the financial services industry.
     p-vg/blpapi               |    3.9.2 | conda           | linux-64, win-64 | py36h6538335_0, py27hc56fc5f_0, py36hf484d3e_0, py27hf484d3e_0
                                          : interface for Bloomberg API services using the Python programming language
Found 6 packages

Run 'anaconda show <USER/PACKAGE>' to get installation details
Paternoster answered 15/11, 2018 at 23:13 Comment(0)
C
1

I struggled with these issues like others here. I was running the latest Anaconda3 5.3.1 with Python 3.7. I did the following :

  1. uninstall anaconda completely (that was difficult and I mostly had to do it manually even after trying anaconda-clean)

  2. uninstall and reinstall Bloomberg

  3. Installed python 3.6 (32-bit) from python.org

  4. Installed Anaconda latest version 64-bit

  5. Found the packages needed for Bloomberg on another PC that wasn't having these issues. But I also found them here: https://bloomberg.bintray.com/pip/simple/blpapi/

  6. Regular command prompt: pip install c:\YOURPATH\blpapi-3.9.1-cp36-cp36m-win32.whl

  7. Check that it worked -- import blpapi in ptyhon worked but it still wouldn't work in Jupyter nb

  8. Tried to install blpapi-3.9.1-cp36-cp36m-win_amd64.whl in anaconda prompt but that didn't work. So in Conda prompt I did conda install python=3.6.3 to downgrade from PY3.7 to 3.6.3

  9. Now in conda prompt: pip install c:\YOURPATH\blpapi-3.9.1-cp36-cp36m-win_amd64.whl and that installed.

A note about Environment variables in PATH -- I have nothing other than the usual C:\blp\DAPI;C:\blp\DAPI\DDE related to Bloomberg.
The dll you need is already in there (I believe).
The one thing I did do with PATH was have C:\Users\YOUR\AppData\Local\Programs\Python\Python36-32\Scripts\;C:\Users\YOUR\AppData\Local\Programs\Python\Python36-32 and that was actually done by ticking the PATH box when I installed python 3.6.

There are many redundant or unnecessary steps here. I think the most important point is there is some issue with the C++ files that Bloomberg gives you with their latest release -- these older files seem to work. The key there is obviously that you have to downgrade to PY 3.6. I think steps 3-6 in my example would have worked without the first two.

Cabinetwork answered 19/12, 2018 at 23:43 Comment(0)
L
1

Check which folder is in your environment path. Sometimes people have two blp folders in system path, i.e. both C:\blp\DAPI and C:\BloombergWindowsSDK\C++API\v3.12.3.1\lib, make sure you have latest blpapi3_32.dll and blpapi3_64.dll in both file.

Lucubrate answered 15/2, 2019 at 18:53 Comment(0)
E
1

My Python version is 3.7.1 [MSC v.1915 64 bit (AMD64)], Windows7 64-bit.

Just migrated to a new PC, and had the same two errors:

"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"

What worked for me is very similar to alex314159, without needing to waste time with PATH variables.

  1. Close all applications--> else cannot move files in steps below since they could be in use.

  2. Download and install the latest C++ SDK (in my case, 2020April it was 3.12.3.1. *Update as of 2020March15, it was blpapi_cpp_3.14.3) from the link provided in the error or original post: https://www.bloomberg.com/professional/support/api-library/ The blpapi3_32.dll and blpapi3_64.dll are inside the 'bin' folder.

  3. Then using CMD in Windows, type 'where blpapi3_64.dll', which for me it returned "C:\Program Files (x86)\blp\DAPI".

  4. Copy&replace the blpapi3_32.dll and blpapi3.64.dll from Step2 into the folder in Step3.

  5. Launch Jupyter Notebook, run 'import blpapi' ...and finally it worked! *20201221 update: migrating to Windows10, did not work. Fix: ensure VisualStudio installed as needs reboot; get version of the SDK blp_cpp download (3.16.1); on laptop outside firewall pip install --index-url=https://bloomberg.bintray.com/pip/simple blpapi==3.16.1 (ie matching version). Wayne used wheel to then install new blpapi folder into SitePackages...(oddly was 3.15 instead)..launch Jupyter and then finally worked. (also ImportError _versionhelper when setting up Bloomberg Python API)

As a side note, I'd love to know why the original error was 'ModuleNotFoundError: No module named '_internals' as when opening the blpapi folder in my site-packages, there is a module called internals.py as well as one called _internals.cp37-win-arnd64.pyd ?

** New: for the related 'tia' module to work, need to change 'basestring' to 'str' in v3api.py ..since I keep doing this, just email the working v3api.py from office PC to new computer, then drag&drop to C:\Users\miste\AppData\Local\Continuum\anaconda3\Lib\site-packages\tia\bbg Remember if cannot see AppData to un-hide it: View->HiddenItems **

** 2021.12.12: https://www.bloomberg.com/professional/support/api-library/ now has a Windows API Python, so just follow pip install command there and no need to separately install C++ api! Still need to tweak tia as per above or try this wrapper instead:
https://pypi.org/project/xbbg/#description

2023.01.21: new migration and laptop. Pip install via anaconda prompt again worked like magic (make sure no blpapi folder is in the sitepackages ) on laptop or the old version will be there and usual C++ issue *

Enthusiastic answered 15/4, 2019 at 4:47 Comment(0)
C
1

For 3.7 on windows I had to use the 3.31.1 version of the C\C++ library. It was marked as experimental but Bloomberg but it allowed me to import it successfully.

Cruz answered 15/5, 2019 at 15:5 Comment(0)
M
1

Windows 10 / Python 3.8 / blpapi_cpp_3.14.3.1

I struggled all my day on it, trying and failing,

At the end, THIS IS WHAT WORKS FOR ME, as described in this chat and here

  1. Download the C++ BLP API from https://www.bloomberg.com/professional/support/api-library/ API Windows >> C/C++ Experimental Release (last version) and extract the blpapi_cpp_3.14.3.1.zip in C:\blp\cpp
  2. Set the USER environment variable BLPAPI_ROOT=C:\blp\cpp\lib\ environment variables Note that the trailing slash is important (didn't work without)!!
  3. Recopy the blpapi3_32.dll and blpapi3_64.dll from C:\blp\cpp\lib to C:\blp\DAPI
  4. In the Shell
  • if installed,uninstall blpapi : execute python uninstall blpapi
  • execute python -m pip install --index-url=https://bloomberg.bintray.com/pip/simple blpapi==3.14.0 Note that indicating the 3.14.0 matching to the C++ version (blpapi_cpp_3.14.3.1) is also important.
  1. Test in the Shell Executing python -c "import blpapi"
Marmoreal answered 9/9, 2020 at 17:54 Comment(1)
I hit this problem about once a year and every time i had to search for solution. Either step 2 (trailing slash) or 3 worked for me without reinstall.Acanthous
P
0

I had the exact same error & replied with my error message. Finally got it to work.

  1. Uninstalled blpapi and my Bloomberg professional software.
  2. Reinstalled the latest Bloomberg professional
  3. Dropped the C++ directory into C:\blp\api\cpp as before
  4. installed blpapi using python -m pip install --index-url=https://bloomberg.bintray.com/pip/simple blpapi in my conda exec

Somehow that worked. I feel really stupid, but relieved.

Potomac answered 6/11, 2018 at 1:45 Comment(0)
H
0

Running Windows 10 and Python 3.7.5.

I downloaded the experimental release here https://www.bloomberg.com/professional/support/api-library/ as suggested by other people already.

I was still getting an error though when I tried to run import blpapi.

I solved this by adding C:\blpapi_cpp_3.13.1.1\bin to my PATH environment variable. Apparently the system couldn't find the DLL files for the C++ SDK and needs a direct path to the folder.

Homegrown answered 23/1, 2020 at 17:33 Comment(0)
J
0

I did 2 things to solve an issue similar to that: In my case, a recent version of the C++ SDK was already installed and the issue was system trying to reach dll files but was it couldn't.

1- I manually copied the .dll files in C++API\lib (blpapi3_32.dll and blpapi3_64.dll in my case) into C:\windows\system32 where all the dll files that system uses.

Also, I copied the dll files in in C++API\lib into C:\blp\DAPI, replacing the new ones with the old ones.

2- I installed Microsoft Visual Studio with the following components

  • C++/CLI Support
  • VC++ 2015.3 v14.00 (v140) toolset for desktop
  • Visual C++ MFC for x86 and x64
  • Visual C++ ATL for x86 and x64

Second step may be useful because you may not have C++ compiler. You may have Microsoft Visual C++ 14.x.x Redistributable or any other version on your computer but it is different from "VC++ 2015.3 v14.00" which comes with Visual Studio.

Junco answered 14/10, 2020 at 21:22 Comment(0)
I
0

This sounds incredibly dumb in retrospect, but I had been trying pip installs based on previous comments in this thread, instead of actually taking the time to read Bloomberg's site. I then tried

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

and it worked straight away.

Iseabal answered 11/3, 2021 at 1:53 Comment(0)
S
0

Tried everything here, but what worked for me was:

pip install blpapi --index-url=https://bcms.bloomberg.com/pip/simple/
Sulky answered 23/7, 2021 at 15:31 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.