scikit_build_example | An example combining scikit-build and pybind11 | Machine Learning library
kandi X-RAY | scikit_build_example Summary
kandi X-RAY | scikit_build_example Summary
An example combining scikit-build and pybind11
Support
Quality
Security
License
Reuse
Top functions reviewed by kandi - BETA
Currently covering the most popular Java, JavaScript and Python libraries. See a Sample of scikit_build_example
scikit_build_example Key Features
scikit_build_example Examples and Code Snippets
Community Discussions
Trending Discussions on scikit_build_example
QUESTION
I am wondering how to use pip to develop a Python package which is going through many revisions rapidly. My work flow is to write C++ code, compile and install with pip install
and test my code.
Then, I would like to change some underlying C++ code, recompile and reinstall with pip, test the new feature, change something else, go back etc. until my package is ready.
Why did pip install ./cmake_example
work well the first time but when making changes to the code, reinstalling with recompiling produced an error? I just re-ran the command pip install ./cmake_example
.
I changed a single line of C++ code in an innocuous way (adding +1 in the 'add' function just to see if I can change code and recompile) and the code compiled fine in my IDE without pip.
My basic idea was to use pip
following this method to avoid having to hackishly insert my shared object into some python directory each time I make a change.
I used the cmake_example from pybind here and followed the steps and did pip install ./cmake_example
and it worked very well. I ran the example fine in a Python console.
Then, I changed some code (just added +1 to the adding function), so nothing substantial and wanted to re-install
the package.
I then got this error:
...ANSWER
Answered 2022-Feb-18 at 23:14I found that deleting the build
directory inside the cmake_example
directory resolved the problem and pip install ./cmake_example
worked again as it did the first time. You can combine the two commands:
QUESTION
I am building a Python extension in C++ using pybind11 and scikit-build. I base on the example provided at https://github.com/pybind/scikit_build_example/blob/master/setup.py.
My CMakelists boils down to this:
...ANSWER
Answered 2022-Feb-18 at 10:35Conclusion: as Alex said this part of the name is necessary. See https://www.python.org/dev/peps/pep-3149/. Python will automatically figure out it can use _mylib.cpython-38-x86_64-linux-gnu.so
if you import _mylib
.
QUESTION
I have a project, cloudgen, that I would like to add bindings for Python so I can access some of the underlying functions. I have stubbed out the initial work on a branch. Because the main executable is built with cmake, I decided to use scikit-build to manage the build and use pybind11 to deal with the binding (following this example repo).
When I run pip install .
in a virtual environment, everything appears to work as expected. I find the executable is installed to /bin
, the library goes into /lib
, and the module goes into /lib/pythonX.Y/site-packages/cloudgen
. In fact, if I run pip uninstall cloudgen
, all of the correct files are uninstalled. However, my problems arise when I start to test the Python bindings. I find two separate but related problems.
- If I installed into an Anaconda environment, the module is able to resolve the path to the shared library and pass the tests, but the executable does not resolve the path to the library.
- On the other hand, if I installed into a virtual environment using
python -m venv
, both the module and the executable are unable to resolve the path to the shared library.
Searching around, I came across this question which notes I could manipulate LD_LIBRARY_PATH
(or equivalently DYLD_LIBRARY_PATH
on macOS or PATH
on Windows), but that is normally frowned upon. That question references an open issue that refers to including additional build products (which as I said appears to not be my problem) but doesn't address the library path resolution. I also came across this question asking about distributing the build products using scikit-build and this question using setuptools directly. Neither of the questions or answers address the library path resolution.
My question is: What is the correct way to distribute a package that contains an executable, shared library, and Python binding module and have the path resolution Just Work™?
A minimal working example is a bit much, but I created a gist to demonstrate the behavior.
...ANSWER
Answered 2021-Nov-30 at 00:52After a bit more digging (and carefully reading the CMake documentation on RPATH
), the correct answer appears to be explicitly setting RPATH
on installation. The relevant change to the linked gist is to add the following to the CMakeLists.txt after creating the targets (adapted from the linked Wiki):
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
Vulnerabilities
No vulnerabilities reported
Install scikit_build_example
Support
Reuse Trending Solutions
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
Find more librariesStay Updated
Subscribe to our newsletter for trending solutions and developer bootcamps
Share this Page