{"id":256,"date":"2005-01-10T07:37:00","date_gmt":"2005-01-10T07:37:00","guid":{"rendered":"http:\/\/jclark.org\/weblog\/Apple\/OSX\/dbxml2-py-osx.html"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-30T04:00:00","slug":"dbxml2-py-osx","status":"publish","type":"post","link":"https:\/\/jclark.org\/weblog\/2005\/01\/10\/dbxml2-py-osx\/","title":{"rendered":"HOWTO: Build DB XML 2.0 with Python Bindings on OS X"},"content":{"rendered":"<p><a href=\"http:\/\/www.sleepycat.com\">Sleepycat Software<\/a> recently released <a href=\"http:\/\/www.sleepycat.com\/products\/xml.shtml\">Berkeley DB XML 2.0<\/a>, a native XML database built on top of <a href=\"http:\/\/www.sleepycat.com\/products\/db.shtml\">Berkley DB<\/a>.  The major change from DB XML 1 to 2 is the addition of <a href=\"http:\/\/www.w3.org\/TR\/xpath20\">XPath 2<\/a>. and <a href=\"http:\/\/www.w3.org\/TR\/xquery\/\">XQuery 1.0<\/a> support.  Here&#8217;s what I did to build and install DB XML 2.0 along with python bindings on OS X 10.3.7. <\/p>\n<p>Having previously built DB XML 1.0 on OS X, I was pleased to see that all of the prerequisite libraries (Xerces-C, Pathan 2, Berkeley DB) are now included in the DB XML source package.  After downloading the tarball from the website (see link above), extracting it and building everything was easy:\n%&gt; cd \/Users\/jclark\/ext\n%&gt; tar -xzf dbxml-2.0.9.tar.gz\n%&gt; cd dbxml-2.0.9\n%&gt; sh buildall.sh<\/p>\n<p>The <code>buildall.sh<\/code> script creates an <code>install<\/code> directory in the build root and installs all of the packages to this location.  This gave me the following dir structure:<\/p>\n<pre><code>  Users\n   + jclark\n      + ext\n         + dbxml-2.0.9\n            + install\n               + bin\n               + docs\n               + include\n               + lib<\/code><\/pre>\n<p>Next I wanted to build python support, which is not built by <code>buildall.sh<\/code>.  The README cautions that the python bindings require the <a href=\"http:\/\/pybsddb.sourceforge.net\/\">pybsddb package<\/a>, which ships with python 2.3 and later, but which must be compiled against the same version of Berkeley DB as XML DB (the XML DB package builds BDB 4.3.0 from source).  OS X 10.3 comes with python 2.3 installed, but the default copy of <code>bsddb<\/code> doesn&#8217;t seem to work.  I downloaded the pybsddb for BDB 4.3 from Sourceforge (via link above), and built it.  Because of the nonstandard install location used by <code>buildall.sh<\/code>, I had to pass an extra param (<code>--berkeley-db<\/code>) to <code>setup.py<\/code>. :<\/p>\n<pre><code>  %&gt; cd \/Users\/jclark\/ext\n  %&gt; tar -xzf bsddb3-4.3.0\n  %&gt; cd bsddb3-4.3.0\n  %&gt; python setup.py --berkeley-db=\/Users\/jclark\/ext\/dbxml-2.0.9\/install\/ build\n  %&gt; python test.py\n  %&gt; python setup.py install<\/code><\/pre>\n<p>With a working <code>bsddb<\/code>, It was time to build XML DB&#8217;s python bindings.  As mentioned in the main README and in the <code>dbxml\/src\/python<\/code> README, the custom BDB\/DBXML\/etc install location requires an edit to <code>dbxml\/src\/python\/setup.py<\/code>. I adjusted the paths thusly:<\/p>\n<pre><code>  if os.name == &quot;posix&quot;:\n    db_home = &quot;\/Users\/jclark\/ext\/dbxml-2.0.9\/install&quot;\n    xerces_home = db_home\n    pathan_home = db_home\n    xquery_home = db_home<\/code><\/pre>\n<p>Building and installing was straightforward:<\/p>\n<pre><code>  %&gt; cd \/Users\/jclark\/ext\/dbxml-2.0.9\/src\/python\n  %&gt; python setup.py build\n  %&gt; python setup.py install<\/code><\/pre>\n<p>Time to test:<\/p>\n<pre><code>  %&gt; cd \/Users\/jclark\/ext\/dbxml-2.0.9\/dbxml\/examples\/python\n  %&gt; python examples.py test\n  Traceback (most recent call last):\n    File &quot;examples.py&quot;, line 6, in ?\n      from bsddb.db import *\n    File &quot;\/System\/Library\/Frameworks\/Python.framework\/Versions\/2.3\/lib\/\n        python2.3\/bsddb\/__init__.py&quot;, line 40, in ?\n      import _bsddb\n  ImportError: No module named _bsddb<\/code><\/pre>\n<p>Uh-oh.  However, a quick look inside <code>examples.py<\/code> reveals the solution.  The import from <code>bsddb.db<\/code> applies when using the version of pybsddb that ships with python; when using a custom pybsddb build you must import from <code>bsddb3<\/code>.  This involved commenting out one line and uncommenting another in <code>examples.py<\/code>.  Let&#8217;s try again:<\/p>\n<pre><code>  %&gt; python examples.py test\n  Traceback (most recent call last):\n    File &quot;examples.py&quot;, line 7, in ?\n      from dbxml import *\n    File &quot;\/System\/Library\/Frameworks\/Python.framework\/Versions\/2.3\/lib\/\n        python2.3\/site-packages\/dbxml.py&quot;, line 5, in ?\n      import _dbxml\n  ImportError: Failure linking new module: libxerces-c.26.dylib: dyld: \n        python can&#039;t open library: libxerces-c.26.dylib  \n        (No such file or directory, errno = 2)<\/code><\/pre>\n<p>Still no joy in Mudville.  It&#8217;s at this point that I began to have trouble with how to proceed; my knowledge of *nix linking, loading, and such is limited.  My rough understanding of dylibs is that they are dynamically linked libraries, a bit like Windows DLLs.  The errors above (a couple of newlines were added for formatting) seem to indicate that the <code>xerces-c<\/code> lib can&#8217;t be located.  I checked the output from building <code>dbxml.py<\/code> and confirmed that the correct (to my untrained eye) <code>-l<\/code>\nand <code>-L<\/code> flags were used to locate all of the required libs from <code>\/Users\/jclark\/ext\/dbxml-2.0.9\/install\/libs<\/code>.  <\/p>\n<p>My problem was, I didn&#8217;t really understand the dyld process.  It was unclear to me whether dynamically linked libraries have the library location linked into the executable (as I suspected, but which didn&#8217;t explain the error) or if they rely on a search path (which probably defaults to <code>\/usr\/lib<\/code> or somesuch).  In the end, <code>man dyld<\/code> proved somewhat enlightening.  It turns out that there&#8217;s a slew of environment variables which can influence the locations searched for dylibs.  It also turns out that <code>otool -L<\/code> can reveal information about linked libraries.  Let&#8217;s see what we can learn (the two-step <code>cd<\/code> avoids a linebreak):<\/p>\n<pre><code>  %&gt; cd \/System\/Library\/Frameworks\/Python.framework\/Versions\/2.3\/lib\/\n  %&gt; cd python2.3\/site-packages\n  %&gt; otool -L _dbxml.so\n    \/System\/Library\/Frameworks\/Python.framework\/Versions\/2.3\/Python \n        (compatibility version 2.3.0, current version 2.3.0)\n    \/Users\/jclark\/ext\/dbxml-2.0.9\/install\/lib\/libdbxml-2.0.dylib \n        (compatibility version 0.0.0, current version 0.0.0)\n    \/Users\/jclark\/ext\/dbxml-2.0.9\/install\/lib\/libdb_cxx-4.3.dylib \n        (compatibility version 0.0.0, current version 0.0.0)\n    \/Users\/jclark\/ext\/dbxml-2.0.9\/install\/lib\/libxquery-1.0.dylib \n        (compatibility version 0.0.0, current version 0.0.0)\n    \/Users\/jclark\/ext\/dbxml-2.0.9\/install\/lib\/libpathan.3.dylib \n        (compatibility version 4.0.0, current version 4.1.0)\n    libxerces-c.26.dylib \n        (compatibility version 0.0.0, current version 0.0.0)\n    \/usr\/lib\/libSystem.B.dylib \n        (compatibility version 1.0.0, current version 71.1.1)<\/code><\/pre>\n<p>For some reason, <code>libxerces-c<\/code> was linked without path information, unlike all of the other libraries.  If anyone knows why this happened, or how to avoid it, please <a href=\"mailto::jason@jclark.org\">email me<\/a> or leave a comment.  I couldn&#8217;t determine how to change this, so I set an evironmental variable to provide the correct search path:<\/p>\n<pre><code>  %&gt; setenv DYLD_LIBRARY_PATH \/Users\/jclark\/ext\/dbxml-2.0.9\/install\/lib\n  %&gt; python examples.py test<\/code><\/pre>\n<p>Success!  <\/p>\n<p>As I said earlier, I&#8217;m a bit under-experienced with some of the details of building software on *nix systems.  If anyone can provide any help with the <code>xerces-c<\/code> dylib issue, or any improvements to these directions, let me know; I&#8217;ll update this post with any additional information I find\/receive.<\/p>","protected":false},"excerpt":{"rendered":"<p>Sleepycat Software recently released Berkeley DB XML 2.0, a native XML database built on top of Berkley DB. The major change from DB XML 1 to 2 is the addition of XPath 2. and XQuery 1.0 support. Here&#8217;s what I did to build and install DB XML 2.0 along with python bindings on OS X [&hellip;]<\/p>","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[15],"tags":[],"class_list":["post-256","post","type-post","status-publish","format-standard","hentry","category-osx"],"_links":{"self":[{"href":"https:\/\/jclark.org\/weblog\/wp-json\/wp\/v2\/posts\/256","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/jclark.org\/weblog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/jclark.org\/weblog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/jclark.org\/weblog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/jclark.org\/weblog\/wp-json\/wp\/v2\/comments?post=256"}],"version-history":[{"count":0,"href":"https:\/\/jclark.org\/weblog\/wp-json\/wp\/v2\/posts\/256\/revisions"}],"wp:attachment":[{"href":"https:\/\/jclark.org\/weblog\/wp-json\/wp\/v2\/media?parent=256"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/jclark.org\/weblog\/wp-json\/wp\/v2\/categories?post=256"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/jclark.org\/weblog\/wp-json\/wp\/v2\/tags?post=256"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}