eclipse Python 2.7 与 Bloomberg API 导入 blpapi 失败
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/24317469/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Python 2.7 with Bloomberg API import blpapi failure
提问by TARKUS
This is my development environment:
这是我的开发环境:
- Windows 7 on a 64-bit HP Pavilion laptop
- Python 2.7, 32-bit in folder C:\python27
- Development environment is Eclipse with PyDev, but this doesn't seem to matter, because I get the same kind of failure whether I use Anaconda or Notepad++.
- Python 2.7 Binary Installer for Windows - 32-bit v3.5.3Having set the Environment PATH in Windows for Python, the BLPAPI does find and install into the C:\Python27 directory, creating
C:\Python27\Lib\site-packages\blpapi.
- 64 位 HP Pavilion 笔记本电脑上的 Windows 7
- 文件夹 C:\python27 中的 Python 2.7,32 位
- 开发环境是带有 PyDev 的 Eclipse,但这似乎无关紧要,因为无论我使用 Anaconda 还是 Notepad++,我都会遇到同样的失败。
- 适用于 Windows 的 Python 2.7 二进制安装程序 - 32 位 v3.5.3在 Windows 中为 Python 设置环境路径后,BLPAPI 确实会找到并安装到 C:\Python27 目录中,创建
C:\Python27\Lib\site-packages\blpapi.
Previous to my 32-bit installation of Python and BLPAPI I tried the 64-bit Python 2.7 with the 64-bit BLPAPI installation, but the results are the same for 64- or 32-bit.
在我安装 32 位 Python 和 BLPAPI 之前,我尝试了 64 位 Python 2.7 和 64 位 BLPAPI 安装,但结果对于 64 位或 32 位是相同的。
My Python script fails on this one line: import blpapi
我的 Python 脚本在这一行失败: import blpapi
PyDev produces this error code:
PyDev 产生此错误代码:
Traceback (most recent call last):
File "C:\Users\Greg\workspace2\Bloomberg\src\TestImport.py", line 1, in <module>
import blpapi
File "C:\Python27\lib\site-packages\blpapi\__init__.py", line 5, in <module>
from .internals import CorrelationId
File "C:\Python27\lib\site-packages\blpapi\internals.py", line 50, in <module>
_internals = swig_import_helper()
File "C:\Python27\lib\site-packages\blpapi\internals.py", line 46, in swig_import_helper
_mod = imp.load_module('_internals', fp, pathname, description)
ImportError: DLL load failed: The specified module could not be found.
回答by Keng Onn
I encountered a similar problem, and spent some time troubleshooting the issue with Bloomberg helpdesk. Here's what I learnt:
我遇到了类似的问题,并花了一些时间通过彭博帮助台解决问题。这是我学到的:
The ImportError is the result of Bloomberg not being able to find the "blpapi3_32.dll" DLL file. This DLL file can be located under the \bin or \lib folder of Bloomberg's C/C++ library, which is at the same location where you got your Python executable. So go download that library (v3.7.5.1 as of this writing), and have your system's "Path" environment variable include that location. This should resolve the issue.
ImportError 是 Bloomberg 无法找到“blpapi3_32.dll”DLL 文件的结果。此 DLL 文件可以位于 Bloomberg 的 C/C++ 库的 \bin 或 \lib 文件夹下,该文件夹与您获得 Python 可执行文件的位置相同。因此,请下载该库(撰写本文时为 v3.7.5.1),并使系统的“路径”环境变量包含该位置。这应该可以解决问题。
PS you can access the PATH variable via Start > right-clicking "Computer" > Properties > Advanced System Settings > Advanced (tab) > Environment Variables > look for the "Path" variable under "System variables". Edit this variable to include the location of the DLL file, e.g. if the original Path variable is "C:\Python27\Lib\site-packages\PyQt4", then new Path variable should be "C:\Python27\Lib\site-packages\PyQt4;C:\blp\API\blpapi_cpp_3.7.5.1\bin"
PS您可以通过开始>右键单击“计算机”>属性>高级系统设置>高级(选项卡)>环境变量>在“系统变量”下查找“路径”变量来访问PATH变量。编辑此变量以包含 DLL 文件的位置,例如,如果原始 Path 变量是“C:\Python27\Lib\site-packages\PyQt4”,那么新的 Path 变量应该是“C:\Python27\Lib\site-包\PyQt4;C:\blp\API\blpapi_cpp_3.7.5.1\bin"
回答by Flavio Wuensche
Note this article, from Bloomberg:
请注意这篇来自彭博社的文章:
In order for python scripts to call Bloomberg API functions, the libraries distributed as part of the Bloomberg C++ SDK must be available to the Python interpreter. Step 3 of installation, above, provides system-wide installation of this library. Linux/Solaris/*nix users without system-wide installations must set the LD_LIBRARY_PATH (or DYLD_LIBRARY_PATH on Darwin/MacOS X) environment variable to include the directory containing the blpapi3 shared libraries. Windows users may need to set the PATH variable to the directory containing blpapi3_32.dll or blpapi3_64.dll. (Note that Windows users with the Bloomberg Terminal software installed already have versions of these libraries in their PATH.)
为了让 Python 脚本调用 Bloomberg API 函数,作为 Bloomberg C++ SDK 一部分分发的库必须可供 Python 解释器使用。上面的安装步骤 3 提供了该库的系统范围安装。没有系统范围安装的 Linux/Solaris/*nix 用户必须设置 LD_LIBRARY_PATH(或 Darwin/MacOS X 上的 DYLD_LIBRARY_PATH)环境变量以包含包含 blpapi3 共享库的目录。Windows 用户可能需要将 PATH 变量设置为包含 blpapi3_32.dll 或 blpapi3_64.dll 的目录。(请注意,安装了 Bloomberg Terminal 软件的 Windows 用户已经在他们的 PATH 中安装了这些库的版本。)
So what I did (very similarly to Keng Onn's answer) was:
所以我所做的(与 Keng Onn 的回答非常相似)是:
Extract files from blpapi_cpp_3.8.8.1.zip (or similar)
Copy blpapi3_32.dll from the bin folder and paste it anywhere safe
从 blpapi_cpp_3.8.8.1.zip(或类似的)中提取文件
从 bin 文件夹中复制 blpapi3_32.dll 并将其粘贴到任何安全的地方
In my case, I pasted it into C:\Python27\Lib\site-packages\blpapi
就我而言,我将其粘贴到 C:\Python27\Lib\site-packages\blpapi
Add this route to your Path environment variable
Click "Start" / Right-click "Computer" / Properties / Advanced System Settings / Advanced tab / Environment Variables
Double click "Path" under "System variables" list
Add a semicolon (;) and your path as seen below
将此路由添加到您的 Path 环境变量
单击“开始”/右键单击“计算机”/属性/高级系统设置/高级选项卡/环境变量
双击“系统变量”列表下的“路径”
添加分号 (;) 和您的路径,如下所示
For me: C:\Python27\Lib\site-packages\blpapi
对我来说:C:\Python27\Lib\site-packages\blpapi


Now it should work just fine for you. Hope it helps.
现在它应该适合你。希望能帮助到你。
回答by alex314159
I had the same issue, which was simply solved after updating the Bloomberg terminal application.
我也有同样的问题,更新彭博终端应用后简单解决。

