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 intoC:\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?
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.
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 :
uninstall anaconda completely (that was difficult and I mostly had to do it manually even after trying anaconda-clean)
uninstall and reinstall Bloomberg
Installed python 3.6 (32-bit) from python.org
Installed Anaconda latest version 64-bit
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/
Regular command prompt:
pip install c:\YOURPATH\blpapi-3.9.1-cp36-cp36m-win32.whl
Check that it worked --
import blpapi
in ptyhon worked but it still wouldn't work in Jupyter nbTried 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.3Now 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.
I had the exact same error & replied with my error message. Finally got it to work.
python -m pip install --index-url=https://bloomberg.bintray.com/pip/simple blpapi
in my conda execSomehow that worked. I feel really stupid, but relieved.
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.
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 ?
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 ofv3.8.18.1
). This seems inconsistent with what they are releasing viaWAPI
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/ viaanacoda search blpapi
Solution that worked for me with Python 3.7 on Windows 10:
1/Download the Bloomberg experimental C++ 3.12 SDK from
WAPI<GO>
orhttps://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 leastC:\blp\DAPI
andC:\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)