ImportError:没有名为couchbase._libcouchbase的模块

时间:2015-08-17 17:42:55

标签: python ubuntu-12.04 couchbase python-cffi

这只发生在Travis构建的Travis中。 这是确切的错误字符串:

Traceback (most recent call last):
  File "app_main.py", line 75, in run_toplevel
  File "app_main.py", line 581, in run_it
  File "<string>", line 1, in <module>
  File "tests/test_pycouchbase.py", line 15, in <module>
    from pycouchbase.utils import *
  File "pycouchbase/__init__.py", line 8, in <module>
    from .connection import Connection
  File "pycouchbase/connection.py", line 3, in <module>
    from couchbase.bucket import Bucket
  File "/home/travis/virtualenv/pypy-2.5.0/site-packages/couchbase/__init__.py", line 28, in <module>
    from couchbase.user_constants import *
  File "/home/travis/virtualenv/pypy-2.5.0/site-packages/couchbase/user_constants.py", line 21, in <module>
    import couchbase._bootstrap
  File "/home/travis/virtualenv/pypy-2.5.0/site-packages/couchbase/_bootstrap.py", line 34, in <module>
    import couchbase.exceptions as E
  File "/home/travis/virtualenv/pypy-2.5.0/site-packages/couchbase/exceptions.py", line 18, in <module>
    import couchbase._libcouchbase as C
ImportError: No module named couchbase._libcouchbase

我已经尝试安装couchbase_cffi,但看起来_libcouchbase.so文件仍然缺失。

建立链接:https://travis-ci.org/ardydedase/pycouchbase/jobs/75973023#L1782

Travis配置文件:

# Config file for automatic testing at travis-ci.org

language: python

python:
  - "3.4"
  - "3.3"
  - "2.7"
  - "2.6"
  - "pypy"

before_install:
  - sudo rm -rf /etc/apt/sources.list.d/*
  - sudo add-apt-repository -y ppa:pypy/ppa
  - wget -O- http://packages.couchbase.com/ubuntu/couchbase.key | sudo apt-key add -
  - echo deb http://packages.couchbase.com/ubuntu precise precise/main | sudo tee /etc/apt/sources.list.d/couchbase.list
  - sudo apt-get update
  - sudo apt-cache search libcouchbase

install:
  # GCC
  - sudo apt-get install python-software-properties
  - sudo add-apt-repository -y ppa:ubuntu-toolchain-r/test
  - sudo apt-get update
  - sudo apt-get -y install gcc-4.8
  - sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-4.8 50
  # libcouchbase dependencies
  - sudo apt-get -y install libxml2-dev libxslt-dev python-all-dev libffi6 libffi-dev 
  - sudo apt-get -y install build-essential libssl-dev python-openssl
  - sudo apt-get -y install libcouchbase-dev libcouchbase2-core libcouchbase2-libevent libevent-dev python-gevent
  - pip -q install gevent || echo "Couldn't find gevent"
  - pip -q install twisted
  - pip -q install testresources
  - pip install -r requirements.txt

# command to run tests, e.g. python setup.py test
script: 
  # - cd couchbase-python-cffi
  # - export CFLAGS=-Qunused-arguments
  # - export CPPFLAGS=-Qunused-arguments
  # - python setup.py test  
  # - python setup.py build
  - echo $PWD
  # - if [[ $TRAVIS_PYTHON_VERSION == pypy ]]; then git clone https://github.com/couchbase/couchbase-python-client.git && cd couchbase-python-client && python setup.py build_ext --inplace && cd ..; fi
  - if [[ $TRAVIS_PYTHON_VERSION == pypy ]]; then cd couchbase-python-cffi && python setup.py build  && python setup.py install && cd .. && ls -al; fi  
  - if [[ $TRAVIS_PYTHON_VERSION == pypy ]]; then ls -al /home/travis/virtualenv/pypy-2.5.0/site-packages/couchbase; fi
  - python -c "from tests import test_pycouchbase; print(test_pycouchbase)"  
  - python runtests.py

我确实尝试引用此主题:https://forums.couchbase.com/t/installing-couchbase-1-0-0-on-ubuntu/291,但我找不到那里引用的build文件夹。

1 个答案:

答案 0 :(得分:2)

如果使用cffi模块,必须先 import couchbase_ffi。原因是couchbase_ffi将自己注入couchbase._libcouchbase模块。

在“普通”扩展名下,couchbase._libcouchbase包含构建的普通CPython扩展代码。由于CPyext在pypy下并不真正起作用,因此在该平台上禁用了代码的构建,并且您需要事先“注入”ffi模块。

不可否认,这是一个烦人的步骤,而不是最“透明”。你可以做类似......(未经测试的!!!):try import couchbase; except ImportError: import couchbase_ffi