简体   繁体   English

如何在Travis CI下安装Vowpal Wabbit Python绑定?

[英]How to install Vowpal Wabbit Python bindings under Travis CI?

I'm trying to use Vowpal Wabbit from my Python projects. 我正在尝试从我的Python项目中使用Vowpal Wabbit。 I can install the Python VW bindings locally (in Ubuntu 18.04) using pip install vowpalwabbit , as long as I've first installed the build dependencies ( apt install libboost-program-options-dev libboost-python-dev zlib1g-dev ). 我可以使用pip install vowpalwabbit在本地(在Ubuntu 18.04中)安装Python VW绑定,只要我首先安装了构建依赖项( apt install libboost-program-options-dev libboost-python-dev zlib1g-dev )。

I want to run unit tests for Python programs under Travis CI, so I need to be able to install dependencies within the Travis environment as well. 我想在Travis CI下为Python程序运行单元测试,因此我还需要能够在Travis环境中安装依赖项。 However, I cannot get the Python VW bindings to install. 但是,我无法安装Python VW绑定。 I created a minimal project demonstrating the problem. 我创建了一个最小的项目来演示该问题。 I'm using the most recent xenial (ie Ubuntu 16.04 based) image of Travis and Python versions 3.5, 3.6 and 3.7. 我正在使用Travis和Python版本xenial和3.7的最新xenial (即基于Ubuntu 16.04的)映像。 Here's the Travis CI output . 这是Travis CI输出

The Python 3.5 issue seems to be caused by linking to the wrong (Python 2.7) version of libboost_python.so (see eg this issue ) when the python extension is built. 构建Python扩展时,Python 3.5问题似乎是由链接到错误的(Python 2.7)版本的libboost_python.so引起的(请参见此问题 )。 That issue had a workaround which involved changing the symlink libboost_python.so to point to the Python 3.5 version (instead for the 2.7 version). 该问题有一个解决方法,其中涉及更改符号链接libboost_python.so以指向Python 3.5版本(而不是2.7版本)。 I tried that on the boost-py2-py3-workaround branch, but it didn't seem to help . 我在boost-py2-py3-workaround分支上尝试过,但是似乎没有帮助

Here is the .travis.yml config: 这是.travis.yml配置:

dist: xenial
language: python
python:
- '3.5'
- '3.6'
- '3.7'
cache: pip
install:
- sudo apt-get install libboost-program-options-dev libboost-python-dev zlib1g-dev
- pip install vowpalwabbit
script:
- python test-vw.py

The test-vw.py script just imports the pyvw module and runs some basic commands (taken from the Python VW documentation): test-vw.py脚本仅导入pyvw模块并运行一些基本命令(取自Python VW文档):

from vowpalwabbit import pyvw

vw = pyvw.vw(quiet=True)
ex = vw.example('1 | a b c')
vw.learn(ex)
print(vw.predict(ex))

I would expect the pip install to succeed and then the test-vw.py should run and produce a little bit of output as the model is created and its prediction is printed. 我希望pip install成功,然后test-vw.py应该运行并在创建模型和打印其预测时产生一点输出。

The actual result depends on the Python version. 实际结果取决于Python版本。 For Python 3.5, the vowpalwabbit library seems to be successfully installed but running the Python script fails with this error ( full build log ): 对于Python 3.5, vowpalwabbit库似乎已成功安装,但运行Python脚本失败并显示此错误( 完整构建日志 ):

$ python test-vw.py Traceback (most recent call last): File "test-vw.py", line 6, in <module> from vowpalwabbit import pyvw File "/home/travis/virtualenv/python3.5.6/lib/python3.5/site-packages/vowpalwabbit/pyvw.py", line 2, in <module> import pylibvw ImportError: /usr/lib/x86_64-linux-gnu/libboost_python-py27.so.1.58.0: undefined symbol: PyClass_Type The command "python test-vw.py" exited with 1.

For Python 3.6 and 3.7, the pip install fails ( full build log ): 对于Python 3.6和3.7, pip install失败( 完整的构建日志 ):

  Using Python 3.6
  pyenv: python3.6-config: command not found

  The `python3.6-config' command exists in these Python versions:
    3.6
    3.6.7

  /usr/bin/g++ -std=c++0x  -I /usr/local/include/boost -I /usr/include -I ../rapidjson/include -fPIC -c pylibvw.cc -o pylibvw.o
  In file included from /usr/include/boost/python/detail/prefix.hpp:13:0,
                   from /usr/include/boost/python/args.hpp:8,
                   from /usr/include/boost/python.hpp:11,
                   from pylibvw.cc:14:
  /usr/include/boost/python/detail/wrap_python.hpp:50:23: fatal error: pyconfig.h: No such file or directory

So there seems to be two separate issues, depending on which Python version is being tried. 因此,似乎有两个独立的问题,具体取决于所尝试的Python版本。 I'm happy for help with either issue. 我很高兴为任何一个问题提供帮助。

I got it working for the Python 3.5 case. 我让它适用于Python 3.5案例。 The crucial part was changing the symlinks to point to the Python 3.5 version of libboost_python.so, like this in .travis.yml: 关键部分是更改符号链接以指向libboost_python.so的Python 3.5版本,例如.travis.yml中的代码:

install:
- sudo apt-get install libboost-program-options-dev libboost-python-dev zlib1g-dev
- sudo ln -sf /usr/lib/x86_64-linux-gnu/libboost_python-py35.a /usr/lib/x86_64-linux-gnu/libboost_python.a
- sudo ln -sf /usr/lib/x86_64-linux-gnu/libboost_python-py35.so /usr/lib/x86_64-linux-gnu/libboost_python.so
- pip install vowpalwabbit

Here is the working code on the boost-py2-py3-workaround branch, and the Travis build output . 这是boost-py2-py3-workaround分支上的工作代码 ,Travis build输出

This is enough to have tests running at least for one Python version, which is OK for now. 这足以使测试至少在一个Python版本上运行,目前还可以。 For the other Python versions (3.6 and 3.7) the problem is that there is no easily available precompiled version of libboost-python that could just be installed into the Travis CI virtual environment. 对于其他Python版本(3.6和3.7),问题在于没有容易获得的libboost-python预编译版本可以直接安装到Travis CI虚拟环境中。 The libboost-python libraries available via apt-get are only available for Python 3.5, which is the default Python 3 version available in Ubuntu 16.04 Xenial. 通过apt-get提供的libboost-python库仅适用于Python 3.5,这是Ubuntu 16.04 Xenial中可用的默认Python 3版本。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM