4

I'm trying to use thanos, which creates an extension module at runtime. Thanos is constantly failing as it cannot import that said extension it created at runtime.

I am baffled as to why this is the case.

At runtime (after compilation) the "cutils_ext" dir contains cutils_ext.so

import cutils_ext works, but import cutils_ext.cutils_ext fails with

ImportError: No module named cutils_ext

I've tested with with imp directly. Say that cutils is the imported cutils_ext package. When I do:

imp.find_module('cutils_ext', cutils.__path__)

I again get the :

ImportError: No module named cutils_ext

I am completely baffled. Is there any way to debug this? I cannot run python in verbose mode due to my inability to start the python interpreter (using picloud), but if I could enable verbose at runtime, that would help (haven't figured out how to do that).

3
  • 1
    Is the Python version that Thanos linked its module with the same as you are using? For example, the entry point protocol differes between Python 2 and Python 3. Commented Jun 29, 2012 at 7:03
  • Yes, all are python2.7. I was even able to download the extension to my own computer and load it directly. Either way, it seems the find_module is failing, even before the load occurs Commented Jun 29, 2012 at 22:59
  • Wow, my bad. Looks like I had another cutils_ext elsewhere on sys,path and Theano was preloading it. Filed a bug on Theano ( github.com/Theano/Theano/issues/728) Commented Jun 30, 2012 at 2:16

1 Answer 1

3

could you try:

import cutils_ext
import cutils_ext.cutils_ext

I don't know why, but sometimes I also have to import a module in order to import the sub modules in it.

Or maybe, just maybe, the second cutils_ext doesn't exist at all in the first cutils_ext?

EDIT: Wait a minute.. could you please post your folder structure and what the PYTHONPATH is containing?

I guess you have something like:

upper_folder (a folder)
    cutils_ext (folder)
        __init__.py (file)
        cutils_ext.so (obviously file)

if your PYTHONPATH points to upper_folder then you should be able to do what you have posted Note that if you have this situation the __ init __.py must be there.

If however your PYTHONPATH is pointing directly to the cutils_ext folder, then I supposed you can only import the file, so cutils_ext.cutils_ext doesn't make sense for the interpreter (unless you have a variable called cutils_ext in cutil_ext.so...)

Sign up to request clarification or add additional context in comments.

1 Comment

"Or maybe, just maybe, the second cutils_ext doesn't exist at all in the first cutils_ext?" Good call. It was very subtle as theano was preloading my cutils_ext package from another location, then patching sys.path. cutils_ext therefore referred to the wrong package. ugh.. thanks for the post.. helped a lot!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.