-
Notifications
You must be signed in to change notification settings - Fork 25
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
The python binding doesn't install itself #34
Comments
Sorry I need more information. Is this on Linux? |
This is on FreeBSD. |
@brunopostle Are you able to help with this issue? Many thanks! |
Yes, basically there is a minimal CMake build configuration that allows you to compile the Topologic C++ library and the pybind11 Python bindings as two separate steps. There is an install target for the library, but no integration with python packaging tools, so you have to install the bindings by copying the .so file into your PYTHONPATH. This isn't ideal, but the project really needs somebody who understands cmake and python packaging to step up and fix it. The good news is that it isn't a particularly complex problem: the library is a pretty normal C++ shared library, and the python bindings are not doing anything weird either. @wassimj I suggest adding a couple of 'labels' to this issue, in particular you should add: 'help wanted', 'cmake' and 'python'. |
Hi there, I can try to look at this; I'm always scared when I have to build C/C++ code, but I have some experience in packaging python libraries. Just for reference: the pybind11 documentation points to an example using cmake; alternatively one can go with setuptools without the need to have pybind11 as submodule. Being a python guy I'd prefer to use setuptools (it seems to be the recommended way), is it ok with you? |
Hi @sanzoghenzo Sure, thanks for your help. |
Hi there, What I got so far:
[build-system]
requires = [
"setuptools>=42",
"wheel",
"pybind11>=2.8.0",
]
build-backend = "setuptools.build_meta"
[tool.cibuildwheel]
test-command = "python {project}/Python-Bindings/tests/topologictest01.py"
test-skip = "*universal2:arm64"
from glob import glob
from setuptools import setup
from pybind11.setup_helpers import Pybind11Extension, build_ext
__version__ = "0.0.1"
ext_modules = [
Pybind11Extension(
"topologic",
sorted(glob("src/*.cpp")),
include_dirs=[
"include",
"../TopologicCore/include",
"/usr/include/opencascade",
"/usr/include/uuid"
],
language='c++',
),
]
setup(
name="topologic",
version=__version__,
author="Cardiff University and University College London",
author_email="",
url="https://github.com/wassimj/Topologic",
description="Python bindings of Topologic",
long_description="",
ext_modules=ext_modules,
cmdclass={"build_ext": build_ext},
zip_safe=False,
python_requires=">=3.6",
) WIth this configuration the 1 - the opencascade and uuid include paths are hardcoded, I didn't find any mentions in pybind11's documentation on how to make them auto-discoverable
For this I didn't find a solution using my google-fu, and I'm sure that there will be many more problems after this... I already spent too much time and I have to give up on this! |
I see this last error on the fedora 37 build host, but not on fedora 36. They both have GCC 12.1.1, but the difference seems to be an upgrade from pybind11 2.9.2 to pybind11 2.10.0 @sanzoghenzo what version of pybind11 do you have?
|
@brunopostle great catch, using But, as I suspected, another one came up...
I now realize that going the setuptools way is not a good strategy because it completely ignores the CMake files. |
This is probably still a bug in Topologic, i.e. it needs to be fixed to work with pybind11 2.10.0 |
I may be wrong, but this kind of bug ('Type' is not a member of 'TopologicCore::Topology') would have failed with gcc regardless of pybind. The fact that Topologic builds the C++ code successfully tells me there is something else going on here. Now it could be that the cppwg files are buggy. I will have to look deeper into that. |
switching to Updated import sys
try:
from skbuild import setup
except ImportError:
print(
"Please update pip, you need pip 10 or greater,\n"
" or you need to install the PEP 518 requirements in pyproject.toml yourself",
file=sys.stderr,
)
raise
from setuptools import find_packages
__version__ = "0.6.0"
setup(
name="topologic",
version=__version__,
author="Cardiff University and University College London",
author_email="",
url="https://github.com/wassimj/Topologic",
description="Python bindings of Topologic",
long_description="",
packages=find_packages(where="src"),
package_dir={"": "src"},
cmake_install_dir="src/topologic",
include_package_data=True,
extras_require={"test": ["pytest"]},
python_requires=">=3.6",
) updated [build-system]
requires = [
"setuptools>=42",
"pybind11~=2.9.2",
"cmake>=3.22",
"scikit-build>=0.15.0",
"ninja; platform_system!='Windows'"
]
build-backend = "setuptools.build_meta"
[tool.cibuildwheel]
test-command = "pytest {project}/tests"
test-extras = ["test"]
test-skip = ["*universal2:arm64"] Updated
then I added a from ._topologic import main if I
And here I remembered why I "hate" C/C++ 🤣 |
On Tue, 9 Aug 2022, 15:06 Andrea Ghensi, wrote:
ImportError: libTopologicCore.so.0: cannot open shared object file: No such file or directory
And here I remembered why I "hate" C/C++ 🤣
This is where I really give up.
This is more or less expected, Linux won't import a dynamic library unless
it is in an approved location (basically /usr/lib64/), specified in the
environment using LD_LIBRARY_PATH, or manipulated using rpath.
I.e. do this before your test:
export LD_LIBRARY_PATH=/folder/where/library/gets/installed
… |
yeh, well, the whole point of having a proper python package, for me, was to avoid fiddling with paths and the like... As I said, I'm no expert at all at C++/CMake, so I'll leave it to you, if you think this is worth the effort. |
On Tue, 9 Aug 2022, 16:33 Andrea Ghensi, wrote:
yeh, well, the whole point of having a proper python package, for me, was
to avoid fiddling with paths and the like...
I don't know how this is normally resolved. I have had this problem before
with packages installed with setup.py, I ended up installing as root to
force a findable installation location.
Maybe libTopologicCore can be built as a static library, and the python
bindings can include it.
… |
This has now all been resolved by the new cmake refactoring and the new pybind version. |
The text was updated successfully, but these errors were encountered: