Can I install a shared C / C ++ library object in a Python virtual machine?

I am using a C ++ library that can be built as a Python module using SWIG.

Building a module results in a shared C ++ object, calls it libFoo.so

and a Python module, which includes both a Python file Foo.py

and some common object that Python uses to interact with libFoo.so

, which is called _Foo.so

.

Now I can sudo make install

both C ++ library and Python module and everything works fine if it loads Python and does import Foo

.

If I am sudo make install

a C ++ library and then install the Python module in virtualenv (by setting the Makefile so that it uses the virtual version of Python to run setup.py

) everything works as well. If I run Python from venv, I can import Foo and the C ++ library will load correctly. Outside of venv, I cannot import Foo.

Now I can build and install a C ++ library so that it installs itself in venv/lib

. Then I can build the Python package correctly and install it in virtualenv. If I run a virtual version of Python, the import of Foo fails due to a missing character, which apparently means it found Foo.py

and _Foo.so

but not libFoo.so

.

If i do

LD_PRELOAD=venv/lib/libFoo.so python

      

import completed successfully and the library is working correctly. (Note that there is nothing special about the directory in this case venv/lib

. I could also have installed the library somewhere completely different and passed the filename in that.)

However, I cannot get Python to look in the venv / lib folder for a C ++ shared object when trying to load that library. The installation LD_LIBRARY_PATH

doesn't seem to change anything, I believe, because either the virtual version of Python ignores this variable, or because there are settings in the Python module itself that dictate how the C ++ object should be loaded.

Is there a way to properly install a C ++ or C library in virtualenv so that Python code that runs in that virtual environment loads it correctly? Or is it just that virtualenvs are not designed to work?

(I don't think the mechanics of this question depend on SWIG, but if SWIG has any implications, or if there are techniques specifically SWIG-related that can solve my problem, it would be great to know.)

+3


source to share





All Articles