ImportError: No module named couchbase._libcouchbase

≯℡__Kan透↙ 提交于 2020-01-06 02:16:26

问题


This only happens for me in Travis under the pypy build. Here's the exact error string:

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

I'm already trying to install couchbase_cffi, but it looks like _libcouchbase.so file is still missing.

Link to build: https://travis-ci.org/ardydedase/pycouchbase/jobs/75973023#L1782

Travis config file:

# 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

I did try to refer to this thread: https://forums.couchbase.com/t/installing-couchbase-1-0-0-on-ubuntu/291, but I can't find the build folder that is being referred in there.


回答1:


If using the cffi module, you must import couchbase_ffi before anything else. The reason is that couchbase_ffi injects itself as the couchbase._libcouchbase module.

Under the "normal" extension, couchbase._libcouchbase contains the normal CPython extension code which is built. Since CPyext doesn't really work under pypy, the building of the code is disabled on that platform, and you are required to "inject" the ffi module beforehand.

Admittedly it's an annoying step and not the most 'transparent'. You might be able to do something like.. (untested!!!): try import couchbase; except ImportError: import couchbase_ffi



来源:https://stackoverflow.com/questions/32056557/importerror-no-module-named-couchbase-libcouchbase

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!