2

I have a Python library that depends on a C library, so I'm using Cython to deal with it. While I've managed to wrap the library and it's ready for installation, I've been facing a strange problem (note: for the sake of non-advertising I'm not using the name of the library).

I have the following directory structure:

package/
       setup.py
       library/
              __init__.py
              module/
                    lib.py
                    _lib.pyx

The setup.py is supposed to convert _lib.pyx into _lib.so, which can be easily imported by Python. Also, library.module is supposed to be installed as a namespace package, so lib.__init__.py contains the single line of code required by PEP420.

__import__('pkg_resources').declare_namespace(__name__)

But when I do:

python setup.py install

and after checking the .egg created I find a _lib.py created inside module with the following lines in it

def __bootstrap__():
   global __bootstrap__, __loader__, __file__
   import sys, pkg_resources, imp
   __file__ = pkg_resources.resource_filename(__name__,'_lib.so')
   __loader__ = None; del __bootstrap__, __loader__
   imp.load_dynamic(__name__,__file__)
__bootstrap__()

While _lib.py is present along with _lib.so, as soon as lib.py imports _lib, it imports the _lib.py file rather than importing _lib.so which is the actual Python wrapper of the C library.

I'd like to know why _lib.py is being created and how I can avoid it.

shuttle87
  • 15,466
  • 11
  • 77
  • 106
Himanshu Mishra
  • 8,510
  • 12
  • 37
  • 74
  • What exactly does *"the work is not possible to continue"* mean? – jonrsharpe Jun 26 '15 at 14:56
  • Sorry. That means, `lib.py` needs imports `_lib` module because that is the Python wrapper of the C library. But as soon as `import _lib` is done, it imports the `_lib.py` file rather than importing `_lib.so`. – Himanshu Mishra Jun 26 '15 at 15:24
  • Please edit that information into the question. – jonrsharpe Jun 26 '15 at 15:24
  • It seems cython creates it, but I'm having a problem with these files in cx_freeze ("resource_filename() only supported for .egg, not .zip"). Did you run into this? – e.tadeu Jan 13 '16 at 11:47

1 Answers1

1

It's now clear that the strange file being created with the same name as .so file, is not creating any problem. Infact that's necessary for the tighter integration with the .so module. So, It is automatically created while installing the file.

Himanshu Mishra
  • 8,510
  • 12
  • 37
  • 74