Install and find a shared library with conda

I want to build two related conda packages:

  • Common object file libfoo.sowith compiled code
  • The Python wrapper around this code, foopy

When importing, the module foopyshould find a file libfoo.sothat will then be used with ctypes:

so_directory = ???
lib = ctypes.cdll.LoadLibrary(os.path.join(so_directory, 'libfoo.so'))

How can I reliably find where the file is libfoo.so? I am happy to change any recipe.

+4
source share
2 answers

I would recommend installing .so in the PREFIX / lib folder - in other words, putting it in the default search path.

For Windows / Anaconda, this is PREFIX / Library / bin.

EDIT:

PREFIX - , Python. /usr /usr/local, ~/miniconda

:

os.path.join DLL. , , python PREFIX, .

+5

, .

. Python ctypes: DLL

, conda env, - $BAR. libfoo.so $BAR/lib/libfoo.so. , , conda-build $PREFIX/lib/libfoo.so.

, foopy setup.py foopy/__init__.py. , pip- conda- ​​ $BAR/lib/python2.7/site-packages/foopy/__init__.py. ( python3.x) , foopy/__init__.py -

import os.path
fourup = '../../../..'
libdir = os.path.normpath(os.path.join(__file__, fourup))

import ctypes
lib = ctypes.CDLL(os.path.join(libdir, 'libfoo.so')
+1

Source: https://habr.com/ru/post/1624329/


All Articles