Python SDK on Ubuntu 14

I was unable to install python library for couchbase on Ubuntu 14.

Server installation is OK and I could use it via the console.

During installation of library i have faced several obstacles and often have been unable to find appropriate resources.

Since recommended method published on developers Python pages completely failed, I conducted further investigation about resources and where to find them. After a while I have concluded that I have to install libcouchbase-devel bundle of linux libraries onto my system.

There was some struggle to find these libraries (as they are virtually non existent on ubuntu official mirrors and even PPA’s and very hard to find on developers site) I have read several stack overflow qa’s and none of them described even remotely issues I am encountering.

i have finally managed to locate page where there are different releases of libcouchbase-devel and I have tried and successfully installed libcouchbase-devel-2.1.0-1.x86_64 (apart from some other dependences it requires).

But in spite of that the underlying shared library was available python’s PIP is still giving me trouble in trying to compile python library (to the certain extent I am expecting to see more pure python library than shared library use but… hey, it is better to be working first)

From my side it looks as if Python SDK is dropped out from the fashion as even some programming drop-downs around developers site skip Python giving typically, Java, .net, Go and sometimes some other SDK.

IMHO Python couchbase is essential due python’s ability to quickly and easily deal with the data which makes it ideal candidate for populating couchbase buckets with the data for data mining or other data investigations for which I find couchbase almost ideally suitable and rare tool.

Thanks for listening. For that matter Python is not even available in tags. Are you trying to phase out Python altogether?

Hi Sorry you’ve run into trouble!

Addressing the questions roughly in order, the Start using the Python SDK documentation page does describe how to install libcouchbase on ubuntu including libcouchbase-dev packages. Couchbase maintains an apt-get repository with these libs. This is the primary source documentation, so any help in updating things like stackoverflow to point to the primary source would be appreciated.

My guess is you ended up on possibly the wrong path by looking at old resources on the 'net, rather than hitting the primary source at

With regard to pip not compiling, it could be related to the rather old version of lcb you’ve installed. The current version is 2.7.6 as covered in the Release Notes and Archives page, which also has links to packages and source. Version 2.1.0 was released in August 2013!

What was the error you ran into? I can probably help more if you post something that describes what you saw in your environment.

We do use libcouchbase intentionally with the Python client, as it gives us excellent performance and compatibility. This does make the installation require those dependencies, but we do some very advanced things like allowing real concurrency in threaded python programs by carefully unlocking/locking the GIL while running evented IO.

Python is not being phased out. We use Python extensively at Couchbase internally. As a matter of fact, we have a current open position to join the team to help improve Python. We’d appreciate any referrals! :slight_smile:

Thank you for replying.

most likely i went down to some previous version (from another available resources) because recipe as given did not work for me. I have just tried to follow up …

1. wget - DONE
2. sudo dpkg -i couchbase-release-1.0-2-amd64.deb - DONE
3. sudo apt-get update

got this at the end of the update:

Fetched 6,688 kB in 11s (571 kB/s)                                             
Reading package lists... Done
W: GPG error: trusty InRelease: The following signatures couldn't be verified because the public key is not available: NO_PUBKEY 6EF1EAC479CF7903

I guesss I need a proper public key to download. If I would have a key to do it.

~/dev/couch$ sudo apt-get install libcouchbase-dev libcouchbase2-bin build-essential
[sudo] password for xxx: 
Reading package lists... Done
Building dependency tree       
Reading state information... Done
build-essential is already the newest version.
libcouchbase-dev is already the newest version.
libcouchbase2-bin is already the newest version.
0 upgraded, 0 newly installed, 0 to remove and 3 not upgraded.

~/dev/couch$ python
Python 2.7.6 (default, Oct 26 2016, 20:30:19) 
[GCC 4.8.4] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> from couchbase.bucket import Bucket
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/xxx/.local/lib/python2.7/site-packages/couchbase/", line 28, in <module>
    from couchbase.user_constants import *
  File "/home/xxx/.local/lib/python2.7/site-packages/couchbase/", line 21, in <module>
    import couchbase._bootstrap
  File "/home/xxx/.local/lib/python2.7/site-packages/couchbase/", line 34, in <module>
    import couchbase.exceptions as E
  File "/home/xxx/.local/lib/python2.7/site-packages/couchbase/", line 18, in <module>
    import couchbase._libcouchbase as C
ImportError: /home/xxx/.local/lib/python2.7/site-packages/couchbase/ undefined symbol: PyUnicodeUCS2_AsUTF8String

Finally managed to make it working… not perfect, but fair enough.

Had to install alternative Python 2.7.13, in a way not to clash with system python installation.
Compilation/installation had some hitches - did not go smooth.


most helpful: sudo make altinstall

after that:

$ /usr/local/bin/python2.7 -m pip install couchbase
Requirement already satisfied: couchbase in /home/xxx/.local/lib/python2.7/site-packages

nice, fire Python:

$ /usr/local/bin/python2.7
Python 2.7.13 (default, Jul 30 2017, 14:01:53) 
[GCC 4.8.4] on linux2
Type "help", "copyright", "credits" or "license" for more information.

let’s try:

>>> from couchbase.bucket import Bucket

OK so far… start server (another terminal…)

$ sudo service couchbase-server start
* Started couchbase-server

continue with python …

>>> cb = Bucket('couchbase://localhost/default')
>>> cb.upsert('u:king_arthur', {'name': 'Arthur', 'email': '', 'email': '', 'interests': ['Holy Grail', 'African Swallows']})
OperationResult<rc=0x0, key=u'u:king_arthur', cas=0x14d6215254d60000>


Indexing did not work. Failed.

(checked in admin, index was already created, perhaps I created it already while tinkering with administration, I think deep down error also suggests that)

>>> cb.n1ql_query('CREATE PRIMARY INDEX ON default').execute()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/xxx/.local/lib/python2.7/site-packages/couchbase/", line 365, in execute
    for _ in self:
  File "/home/xxx/.local/lib/python2.7/site-packages/couchbase/", line 389, in __iter__
    raw_rows = self.raw.fetch(self._mres)
couchbase.exceptions.HTTPError: <RC=0x3B[HTTP Operation failed. Inspect status code for details], HTTP Request failed. Examine 'objextra' for full result, Results=1, C Source=(src/http.c,140), OBJ=ViewResult<rc=0x3B[HTTP Operation failed. Inspect status code for details], value={u'status': u'errors', u'errors': [{u'msg': u'GSI CreatePrimaryIndex() - cause: Index default.#primary already exists', u'code': 5000}], u'results': [], u'metrics': {u'elapsedTime': u'2.32618749s', u'executionTime': u'2.266885629s', u'resultSize': 0, u'resultCount': 0, u'errorCount': 1}, u'requestID': u'7d425eeb-7b5d-4b23-9c87-9cbfee0f73ff', u'signature': None}, http_status=500>>

Let’s Query:

>>> from couchbase.n1ql import N1QLQuery
>>> row_iter = cb.n1ql_query(N1QLQuery('SELECT name FROM default WHERE $1 IN interests', 'African Swallows'))
>>> row_iter
<couchbase.n1ql.N1QLRequest object at 0x7fc6b83bff50>
>>> for row in row_iter: print row
{u'name': u'Arthur'}

Good. Worked. Enough for fiddling around.

Any suggestions on how it could have been better are welcome