PyAlembic import quirk

1,428 views
Skip to first unread message

Andrew Harvey

unread,
Sep 23, 2012, 10:51:33 AM9/23/12
to alembic-d...@googlegroups.com
Hi again,

Now that I've built the Alembic Python bindings, I'm attempting to
import them with the following:

>>> import alembic
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: 'NoneType' object has no attribute 'BaseExc'


The following does work though:

>>> import imath
>>> import alembic

My guess is that the alembic module is failing to properly load the
imath module.

I also tried this:

>>> import iex
>>> import alembic
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: No Python class registered for C++ class PyImath::FixedArray<bool>


As far as I can tell, the build scripts are able to find all the
suitable libraries and modules.

- Andrew

Barnaby Robson

unread,
Sep 24, 2012, 12:09:27 PM9/24/12
to alembic-d...@googlegroups.com
Hey Andrew,

This is somewhat expected. The bindings are written with a hard
dependency that imath must be imported first and that's why line 116 of
python/PyAlembic/main.cpp is this:

handle<> imath( PyImport_ImportModule( "imath" ) );

So now we have to determine why that didn't work for you. When we were
developing the bindings we hit two classes of errors relating to this.
One was when the wrong version of imath was found and loaded on the path
and the error for that looked a lot like your one when you imported iex
first.

The second one was related to an issue where our sitecustomize wasn't
being run in some python versions and imath would fail to automatically
open. The important lines for us are these (on linux):

import DLFCN
import sys
sys.setdlopenflags(DLFCN.RTLD_NOW | DLFCN.RTLD_GLOBAL)

If both the above are irrelevant you may have hit a 3rd kind of issue.

barnaby.

Mark

unread,
Oct 19, 2012, 2:56:54 PM10/19/12
to alembic-d...@googlegroups.com
Hello,

The 'import DLFCN' stuff fixed an import problem I reported here: https://groups.google.com/forum/?hl=en&fromgroups=#!topic/alembic-discussion/OMOvhg0Nv7o

Is there a way to see when the sitecustomize isn't being run in your python version?

mark floyd

unread,
Oct 19, 2012, 5:13:57 PM10/19/12
to alembic-d...@googlegroups.com
Please note we can not import symbols into the global namespace - the setdlopenflags trick does allow us to import imath, but it will cause more problems than it solves due to all of our third party plugins.

We could use an explanation of "sitecustomize" and how we can get it working (in Python 2.6.4+)

--
 
 

Barnaby Robson

unread,
Oct 19, 2012, 8:17:19 PM10/19/12
to alembic-d...@googlegroups.com
When python initializes it loads site.py. "sitecustomize" is just one of the scripts that our site.py references to initialize our python runtime, other facilities will have different scripts.  python -v will show you everything that is happening at python startup.

I actually don't have a solution for you if you cannot set those dl open flags.  Those flags are just a necessary part of using c++ extensions with python that use type id based type translation (like boost python does).

We haven't run into issues like you mention but maybe we don't have as much experience with 3rd party plugins.  Are there particular ones that you are having issues with in regards to that setting ?  Do you have to have multiple copies of the same library loaded at run time ?

barnaby.
--
 
 


Mark

unread,
Oct 19, 2012, 9:56:31 PM10/19/12
to alembic-d...@googlegroups.com
We had all sorts of problems with symbol collisions and other fallout from global symbols in our software environment - which is why we spent 3+ years flushing out python code that had imported into the global namespace. 

With the patch I applied in my link, everything appears to be working just fine (based on tests run by production thus far).  Is the exception registration code the only thing that relies on loading symbols into the global namespace?

Shih-Chin

unread,
Oct 24, 2012, 1:58:12 AM10/24/12
to alembic-d...@googlegroups.com
Hi Mark,

Thanks for the sharing. I've applied your patch for imathmodule, but I still get the same error on Windows:

>>> import alembic
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: No Python class registered for C++ class class PyImath::FixedArray<bool>

I've also tried to import iex and imath before importing the alembic module, and still got no luck.
Did I miss anything? Thanks in advance.

Shih-Chin

Mark於 2012年10月20日星期六UTC+8上午9時56分31秒寫道:

Mark

unread,
Oct 24, 2012, 2:14:46 AM10/24/12
to alembic-d...@googlegroups.com

Caroline B.

unread,
Feb 19, 2016, 9:59:25 AM2/19/16
to alembic-discussion, emfl...@gmail.com
Hi,

Sorry to unbury this post :)
I recently faced the same problem and had a hard time finding a viable solution to make pyalembic working, without any imath issue. So in case someone finds this post looking for a solution, here's why I did that worked for me:

  1. according to Ryan Galloway here (https://groups.google.com/d/msg/alembic-discussion/jLwgzpZRjus/_FpsojzfM0QJ), the compatible boost for python bindings is from 1.48 to 1.52, I personnally used the 1.48.
  2. during compilation of pyilmbase and pyalembic I got a _POSIX_C_SOURCE and _XOPEN_SOURCE warning like here (http://stackoverflow.com/questions/10056393/g-with-python-h-how-to-compile), so I did what they say in the post and put all Python.h and boost/python/* headers on top of all headers in both Ilmbase and Alembic files

I recompiled everything and now the alembic module is working like a charm, loading ilmbase by itself.
Hope this helps :)

Caro

Ryan Galloway

unread,
Feb 19, 2016, 1:39:44 PM2/19/16
to alembic-d...@googlegroups.com, emfl...@gmail.com

Hi Caroline,

Thanks for the tip. This thread is quite old, and I think at the time I had only tested a few versions of boost. If you're having issues with more recent versions then that's something we'll probably want to look into.

Just curious, which Alembic release are you building? Have you tried using the latest pre-release code from the github repo? Do you have a clone with the updated includes that we could take a look at? 

Thanks,

Ryan


--
You received this message because you are subscribed to the Google Groups "alembic-discussion" group.
To unsubscribe from this group and stop receiving emails from it, send an email to alembic-discuss...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Caroline B.

unread,
Mar 8, 2016, 12:06:46 PM3/8/16
to alembic-discussion
Hello Ryan,

Sorry for the late answer.

Yes, I used the pre-release from the github repo (last commit at the time I got it: the pull-request #50 from AardmanCGI). Actually turned out we had some conflicting issues with the boost I was using, but it's OK now. I finally retried and I was able to compile and make pyalembic to work with both boost-1.55 and boost-1.60. So, I think for the imath from pyalembic error, the headers trick is enough. Any boost is fine :)

As for the updated includes, I forked the github repo on the private gitlab we use at work. And, and I'm so sorry for that :(, I've been told by big bosses not to share it. Still, if you want to, I can send you the includes by email. I just put whenever I saw "#include <Python.h>" and/or "#include <boost/python.hpp>" in a *.h on top of all the included files.

Caro
To unsubscribe from this group and stop receiving emails from it, send an email to alembic-discussion+unsub...@googlegroups.com.

timyan...@gmail.com

unread,
Nov 29, 2016, 6:43:28 PM11/29/16
to alembic-discussion
Another bump to this thread, just to provide help to people encountering this error when loading alembic python libraries in Maya.

I'm replacing the alembic python libraries that ship with Maya in favor of PyAlembic from the alembic github repo. When doing "import alembic" from within Maya I, too, was hit with "No Python class registered for C++ class PyImath::FixedArray<bool>"

The problem did indeed come down to imath library mismatch, as suggested above. Specifically, Maya ships with its own version of imath under the filename "imathmodule.so" (in linux).  Upon examining imathmodule.so symbols, I noticed the namespace "Imath_2_0" has been modified to "Alembic_Imath_2_0". Autodesk doesn't ship headers for this custom imath library, so unfortunately it's not trivial to build against it. 

My solution was:
1) Update the environment variable PYTHONPATH so my imath library is loaded instead of Maya's imathmodule.so
2) Call "import imath" before any call to "import alembic"

- Tim

Paul Molodowitch

unread,
Dec 9, 2016, 7:26:25 PM12/9/16
to alembic-discussion
So I ran into this as well, and dug into the issue a bit more, and have a patch that seems to fix it... though there's still a bit of a mystery as to why.

First, I was initially getting the exact same error as others here:

    AttributeError: 'NoneType' object has no attribute 'BaseExc' 

However, on investigation, I found I was actually dynamically linking to boost, when I intended to statically link.  Once I fixed that, though, I still had a similar, though slightly different error:

    AttributeError: 'NoneType' object has no attribute 'iex'

When I fired up a debugger, it seemed the error was on this line, in PyIlmBase/PyImath/imathmodule.cpp, in init_module_imath (created form the BOOST_PYTHON_MODULE(imath) macro):

    scope().attr("iex") = iex;    

The problem was that scope() was returning "None", when it should have been returning the scope for the imath module - which should be set up by boost::python::detail::init_module().  However, this didn't seem to be running properly.

However, when I simply "manually expanded" the BOOST_PYTHON_MODULE, and "manually inlined" boost::python::detail::init_module(), it magically started working. That's what the included patch file does.  I have no idea why this would make a difference - it should be essentially the same as what the macro expands out to.  It's possible it's some sort of bug with Boost.Python, or even with gcc itself... so here are the exact versions of everything I was using:

boost-1.55.0
gcc-4.8.3
ilmbase-2.2.0
alembic-1.5.8

These versions were picked for compatibility with the vfx reference platform, CY2016: http://www.vfxplatform.com/

Anyway, perhaps this patch will help someone, or someone else will be able to dig deeper and figure out why the BOOST_PYTHON_MODULE(imath) version doesn't work.  I'd be curious to see what happened with a different compiler, for instance (say, clang).

- Paul
fix_pyalembic_imath_import.patch
Reply all
Reply to author
Forward
0 new messages