Installing couchbase-1.0.0 on Ubuntu

Hello,

I am trying to install couchbase sdk (1.0.0) on my Ubuntu machine. But although setup.py install exited without any error but now when I do “from couchbase import Couchbase” it gives me an error:

Python 2.7.3 (default, Apr 10 2013, 06:20:15)
[GCC 4.6.3] on linux2
Type “help”, “copyright”, “credits” or “license” for more information.

from couchbase import Couchbase
Traceback (most recent call last):
File “”, line 1, in
File “couchbase/init.py”, line 18, in
from couchbase.connection import Connection
File “couchbase/connection.py”, line 22, in
import couchbase._bootstrap
File “couchbase/_bootstrap.py”, line 34, in
import couchbase.exceptions as E
File “couchbase/exceptions.py”, line 18, in
import couchbase._libcouchbase as C
ImportError: No module named _libcouchbase

And here is the output from the “setup.py install” :

running install Checking .pth file support in /usr/local/lib/python2.7/dist-packages/ /usr/bin/python -E -c pass TEST PASSED: /usr/local/lib/python2.7/dist-packages/ appears to support .pth files running bdist_egg running egg_info writing couchbase.egg-info/PKG-INFO writing top-level names to couchbase.egg-info/top_level.txt writing dependency_links to couchbase.egg-info/dependency_links.txt reading manifest file 'couchbase.egg-info/SOURCES.txt' writing manifest file 'couchbase.egg-info/SOURCES.txt' installing library code to build/bdist.linux-x86_64/egg running install_lib running build_py running build_ext building 'couchbase._libcouchbase' extension gcc -pthread -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -fPIC -I/usr/include/python2.7 -c src/argument.c -o build/temp.linux-x86_64-2.7/src/argument.o gcc -pthread -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -fPIC -I/usr/include/python2.7 -c src/exceptions.c -o build/temp.linux-x86_64-2.7/src/exceptions.o gcc -pthread -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -fPIC -I/usr/include/python2.7 -c src/ext.c -o build/temp.linux-x86_64-2.7/src/ext.o gcc -pthread -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -fPIC -I/usr/include/python2.7 -c src/result.c -o build/temp.linux-x86_64-2.7/src/result.o gcc -pthread -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -fPIC -I/usr/include/python2.7 -c src/opresult.c -o build/temp.linux-x86_64-2.7/src/opresult.o gcc -pthread -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -fPIC -I/usr/include/python2.7 -c src/callbacks.c -o build/temp.linux-x86_64-2.7/src/callbacks.o gcc -pthread -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -fPIC -I/usr/include/python2.7 -c src/convert.c -o build/temp.linux-x86_64-2.7/src/convert.o gcc -pthread -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -fPIC -I/usr/include/python2.7 -c src/connection.c -o build/temp.linux-x86_64-2.7/src/connection.o gcc -pthread -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -fPIC -I/usr/include/python2.7 -c src/store.c -o build/temp.linux-x86_64-2.7/src/store.o gcc -pthread -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -fPIC -I/usr/include/python2.7 -c src/constants.c -o build/temp.linux-x86_64-2.7/src/constants.o gcc -pthread -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -fPIC -I/usr/include/python2.7 -c src/multiresult.c -o build/temp.linux-x86_64-2.7/src/multiresult.o gcc -pthread -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -fPIC -I/usr/include/python2.7 -c src/miscops.c -o build/temp.linux-x86_64-2.7/src/miscops.o gcc -pthread -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -fPIC -I/usr/include/python2.7 -c src/typeutil.c -o build/temp.linux-x86_64-2.7/src/typeutil.o gcc -pthread -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -fPIC -I/usr/include/python2.7 -c src/oputil.c -o build/temp.linux-x86_64-2.7/src/oputil.o gcc -pthread -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -fPIC -I/usr/include/python2.7 -c src/get.c -o build/temp.linux-x86_64-2.7/src/get.o gcc -pthread -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -fPIC -I/usr/include/python2.7 -c src/arithmetic.c -o build/temp.linux-x86_64-2.7/src/arithmetic.o gcc -pthread -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -fPIC -I/usr/include/python2.7 -c src/http.c -o build/temp.linux-x86_64-2.7/src/http.o gcc -pthread -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -fPIC -I/usr/include/python2.7 -c src/htresult.c -o build/temp.linux-x86_64-2.7/src/htresult.o gcc -pthread -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -fPIC -I/usr/include/python2.7 -c src/ctranscoder.c -o build/temp.linux-x86_64-2.7/src/ctranscoder.o gcc -pthread -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -fPIC -I/usr/include/python2.7 -c src/observe.c -o build/temp.linux-x86_64-2.7/src/observe.o gcc -pthread -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -fPIC -I/usr/include/python2.7 -c src/viewrow/viewrow.c -o build/temp.linux-x86_64-2.7/src/viewrow/viewrow.o gcc -pthread -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -fPIC -I/usr/include/python2.7 -c src/contrib/jsonsl/jsonsl.c -o build/temp.linux-x86_64-2.7/src/contrib/jsonsl/jsonsl.o gcc -pthread -shared -Wl,-O1 -Wl,-Bsymbolic-functions -Wl,-Bsymbolic-functions -Wl,-z,relro build/temp.linux-x86_64-2.7/src/argument.o build/temp.linux-x86_64-2.7/src/exceptions.o build/temp.linux-x86_64-2.7/src/ext.o build/temp.linux-x86_64-2.7/src/result.o build/temp.linux-x86_64-2.7/src/opresult.o build/temp.linux-x86_64-2.7/src/callbacks.o build/temp.linux-x86_64-2.7/src/convert.o build/temp.linux-x86_64-2.7/src/connection.o build/temp.linux-x86_64-2.7/src/store.o build/temp.linux-x86_64-2.7/src/constants.o build/temp.linux-x86_64-2.7/src/multiresult.o build/temp.linux-x86_64-2.7/src/miscops.o build/temp.linux-x86_64-2.7/src/typeutil.o build/temp.linux-x86_64-2.7/src/oputil.o build/temp.linux-x86_64-2.7/src/get.o build/temp.linux-x86_64-2.7/src/arithmetic.o build/temp.linux-x86_64-2.7/src/http.o build/temp.linux-x86_64-2.7/src/htresult.o build/temp.linux-x86_64-2.7/src/ctranscoder.o build/temp.linux-x86_64-2.7/src/observe.o build/temp.linux-x86_64-2.7/src/viewrow/viewrow.o build/temp.linux-x86_64-2.7/src/contrib/jsonsl/jsonsl.o -lcouchbase -o build/lib.linux-x86_64-2.7/couchbase/_libcouchbase.so creating build/bdist.linux-x86_64 creating build/bdist.linux-x86_64/egg creating build/bdist.linux-x86_64/egg/couchbase copying build/lib.linux-x86_64-2.7/couchbase/_pyport.py -> build/bdist.linux-x86_64/egg/couchbase copying build/lib.linux-x86_64-2.7/couchbase/exceptions.py -> build/bdist.linux-x86_64/egg/couchbase copying build/lib.linux-x86_64-2.7/couchbase/connection.py -> build/bdist.linux-x86_64/egg/couchbase copying build/lib.linux-x86_64-2.7/couchbase/_libcouchbase.so -> build/bdist.linux-x86_64/egg/couchbase copying build/lib.linux-x86_64-2.7/couchbase/_version.py -> build/bdist.linux-x86_64/egg/couchbase copying build/lib.linux-x86_64-2.7/couchbase/__init__.py -> build/bdist.linux-x86_64/egg/couchbase copying build/lib.linux-x86_64-2.7/couchbase/transcoder.py -> build/bdist.linux-x86_64/egg/couchbase copying build/lib.linux-x86_64-2.7/couchbase/user_constants.py -> build/bdist.linux-x86_64/egg/couchbase copying build/lib.linux-x86_64-2.7/couchbase/admin.py -> build/bdist.linux-x86_64/egg/couchbase copying build/lib.linux-x86_64-2.7/couchbase/result.py -> build/bdist.linux-x86_64/egg/couchbase creating build/bdist.linux-x86_64/egg/couchbase/views copying build/lib.linux-x86_64-2.7/couchbase/views/__init__.py -> build/bdist.linux-x86_64/egg/couchbase/views copying build/lib.linux-x86_64-2.7/couchbase/views/iterator.py -> build/bdist.linux-x86_64/egg/couchbase/views copying build/lib.linux-x86_64-2.7/couchbase/views/params.py -> build/bdist.linux-x86_64/egg/couchbase/views copying build/lib.linux-x86_64-2.7/couchbase/_bootstrap.py -> build/bdist.linux-x86_64/egg/couchbase byte-compiling build/bdist.linux-x86_64/egg/couchbase/_pyport.py to _pyport.pyc byte-compiling build/bdist.linux-x86_64/egg/couchbase/exceptions.py to exceptions.pyc byte-compiling build/bdist.linux-x86_64/egg/couchbase/connection.py to connection.pyc byte-compiling build/bdist.linux-x86_64/egg/couchbase/_version.py to _version.pyc byte-compiling build/bdist.linux-x86_64/egg/couchbase/__init__.py to __init__.pyc byte-compiling build/bdist.linux-x86_64/egg/couchbase/transcoder.py to transcoder.pyc byte-compiling build/bdist.linux-x86_64/egg/couchbase/user_constants.py to user_constants.pyc byte-compiling build/bdist.linux-x86_64/egg/couchbase/admin.py to admin.pyc byte-compiling build/bdist.linux-x86_64/egg/couchbase/result.py to result.pyc byte-compiling build/bdist.linux-x86_64/egg/couchbase/views/__init__.py to __init__.pyc byte-compiling build/bdist.linux-x86_64/egg/couchbase/views/iterator.py to iterator.pyc byte-compiling build/bdist.linux-x86_64/egg/couchbase/views/params.py to params.pyc byte-compiling build/bdist.linux-x86_64/egg/couchbase/_bootstrap.py to _bootstrap.pyc creating stub loader for couchbase/_libcouchbase.so byte-compiling build/bdist.linux-x86_64/egg/couchbase/_libcouchbase.py to _libcouchbase.pyc creating build/bdist.linux-x86_64/egg/EGG-INFO copying couchbase.egg-info/PKG-INFO -> build/bdist.linux-x86_64/egg/EGG-INFO copying couchbase.egg-info/SOURCES.txt -> build/bdist.linux-x86_64/egg/EGG-INFO copying couchbase.egg-info/dependency_links.txt -> build/bdist.linux-x86_64/egg/EGG-INFO copying couchbase.egg-info/top_level.txt -> build/bdist.linux-x86_64/egg/EGG-INFO writing build/bdist.linux-x86_64/egg/EGG-INFO/native_libs.txt zip_safe flag not set; analyzing archive contents... creating dist creating 'dist/couchbase-1.0.0-py2.7-linux-x86_64.egg' and adding 'build/bdist.linux-x86_64/egg' to it removing 'build/bdist.linux-x86_64/egg' (and everything under it) Processing couchbase-1.0.0-py2.7-linux-x86_64.egg creating /usr/local/lib/python2.7/dist-packages/couchbase-1.0.0-py2.7-linux-x86_64.egg Extracting couchbase-1.0.0-py2.7-linux-x86_64.egg to /usr/local/lib/python2.7/dist-packages Removing couchbase 0.8.2 from easy-install.pth file Adding couchbase 1.0.0 to easy-install.pth file

Installed /usr/local/lib/python2.7/dist-packages/couchbase-1.0.0-py2.7-linux-x86_64.egg
Processing dependencies for couchbase==1.0.0
Finished processing dependencies for couchbase==1.0.0

Not sure whats going wrong at this point now, I have also installed libcouchbase using the apt-get command.

Please advise.

Thanks!!

If you’re in tl;dr mode, just exit the source directory and importing the module should work. The following is an explanation as to why.

You are most likely running this python console from within the build directory. In this case when you do ‘import couchbase’, Python first checks your current directory for a

couchbase/init.py
file, and if found; loads that.

Because Python cannot have different directories hosting the same namespace, it uses the

couchbase
directory in your current working directory (i.e.)
couchbase-1.0.0
. When you import it, it will search for the
$PWD/couchbase/_libcouchbase.so
file, which is not there.

The reason is because extension modules by default are placed in the

$PWD/build
directory.

If you exit the source directory, your module will load properly as Python will not try to load the “unbuilt” extension. Optionally you can copy the

_libcouchbase.co
from the
build
directory into the
couchbase
directory within the source tree, OR use
python setup.py build_ext --inplace
which will ensure the
_libcouchbase.so
is also in the appropriate location within the source directory.

Thanks mnuberg for the explanation, it worked :slight_smile: