pybind / cmake_example Goto Github PK
View Code? Open in Web Editor NEWExample pybind11 module built with a CMake-based build system
License: Other
Example pybind11 module built with a CMake-based build system
License: Other
Hi Dean,
would you be open to moving this repository to the 'pybind11' organization? (similar to the 'pbtest' pip example which is already there). If so, please go ahead and initiate a transfer, and I'll also add you to the organization.
Thanks,
Wenzel
Thanks for the nice template. However...
I'm sometimes running into build problems, most recently I have some unresolved problem here (https://github.com/conda-forge/prrng-feedstock). The problem is that the CMake call is quite buried, and that makes the whole thing hard to debug, or adapt when needed. Did you even consider having either:
setup.py
(I'm honestly not sure that it even possible).setuptools
from CMake (also there, not sure if it possible), but this would make everything so much nicer: only one place to customise, and in fact a command that can take command-line options.cmake ..
make
Than I got a "cmake_example.cpython-35m-x86_64-linux-gnu.so"
I can't be import like "import cmake_example" 。 What 's the problems of my operating?
The build requirements seems to be downloaded by the install process, but not actually found when building;
git clone https://github.com/pybind/cmake_example.git
cd cmake_example
pip3 install .
...
Traceback (most recent call last):
File "/private/var/folders/.../overlay/bin/cmake", line 5, in <module>
from cmake import cmake
ModuleNotFoundError: No module named 'cmake'
If you manually install using pip3 install cmake
it works after that.
Hi:
I want to set extension's path not to site-packages root, like:
site-packages
cmake_example
__init__.py
cmake_example.cp38-win_amd64.pyd
what should I do in setup.py?
Thanks!
I'm receiving this error while tying to put together a simple pybind cmake example app.
Process finished with exit code -1073741515 (0xC0000135)
I've been google for hours now trying to figure out the source of this error. When i comment out the lines utilizing pybind (First 3 lines in main). It compiles and runs correctly and reaches the print statement. I'm pretty new to CMake so it's possible i set it up wrong. I added the lines pointing to python because I was receiving errors about missing python dll's. I'm using CLion and MSVS 2017 if that makes any difference.
example.cpp
#include <iostream>
#include <../pybind11/include/pybind11/pybind11.h>
#include <../pybind11/include/pybind11/embed.h>
#include <CImg.h>
namespace py = pybind11;
using namespace py::literals;
int main(int argc, char *argv[])
{
py::scoped_interpreter guard{};
auto example = py::module::import("example");
auto resultobj = example.attr("add")(2,2);
int result = resultobj.cast<int>();
std::cout << result;
}
example.py
def add(a,b):
return a+b
Cmakelists.txt:
cmake_minimum_required(VERSION 3.14)
project(TestApp)
set(CMAKE_CXX_STANDARD 11)
find_package(PythonLibs REQUIRED)
include_directories(${PYTHON_INCLUDE_DIRS})
link_directories(C:\\Users\\myuser\\AppData\\Local\\Programs\\Python\\Python37-32\\libs)
add_subdirectory(lib/pybind11)
include_directories(lib/CImg-2.6.7)
add_executable(example src/example.cpp)
target_link_libraries(example PRIVATE pybind11::embed)
File Structure
TestApp
----src/
--------example.cpp
----lib/
--------Cimg-2.6.7/
--------pybind/
When I git clone the cmake_example, I do not find ./cmake_example file. And I mkdir build and cmake .. & make, still did not find ./cmake_example. In addition, I run python setup.py install, it still not work. any help?
I noticed an addition for cross-compilation on macOS here ce0ea77 by @henryiii . In trying to make my feedstock work (conda-forge/gmattensor-feedstock#13) I also got across the suggestion to pass the environment variable CMAKE_ARGS
here. Does anyone know if that is really needed? And if so, it might not be so bad to add it to the example.
Can I create a module called "cmake_sub_example" in a subdirectory with the same title? I am trying this because I want to use it in a bigger project where I intend to start cmake from the highest level.
Hey
So I have a little complex library here and I need to be "in control" of what goes where/how...
Here is my RnD test that "builds" but fails to work/import in python... would any1 be able to look in to it ?
cmake_minimum_required(VERSION 3.25)
project(exampleHowToPybind)
#add_compile_options(/Zi /MDd /Od)
#set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /Zi /Od")
#set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} /DEBUG")
set(PY_BIND_ROOT "S:/01_Code//pybind11/include")
set(PY_VERSION 37)
set(PY_EXE "C:/Program Files/Python37")
set(Python3_ROOT_DIR "C:/Program Files/Python37")
set(Python_INCLUDE_DIRS "${Python3_ROOT_DIR}/include")
set(Python3_FIND_ABI "ON" "3" "7")
set(PYTHON_EXECUTABLE "${Python3_ROOT_DIR}/python.exe" CACHE FILEPATH "Path to the Python executable")
set(PY_BUILD_DEB)
if (${CMAKE_BUILD_TYPE} MATCHES Debug)
message("WERE IN DEBUG MODE")
set(PY_BUILD_DEB "_d")
endif ()
set(_PYTHON_EXECUTABLE "${PY_EXE}/python.exe" CACHE STRING "Path to the Python executable")
set(_PYTHON_INCLUDE_DIR "${PY_EXE}/include" CACHE STRING "Path to the Python include directory")
set(_PYTHON_LIBRARY "${PY_EXE}/libs/python${PY_VERSION}${PY_BUILD_DEB}.lib" CACHE STRING "Path to the Python library")
set(OLD_PATH ${CMAKE_PREFIX_PATH})
set(CMAKE_PREFIX_PATH ${PY_EXE})
#find_package(Python3 REQUIRED COMPONENTS Interpreter Development)# HINTS "${PYTHON_EXECUTABLE}")
#set(CMAKE_PREFIX_PATH ${PY_BIND_ROOT}/tools)
#find_package(pybind11)
set(CMAKE_PREFIX_PATH ${OLD_PATH})
message(" PYTHON_EXECUTABLE : ${_PYTHON_EXECUTABLE}")
message(" PYTHON_INCLUDE_DIR : ${_PYTHON_INCLUDE_DIR}")
message(" PYTHON_LIBRARY : ${_PYTHON_LIBRARY}")
message(" Python_LIBRARIES : ${Python_LIBRARIES}")
message("Python_INCLUDE_DIRS : ${Python_INCLUDE_DIRS}")
# include("${PY_BIND_ROOT}/CMakeLists.txt")
add_library(pybind11 INTERFACE)
target_include_directories(pybind11 INTERFACE ${PY_BIND_ROOT})
set(SRC main.cpp)
#add_executable(${PROJECT_NAME} ${SRC})
add_library(${PROJECT_NAME} MODULE ${SRC})
set_target_properties(${PROJECT_NAME} PROPERTIES SUFFIX ".pyd" )
target_link_libraries(${PROJECT_NAME} PRIVATE pybind11 ${PYTHON_LIBRARY} "${PY_EXE}/libs/python${PY_VERSION}.lib")
target_include_directories(${PROJECT_NAME} PRIVATE ${Python_INCLUDE_DIRS})
Now my current problem is that I can't use find_package. It works fine in Clion, but in visual studio 2022 it returns python 310 instead of 37 that I specified. No matter what I try he's ignoring my requests. In any case, I've decided to ignore that find package and link by hand....
So with the example here I got a basic extension working. After that I figured I'd try extending it to the rest of my project. The problem I am having is that a few of my source files are using CUDA code which, at the moment, is giving me unresolved external symbol errors.
I'll outline an example of my code files and the CMakeLists.txt I have at the moment:
The bindings I have in module.cpp:
#include "pch.h"
namespace py = pybind11;
void add_external_bindings(py::module_ &);
PYBIND11_MODULE(project_bindings, m) {
add_external_bindings(m);
}
The add_external_bindings
function is defined in another file (main.cpp) that uses some CUDA calls:
#include "pch.h"
// =====
// Some code that uses CUDA
// =====
namespace py = pybind11;
void add_external_bindings( py::module_& m ) {
py::class_<ExternalClass>( m, "ExternalClass" )
.def( py::init<int, int, int, const std::string&>() );
}
and finally my CMakeLists.txt (Apologies in advance if it strays from industry standards or conventions, I am unfortunately not very familiar with cmake):
cmake_minimum_required(VERSION 3.18)
project(project_bindings)
set(SOURCE_FILES
"FFT-Fluid/src/module.cpp"
"FFT-Fluid/src/stokes.cpp"
"FFT-Fluid/src/kernels.cu"
)
add_subdirectory(pybind11 REQUIRED)
pybind11_add_module(project_bindings SHARED ${SOURCE_FILES})
set_target_properties(project_bindings PROPERTIES CXX_STANDARD 17)
# EXAMPLE_VERSION_INFO is defined by setup.py and passed into the C++ code as a
# define (VERSION_INFO) here.
target_compile_definitions(project_bindings PRIVATE VERSION_INFO=${EXAMPLE_VERSION_INFO})
find_package(CUDA REQUIRED)
target_include_directories(project_bindings PRIVATE
# =====
# Some external libraries
# =====
${CUDA_INCLUDE_DIRS}
)
I thought that by using target_include_directories
the CUDA dependency would be taken care of but it is evidently not the case as I get the following errors for this and several other CUDA functions:
error LNK2001: unresolved external symbol cudaMallocArray
Does anyone know how to properly have CMake detect/link CUDA files?
Hello
Thanks for this awesome test!
I'm lost with customization tho...
How can I specify python in CMakeList.txt file?
I build this file without using your python. setup routine tho... just added
add_definitions(-DVERSION_INFO=3.10)
To cmake and it build locally.
Works great, locally, but I Have no idea how it knows which python to use.
I want to be explicit.
Any ideas?
Pinging our 2 biggest contributors hoping for a miracle :- )
@dean0x7d @henryiii
SOLVED>
To specify python version using "new methods"
set(PYBIND11_PYTHON_VERSION 3.9)
set(OLD_PATH ${CMAKE_PREFIX_PATH})
set(CMAKE_PREFIX_PATH ${P3_ROOT_DIR})
add_subdirectory(S:/pybind11 S:/pybind11)
set(CMAKE_PREFIX_PATH ${OLD_PATH})
at least on windows before adding pybind11
big thanks to @henryiii !!
When including pybind11 directly via add_subdirectory
, the selected python interpreter would be useful to be queried, e.g. for install paths.
With find_package(pybind11)
the variables PYTHON_VERSION_MAJOR
and ..._MINOR
leak into the caller's scope and can be queried, but add_subdirectory
does proper encapsulation.
Can we maybe add PYTHON_VERSION_MAJOR
and PYTHON_VERSION_MINOR
as CMake target properties to the pybind11::pybind11
target? With that we could query it from a calling project (or maybe you have an alternative idea as well).
I'm not totally sure of the provenance (is it from pybind11 itself?), but when I try to load a compiled module (it compiles fine) with a cmake_example-based setup.py
(https://github.com/usnistgov/NISTfit), on xubuntu 17.04, I get errors when I try to load the module. Some info:
The cmake_example
works just fine, as does the python_example
in this environment, so I'm a bit at a loss to understand what is going on.
The error
ImportError: /home/ian/miniconda3/lib/python3.6/site-packages/matplotlib/../../../libstdc++.so.6: version `GLIBCXX_3.4.22' not found (required by /home/ian/miniconda3/lib/python3.6/site-packages/NISTfit.cpython-36m-x86_64-linux-gnu.so)
I think that it would be beneficial to keep the two projects in sync as much as possible (directory structure, conda recipe). I imagine that if someone solves an issue for one, it will apply to the other if it is not cmake
of distutils.compiler
- specific.
I don't have a strong opinion of these matters (except that we should probably rename python_example/py
to python_example/src
like in cmake_example).
Hi,
I have cloned and used the cmake example. After installing it with pip, I am able to run the test.py. Now, I would like to use the pip installer instead of having the pybind code as submodule (using the binaries instead of the headers). So I installed the lib with "pip3 install pybind11", and access the library by adapting the CMakeList.txt:
cmake_minimum_required(VERSION 3.5)
project(pybind_decoder_lib)
set(LIDAR_PERCEPTION_DIR ${CMAKE_SOURCE_DIR}/../../../..)
include(${LIDAR_PERCEPTION_DIR}/common.cmake)
find_package(catkin REQUIRED COMPONENTS
roscpp
lidar_msgs
)
## Both Boost.python and Python libs are required.
find_package(pybind11 REQUIRED HINTS /home/user/.local/lib/python3.8/site-packages)
###################################
## catkin specific configuration ##
###################################
catkin_package(
LIBRARIES pybind_decoder_lib
CATKIN_DEPENDS roscpp
# DEPENDS system_lib
)
###########
## Build ##
###########
# include Boost and Python.
include_directories(
include
${catkin_INCLUDE_DIRS}
${PYTHON_INCLUDE_DIRS}
${pybind11_INCLUDE_DIRS}
${pybind11_INCLUDE_DIR} # here I am not sure which spelling, so I try both
)
## Declare a cpp library
pybind11_add_module(pybind_decoder_lib src/pybind_decoder_lib.cpp)
## Specify libraries to link a library or executable target against
# Don't prepend wrapper library name with lib and add to Python libs.
set_target_properties(pybind_decoder_lib PROPERTIES
PREFIX ""
LIBRARY_OUTPUT_DIRECTORY ${CATKIN_DEVEL_PREFIX}/${CATKIN_PACKAGE_PYTHON_DESTINATION})
Here is the CPP:
/// @file pybind_decoder_lib.cpp
// ****************************************************************************
#include <pybind11/pybind11.h>
int add(int i, int j) {
return i + j;
}
namespace py = pybind11;
PYBIND11_MODULE(pybind_decoder_lib, m) {
m.doc() = "pybind11 example plugin"; // optional module docstring
m.def("add", &add, R"pbdoc(
Add two numbers
Some other explanation about the add function.
)pbdoc");
m.def("subtract", [](int i, int j) { return i - j; }, R"pbdoc(
Subtract two numbers
Some other explanation about the subtract function.
)pbdoc");
m.attr("__version__") = "dev";
}
And finally, here is my python code):
import pybind_decoder_lib as m
# result = m.subtract(30, 14)
# print(result)
print(m.add(1, 2))
user@SI-C-0020Q:/work/catkin_ws/src/lidar_perception/pybind_decoder_lib/tst$ python3 test_basic.py
Traceback (most recent call last):
File "test_basic.py", line 5, in
print(m.add(1, 2))
AttributeError: module 'pybind_decoder_lib' has no attribute 'add'
When I check the binary with nm -D, it confirms the error, the python module exists, but does not have any add method. SO somehow the PYBIND11_MODULE macro fails, but I don t know why.
I tried to build this example on Windows, but ran into an error.
Versions:
D:\github>pip install .\cmake_example
Processing o:\github\cmake_example
Installing collected packages: cmake-example
Running setup.py install for cmake-example ... error
Exception:
Traceback (most recent call last):
File "c:\program files (x86)\python36-32\lib\site-packages\pip\compat\__init__.py", line 73, in console_to_str
return s.decode(sys.__stdout__.encoding)
UnicodeDecodeError: 'utf-8' codec can't decode byte 0x81 in position 48: invalid start byte
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "c:\program files (x86)\python36-32\lib\site-packages\pip\commands\install.py", line 342, in run
prefix=options.prefix_path,
File "c:\program files (x86)\python36-32\lib\site-packages\pip\req\req_set.py", line 784, in install
**kwargs
File "c:\program files (x86)\python36-32\lib\site-packages\pip\req\req_install.py", line 878, in install
spinner=spinner,
File "c:\program files (x86)\python36-32\lib\site-packages\pip\utils\__init__.py", line 676, in call_subprocess
line = console_to_str(proc.stdout.readline())
File "c:\program files (x86)\python36-32\lib\site-packages\pip\compat\__init__.py", line 75, in console_to_str
return s.decode('utf_8')
UnicodeDecodeError: 'utf-8' codec can't decode byte 0x81 in position 48: invalid start byte
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "c:\program files (x86)\python36-32\lib\site-packages\pip\basecommand.py", line 215, in main
status = self.run(options, args)
File "c:\program files (x86)\python36-32\lib\site-packages\pip\commands\install.py", line 385, in run
requirement_set.cleanup_files()
File "c:\program files (x86)\python36-32\lib\site-packages\pip\req\req_set.py", line 729, in cleanup_files
req.remove_temporary_source()
File "c:\program files (x86)\python36-32\lib\site-packages\pip\req\req_install.py", line 977, in remove_temporary_source
rmtree(self.source_dir)
File "c:\program files (x86)\python36-32\lib\site-packages\pip\_vendor\retrying.py", line 49, in wrapped_f
return Retrying(*dargs, **dkw).call(f, *args, **kw)
File "c:\program files (x86)\python36-32\lib\site-packages\pip\_vendor\retrying.py", line 212, in call
raise attempt.get()
File "c:\program files (x86)\python36-32\lib\site-packages\pip\_vendor\retrying.py", line 247, in get
six.reraise(self.value[0], self.value[1], self.value[2])
File "c:\program files (x86)\python36-32\lib\site-packages\pip\_vendor\six.py", line 686, in reraise
raise value
File "c:\program files (x86)\python36-32\lib\site-packages\pip\_vendor\retrying.py", line 200, in call
attempt = Attempt(fn(*args, **kwargs), attempt_number, False)
File "c:\program files (x86)\python36-32\lib\site-packages\pip\utils\__init__.py", line 102, in rmtree
onerror=rmtree_errorhandler)
File "c:\program files (x86)\python36-32\lib\shutil.py", line 494, in rmtree
return _rmtree_unsafe(path, onerror)
File "c:\program files (x86)\python36-32\lib\shutil.py", line 384, in _rmtree_unsafe
_rmtree_unsafe(fullname, onerror)
File "c:\program files (x86)\python36-32\lib\shutil.py", line 384, in _rmtree_unsafe
_rmtree_unsafe(fullname, onerror)
File "c:\program files (x86)\python36-32\lib\shutil.py", line 384, in _rmtree_unsafe
_rmtree_unsafe(fullname, onerror)
File "c:\program files (x86)\python36-32\lib\shutil.py", line 393, in _rmtree_unsafe
onerror(os.rmdir, path, sys.exc_info())
File "c:\program files (x86)\python36-32\lib\site-packages\pip\utils\__init__.py", line 114, in rmtree_errorhandler
func(path)
PermissionError: [WinError 32] Der Prozess kann nicht auf die Datei zugreifen, da sie von einem anderen Prozess verwendet wird: 'C:\\Users\\Sysadmin\\AppData\\Local\\Temp\\pip-r3e3669_-build\\build\\temp.win32-3.6\\Release'
With my code that is almost identical to this example, I am getting on Linux/macOS (but not on Windows) that
...
-- Build files have been written to: /tmp/pip-req-build-aua6es75/build/temp.linux-x86_64-3.9
ninja: no work to do.
running install_lib
warning: install_lib: 'build/lib.linux-x86_64-3.9' does not exist -- no Python modules to install
I.e. the *.so
is created ok, but in the build/temp.*
directory. It is never copied to the build/lib.*
directory.
For reference, I am trying here : tdegeus/prrng#4
It would be really nice if instead of needing to install the package using pip install ./cmake_example
, you could use Poetry's built-in shell to run the package locally. I do this regularly with other packages that use poetry.
Example:
$ poetry run python
>>> import cmake_example
>>>
If I am wrapping a shared library (e.g. libParent.so
), and generate python bindings (e.g. libBindings.so
), setup.py
will install both libBindings.so
(correctly) and libParent.so
(incorrectly) to python's .../dist-packages/
. .../dist-packages/
directory is not usually in $LD_LIBRARY_PATH
, so the loader does not see libParent.so
and I get an error like this:
ImportError: libParent.so.0.0.1: cannot open shared object file: No such file or directory
Contents of Bindings/CMakeLists.txt
look like this:
pybind11_add_module(Bindings bindings.cpp)
target_link_libraries(Bindings PRIVATE Parent)
Is there an elegant way to solve this?
Can't make the doc html
[autosummary] generating autosummary for: cmake_example.rst, index.rst
Failed to import 'cmake_example': no module named cmake_example
building [mo]: targets for 0 po files that are out of date
building [html]: targets for 0 source files that are out of date
updating environment: 0 added, 1 changed, 0 removed
reading sources... [100%] cmake_example
/home/tumh/cmake_example/docs/cmake_example.rst:1: WARNING: autodoc: failed to import module u'cmake_example'; the following exception was raised:
Traceback (most recent call last):
File "/usr/lib/python2.7/dist-packages/sphinx/ext/autodoc.py", line 386, in import_object
__import__(self.modname)
ImportError: No module named cmake_example
looking for now-outdated files... none found
pickling environment... done
checking consistency... done
preparing documents... done
writing output... [100%] index
/home/tumh/cmake_example/docs/index.rst:6: WARNING: toctree contains reference to document u'cmake_example' that doesn't have a title: no link will be generated
generating indices... genindex
writing additional pages... search
copying static files... WARNING: html_static_path entry u'/home/tumh/cmake_example/docs/_static' does not exist
done
copying extra files... done
dumping search index in English (code: en) ... done
dumping object inventory... done
build succeeded, 3 warnings.
Any idea?
Hi,
I want to use pybind11 to bind a C++ package that depends on third-party libraries like Eigen and Boost and build it into a conda package. I was wondering if there is an example of doing so? I took a look at the scikit-build
example that also does not depend on third-party libraries.
How can one make the package such that on running "pip install ./cmake_example" it creates a subfolder in site-packages named "cmake_example" which contains the shared library for cmake_example?
I find the version
set in setup.py
is not working, instead I need to specify the version inside main.cpp
, is it desired behaviour?
I updated the pybind11 module, yielding pybind11 2.7.1.dev1. But the build fails now, with lots of errors of this kind:
CMake Error in pybind11/CMakeLists.txt:
IMPORTED_LOCATION not set for imported target "pybind11::python_headers"
configuration "RelWithDebInfo".
They were also present in 2.6, but the build still worked, now it doesn't.
Windows, cmake version 3.19.0-rc2
Hi,
you can make this a "template repository" on GitHub via: https://github.com/pybind/cmake_example/settings
From the docs:
You can make an existing repository a template, so you and others can generate new repositories with the same directory structure and files.
I'd like to use this template to create a python/c++ hybrid package, but it seems the package root module is even defined in main.cpp, can it be a init.py instead?
Hello,
Great job, dear. Very helpfull.
I created a project based on this repo. But I changed the name of the module to "calculadora" (I'm already doing an example in c++ to this name). Well, I used the same project, but changed the project name only.
The build and installation seem to work correctly, but when I called the import on the python console, I got this error.
import calculadora
Traceback (most recent call last):
File "", line 1, in
ModuleNotFoundError: No module named 'calculadora'
I can see the calculadora library in the pip3 list. Anyone could help me to understand it and fix it ?
I'm using the Ubuntu SO. Python 3.7.
Thanks.
Hello,
I'm trying to reproduce the installation within a conda virtual environment, on a Mac with the M1 chip.
CMake version 3.21.0 is installed, together with ninja version 1.10.0.git.kitware.jobserver-1 and Python 3.9.10
When running python3 -m pip install .
, the following error log is produced
Processing /Users/marioberaha/dev/tests/cmake_example
Installing build dependencies ... done
Getting requirements to build wheel ... done
Preparing metadata (pyproject.toml) ... done
Building wheels for collected packages: cmake-example
Building wheel for cmake-example (pyproject.toml) ... error
ERROR: Command errored out with exit status 1:
command: /opt/homebrew/opt/[email protected]/bin/python3.9 /opt/homebrew/lib/python3.9/site-packages/pip/_vendor/pep517/in_process/_in_process.py build_wheel /var/folders/c3/_f3tgzn14ylfqqgqhkdntngh0000gn/T/tmpsuhp61z1
cwd: /Users/marioberaha/dev/tests/cmake_example
Complete output (70 lines):
running bdist_wheel
running build
running build_ext
CMake Error at CMakeLists.txt:2 (project):
Running
'/private/var/folders/c3/_f3tgzn14ylfqqgqhkdntngh0000gn/T/pip-build-env-xjc41kgv/overlay/bin/ninja' '--version'
failed with:
No such file or directory
-- Configuring incomplete, errors occurred!
See also "/Users/marioberaha/dev/tests/cmake_example/build/temp.macosx-11-arm64-3.9/cmake_example/CMakeFiles/CMakeOutput.log".
See also "/Users/marioberaha/dev/tests/cmake_example/build/temp.macosx-11-arm64-3.9/cmake_example/CMakeFiles/CMakeError.log".
Traceback (most recent call last):
File "/opt/homebrew/lib/python3.9/site-packages/pip/_vendor/pep517/in_process/_in_process.py", line 363, in <module>
main()
File "/opt/homebrew/lib/python3.9/site-packages/pip/_vendor/pep517/in_process/_in_process.py", line 345, in main
json_out['return_val'] = hook(**hook_input['kwargs'])
File "/opt/homebrew/lib/python3.9/site-packages/pip/_vendor/pep517/in_process/_in_process.py", line 261, in build_wheel
return _build_backend().build_wheel(wheel_directory, config_settings,
File "/opt/homebrew/Cellar/[email protected]/3.9.10/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/setuptools/build_meta.py", line 244, in build_wheel
return self._build_with_temp_dir(['bdist_wheel'], '.whl',
File "/opt/homebrew/Cellar/[email protected]/3.9.10/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/setuptools/build_meta.py", line 229, in _build_with_temp_dir
self.run_setup()
File "/opt/homebrew/Cellar/[email protected]/3.9.10/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/setuptools/build_meta.py", line 174, in run_setup
exec(compile(code, __file__, 'exec'), locals())
File "setup.py", line 119, in <module>
setup(
File "/opt/homebrew/Cellar/[email protected]/3.9.10/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/setuptools/__init__.py", line 155, in setup
return distutils.core.setup(**attrs)
File "/opt/homebrew/Cellar/[email protected]/3.9.10/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/setuptools/_distutils/core.py", line 148, in setup
return run_commands(dist)
File "/opt/homebrew/Cellar/[email protected]/3.9.10/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/setuptools/_distutils/core.py", line 163, in run_commands
dist.run_commands()
File "/opt/homebrew/Cellar/[email protected]/3.9.10/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/setuptools/_distutils/dist.py", line 967, in run_commands
self.run_command(cmd)
File "/opt/homebrew/Cellar/[email protected]/3.9.10/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/setuptools/_distutils/dist.py", line 986, in run_command
cmd_obj.run()
File "/opt/homebrew/Cellar/[email protected]/3.9.10/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/wheel/bdist_wheel.py", line 299, in run
self.run_command('build')
File "/opt/homebrew/Cellar/[email protected]/3.9.10/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/setuptools/_distutils/cmd.py", line 313, in run_command
self.distribution.run_command(command)
File "/opt/homebrew/Cellar/[email protected]/3.9.10/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/setuptools/_distutils/dist.py", line 986, in run_command
cmd_obj.run()
File "/opt/homebrew/Cellar/[email protected]/3.9.10/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/setuptools/_distutils/command/build.py", line 135, in run
self.run_command(cmd_name)
File "/opt/homebrew/Cellar/[email protected]/3.9.10/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/setuptools/_distutils/cmd.py", line 313, in run_command
self.distribution.run_command(command)
File "/opt/homebrew/Cellar/[email protected]/3.9.10/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/setuptools/_distutils/dist.py", line 986, in run_command
cmd_obj.run()
File "/opt/homebrew/Cellar/[email protected]/3.9.10/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/setuptools/command/build_ext.py", line 79, in run
_build_ext.run(self)
File "/opt/homebrew/Cellar/[email protected]/3.9.10/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/Cython/Distutils/old_build_ext.py", line 186, in run
_build_ext.build_ext.run(self)
File "/opt/homebrew/Cellar/[email protected]/3.9.10/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/setuptools/_distutils/command/build_ext.py", line 339, in run
self.build_extensions()
File "/opt/homebrew/Cellar/[email protected]/3.9.10/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/Cython/Distutils/old_build_ext.py", line 195, in build_extensions
_build_ext.build_ext.build_extensions(self)
File "/opt/homebrew/Cellar/[email protected]/3.9.10/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/setuptools/_distutils/command/build_ext.py", line 448, in build_extensions
self._build_extensions_serial()
File "/opt/homebrew/Cellar/[email protected]/3.9.10/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/setuptools/_distutils/command/build_ext.py", line 473, in _build_extensions_serial
self.build_extension(ext)
File "setup.py", line 113, in build_extension
subprocess.check_call(["cmake", ext.sourcedir] + cmake_args, cwd=build_temp)
File "/opt/homebrew/Cellar/[email protected]/3.9.10/Frameworks/Python.framework/Versions/3.9/lib/python3.9/subprocess.py", line 373, in check_call
raise CalledProcessError(retcode, cmd)
subprocess.CalledProcessError: Command '['cmake', '/Users/marioberaha/dev/tests/cmake_example', '-DCMAKE_LIBRARY_OUTPUT_DIRECTORY=/Users/marioberaha/dev/tests/cmake_example/build/lib.macosx-11-arm64-3.9/', '-DPYTHON_EXECUTABLE=/opt/homebrew/Cellar/[email protected]/3.9.10/bin/python3.9', '-DCMAKE_BUILD_TYPE=Release', '-DEXAMPLE_VERSION_INFO=0.0.1', '-GNinja']' returned non-zero exit status 1.
----------------------------------------
ERROR: Failed building wheel for cmake-example
Failed to build cmake-example
ERROR: Could not build wheels for cmake-example, which is required to install pyproject.toml-based projects
my host is x86-ubuntu, I need to build with my nxp-imx6ul with pybind.
I have build python for ubuntu and arm-board(nxp), then I want to build pybind,
I Use this example, set the arm-linux-gcc for this project,
so how to set python path( ubuntu and arm-python) to pybind11?
or how to change the cmakelist
I tried to understand how this example works, but I do not know what lines shall I add to the CMakeLists.txt if my main.cpp have include other headers and called the functions defined in these headers.
For example, I have a fun.cpp/fun.h sources files:
// fun.h
void print();
// fun.cpp
#include<iostream>
void print() {std::cout << "hello world" << endl;}
And in my main.cpp
#include<pybind11/pybind11.h>
#include"fun.h"
namespace py = pybind11;
PYBIND11_MODULE(main, m) {
m.doc() = "some description of this module";
m.def("print_", &print, "print hello world");
}
I tried to write a CMakeLists.txt
cmake_minimum_required(VERSION 2.8.12)
project(example)
add_library(fun fun.cpp)
add_subdirectory(pybind11)
pybind11_add_module(main SHARED main.cpp)
But this does not work, when I import from python side. What is the correct CMakeList.txt should be like please ?
I want to cmake
it manually. From this video https://www.youtube.com/watch?v=H2wOlriHGmM.
The following are successes.
mkdir build
cd build
cmake ..
make mymath
Scanning dependencies of target mymath
[ 50%] Building CXX object CMakeFiles/mymath.dir/src/mymath.cpp.o
[100%] Linking CXX static library libmymath.a
[100%] Built target mymath
make cmake_example
[ 50%] Built target mymath
Scanning dependencies of target cmake_example
[ 75%] Building CXX object CMakeFiles/cmake_example.dir/src/binder.cpp.o
[100%] Linking CXX shared module cmake_example.cpython-38-x86_64-linux-gnu.so
[100%] Built target cmake_example
And I don't know how to use setup.py
I tried python3 setup.py cmake_example
But the output is :
usage: setup.py [global_opts] cmd1 [cmd1_opts] [cmd2 [cmd2_opts] ...]
or: setup.py --help [cmd1 cmd2 ...]
or: setup.py --help-commands
or: setup.py cmd --help
error: invalid command 'cmake_example'
What is the cmd1 means?
Hello,
I am new to python bindings, so i had a question regarding this library. I have all the c++ files for my project, however what i now require is a .whl file for the same so i can install the python package locally into the system.
can pybind11 do it? if so it would be great to have some insights. Or if there is any other way to do so.
I really look forward to hearing from you.
Hi!
The setup.py script here is awesome and works great. I can successfully do pip install .\myproject
to install locally and cd myproject && python setup.py bdist_wheel
to create a wheel to distribute for the current platform. However what doesn't really work is creating a source distribution (sdist
) so others can build it from pypi when a wheel is not available (or on Linux). python setup.py sdist
runs and creates a .tar.gz, but it doesn't contain any source or CMake files so obviously it can't build. I read that there's different ways of including files in an sdist
but I can't really figure out how to go on in the case of a CMake project like this. Has any of you worked with that before and encountered this issue?
Thanks!
Hi everybody,
I created a project based on this example. What my project basicaly does, is fetching data from an API. The API consists of a .lib, .h and .DLL file. I included the .h file in my CPP code and added the .lib via target_link_libraries
in CMakeLists.txt.
After running pip install .
the .pyd file gets copied to site packages, but after an import in python it fails because of the missing .DLL
I solved the problem by copying the DLL next to the pyd under site packages, but would like to automate this process. What would be the best way, to accomplish this?
I already tried adding package_data to setup.py without success.
make: *** No rule to make target 'install'. Stop.
used these commands
cd pybind11
mkdir build
cd build
cmake ..
make install
can anyone help with this
I want to deploy an example python library, so someone can just include a folder and start using the API
I ran the following commands:
mkdir build; cd build
cmake ..; make
This generated a cmake_example.so
How can I now start using that with python?
I tried to make a project depend on the Pypi cmake package to try to help a pip install with this template work more concisely, but there are headaches and incompatibilities if scikit-build is not brought up-to-date in a separate command before using this setup.py file. But it looks like using sk-build directly would simplify this setup.py file, but complicate the CMakeLists.txt. I'm trying it out in my project and I figure I'll share a minimal example from the results.
Should I issue a PR to this project proposing a setup.py in terms of skbuild? Or is there a reason that skbuild is not appropriate in this setup.py and should maybe be a separate example in the pybind ecosystem?
Hi,
I know that this question/issue might be hard to figure out, and I'm not sure that it's even an issue with this cmake_example, but I'm kind of desperate and I thought that maybe I was missing something.
I used this repo as a skeleton for my package pyvinecopulib and everything worked well if I use a "vanilla" conda environment.
In other words, if I just install miniconda and use the base environment, do a git clone --recursive
and then a pip install
, it works.
However, I have another conda environment with the following config:
# Name Version Build Channel
_libgcc_mutex 0.1 main
attrs 19.1.0 py37_1
backcall 0.1.0 py37_0
bleach 3.1.0 py37_0
ca-certificates 2019.6.16 hecc5488_0 conda-forge
certifi 2019.6.16 py37_1 conda-forge
dbus 1.13.6 h746ee38_0
decorator 4.4.0 py37_1
defusedxml 0.6.0 py_0
entrypoints 0.3 py37_0
expat 2.2.6 he6710b0_0
fontconfig 2.13.0 h9420a91_0
freetype 2.9.1 h8a8886c_1
glib 2.56.2 hd408876_0
gmp 6.1.2 h6c8ec71_1
greenlet 0.4.15 py37h516909a_0 conda-forge
gst-plugins-base 1.14.0 hbbd80ab_1
gstreamer 1.14.0 hb453b48_1
icu 58.2 h9c2bf20_1
ipykernel 5.1.1 py37h39e3cac_0
ipython 7.7.0 py37h39e3cac_0
ipython_genutils 0.2.0 py37_0
ipywidgets 7.5.1 py_0
jedi 0.13.3 py37_0
jinja2 2.10.1 py37_0
jpeg 9b h024ee3a_2
jsonschema 3.0.1 py37_0
jupyter 1.0.0 py37_7
jupyter_client 5.3.1 py_0
jupyter_console 6.0.0 py37_0
jupyter_core 4.5.0 py_0
jupyter_qtconsole_colorschemes 0.8.1 py_1 conda-forge
libedit 3.1.20181209 hc058e9b_0
libffi 3.2.1 hd88cf55_4
libgcc-ng 9.1.0 hdf63c60_0
libpng 1.6.37 hbc83047_0
libsodium 1.0.16 h1bed415_0
libstdcxx-ng 9.1.0 hdf63c60_0
libuuid 1.0.3 h1bed415_2
libxcb 1.13 h1bed415_1
libxml2 2.9.9 hea5a465_1
markupsafe 1.1.1 py37h7b6447c_0
mistune 0.8.4 py37h7b6447c_0
msgpack-python 0.6.1 py37h6bb024c_0 conda-forge
nbconvert 5.5.0 py_0
nbformat 4.4.0 py37_0
ncurses 6.1 he6710b0_1
notebook 6.0.0 py37_0
notedown 1.5.1 py_0 conda-forge
numpy 1.17.0 pypi_0 pypi
openssl 1.1.1c h516909a_0 conda-forge
pandoc 2.2.3.2 0
pandoc-attributes 0.1.7 py_1 conda-forge
pandocfilters 1.4.2 py37_1
parso 0.5.0 py_0
pcre 8.43 he6710b0_0
pexpect 4.7.0 py37_0
pickleshare 0.7.5 py37_0
pip 19.1.1 py37_0
prometheus_client 0.7.1 py_0
prompt_toolkit 2.0.9 py37_0
ptyprocess 0.6.0 py37_0
pygments 2.4.2 py_0
pynvim 0.3.2 py37_0 conda-forge
pyqt 5.9.2 py37h05f1152_2
pyrsistent 0.14.11 py37h7b6447c_0
python 3.7.4 h265db76_0
python-dateutil 2.8.0 py37_0
pyzmq 18.0.0 py37he6710b0_0
qt 5.9.7 h5867ecd_1
qtconsole 4.5.2 py_0
readline 7.0 h7b6447c_5
send2trash 1.5.0 py37_0
setuptools 41.0.1 py37_0
sip 4.19.8 py37hf484d3e_0
six 1.12.0 py37_0
sqlite 3.29.0 h7b6447c_0
terminado 0.8.2 py37_0
testpath 0.4.2 py37_0
tk 8.6.8 hbc83047_0
tornado 6.0.3 py37h7b6447c_0
traitlets 4.3.2 py37_0
unidecode 1.0.23 py37_0
wcwidth 0.1.7 py37_0
webencodings 0.5.1 py37_1
wheel 0.33.4 py37_0
widgetsnbextension 3.5.0 py37_0
xz 5.2.4 h14c3975_4
zeromq 4.3.1 he6710b0_3
zlib 1.2.11 h7b6447c_3
which can be replicated using the following explicit spec file on linux:
# This file may be used to create an environment using:
# $ conda create --name <env> --file <this file>
# platform: linux-64
@EXPLICIT
https://repo.anaconda.com/pkgs/main/linux-64/_libgcc_mutex-0.1-main.conda
https://conda.anaconda.org/conda-forge/linux-64/ca-certificates-2019.6.16-hecc5488_0.tar.bz2
https://repo.anaconda.com/pkgs/main/linux-64/gmp-6.1.2-h6c8ec71_1.conda
https://repo.anaconda.com/pkgs/main/linux-64/icu-58.2-h9c2bf20_1.conda
https://repo.anaconda.com/pkgs/main/linux-64/jpeg-9b-h024ee3a_2.conda
https://repo.anaconda.com/pkgs/main/linux-64/libstdcxx-ng-9.1.0-hdf63c60_0.conda
https://repo.anaconda.com/pkgs/main/linux-64/libgcc-ng-9.1.0-hdf63c60_0.conda
https://repo.anaconda.com/pkgs/main/linux-64/expat-2.2.6-he6710b0_0.conda
https://repo.anaconda.com/pkgs/main/linux-64/libffi-3.2.1-hd88cf55_4.conda
https://repo.anaconda.com/pkgs/main/linux-64/libsodium-1.0.16-h1bed415_0.conda
https://repo.anaconda.com/pkgs/main/linux-64/libuuid-1.0.3-h1bed415_2.conda
https://repo.anaconda.com/pkgs/main/linux-64/libxcb-1.13-h1bed415_1.conda
https://repo.anaconda.com/pkgs/main/linux-64/ncurses-6.1-he6710b0_1.conda
https://conda.anaconda.org/conda-forge/linux-64/openssl-1.1.1c-h516909a_0.tar.bz2
https://repo.anaconda.com/pkgs/main/linux-64/pcre-8.43-he6710b0_0.conda
https://repo.anaconda.com/pkgs/main/linux-64/xz-5.2.4-h14c3975_4.conda
https://repo.anaconda.com/pkgs/main/linux-64/zlib-1.2.11-h7b6447c_3.conda
https://repo.anaconda.com/pkgs/main/linux-64/glib-2.56.2-hd408876_0.conda
https://repo.anaconda.com/pkgs/main/linux-64/libedit-3.1.20181209-hc058e9b_0.conda
https://repo.anaconda.com/pkgs/main/linux-64/libpng-1.6.37-hbc83047_0.conda
https://repo.anaconda.com/pkgs/main/linux-64/libxml2-2.9.9-hea5a465_1.conda
https://repo.anaconda.com/pkgs/main/linux-64/pandoc-2.2.3.2-0.conda
https://repo.anaconda.com/pkgs/main/linux-64/readline-7.0-h7b6447c_5.conda
https://repo.anaconda.com/pkgs/main/linux-64/tk-8.6.8-hbc83047_0.conda
https://repo.anaconda.com/pkgs/main/linux-64/zeromq-4.3.1-he6710b0_3.conda
https://repo.anaconda.com/pkgs/main/linux-64/dbus-1.13.6-h746ee38_0.conda
https://repo.anaconda.com/pkgs/main/linux-64/freetype-2.9.1-h8a8886c_1.conda
https://repo.anaconda.com/pkgs/main/linux-64/gstreamer-1.14.0-hb453b48_1.conda
https://repo.anaconda.com/pkgs/main/linux-64/sqlite-3.29.0-h7b6447c_0.tar.bz2
https://repo.anaconda.com/pkgs/main/linux-64/fontconfig-2.13.0-h9420a91_0.conda
https://repo.anaconda.com/pkgs/main/linux-64/gst-plugins-base-1.14.0-hbbd80ab_1.conda
https://repo.anaconda.com/pkgs/main/linux-64/python-3.7.4-h265db76_0.tar.bz2
https://repo.anaconda.com/pkgs/main/linux-64/attrs-19.1.0-py37_1.conda
https://repo.anaconda.com/pkgs/main/linux-64/backcall-0.1.0-py37_0.conda
https://conda.anaconda.org/conda-forge/linux-64/certifi-2019.6.16-py37_1.tar.bz2
https://repo.anaconda.com/pkgs/main/linux-64/decorator-4.4.0-py37_1.conda
https://repo.anaconda.com/pkgs/main/noarch/defusedxml-0.6.0-py_0.tar.bz2
https://repo.anaconda.com/pkgs/main/linux-64/entrypoints-0.3-py37_0.conda
https://conda.anaconda.org/conda-forge/linux-64/greenlet-0.4.15-py37h516909a_0.tar.bz2
https://repo.anaconda.com/pkgs/main/linux-64/ipython_genutils-0.2.0-py37_0.conda
https://repo.anaconda.com/pkgs/main/linux-64/markupsafe-1.1.1-py37h7b6447c_0.conda
https://repo.anaconda.com/pkgs/main/linux-64/mistune-0.8.4-py37h7b6447c_0.conda
https://conda.anaconda.org/conda-forge/linux-64/msgpack-python-0.6.1-py37h6bb024c_0.tar.bz2
https://conda.anaconda.org/conda-forge/noarch/pandoc-attributes-0.1.7-py_1.tar.bz2
https://repo.anaconda.com/pkgs/main/linux-64/pandocfilters-1.4.2-py37_1.conda
https://repo.anaconda.com/pkgs/main/noarch/parso-0.5.0-py_0.tar.bz2
https://repo.anaconda.com/pkgs/main/linux-64/pickleshare-0.7.5-py37_0.conda
https://repo.anaconda.com/pkgs/main/noarch/prometheus_client-0.7.1-py_0.tar.bz2
https://repo.anaconda.com/pkgs/main/linux-64/ptyprocess-0.6.0-py37_0.conda
https://repo.anaconda.com/pkgs/main/linux-64/pyzmq-18.0.0-py37he6710b0_0.conda
https://repo.anaconda.com/pkgs/main/linux-64/qt-5.9.7-h5867ecd_1.conda
https://repo.anaconda.com/pkgs/main/linux-64/send2trash-1.5.0-py37_0.conda
https://repo.anaconda.com/pkgs/main/linux-64/sip-4.19.8-py37hf484d3e_0.conda
https://repo.anaconda.com/pkgs/main/linux-64/six-1.12.0-py37_0.conda
https://repo.anaconda.com/pkgs/main/linux-64/testpath-0.4.2-py37_0.conda
https://repo.anaconda.com/pkgs/main/linux-64/tornado-6.0.3-py37h7b6447c_0.conda
https://repo.anaconda.com/pkgs/main/linux-64/unidecode-1.0.23-py37_0.conda
https://repo.anaconda.com/pkgs/main/linux-64/wcwidth-0.1.7-py37_0.conda
https://repo.anaconda.com/pkgs/main/linux-64/webencodings-0.5.1-py37_1.conda
https://repo.anaconda.com/pkgs/main/linux-64/jedi-0.13.3-py37_0.conda
https://repo.anaconda.com/pkgs/main/linux-64/pexpect-4.7.0-py37_0.conda
https://conda.anaconda.org/conda-forge/linux-64/pynvim-0.3.2-py37_0.tar.bz2
https://repo.anaconda.com/pkgs/main/linux-64/pyqt-5.9.2-py37h05f1152_2.conda
https://repo.anaconda.com/pkgs/main/linux-64/pyrsistent-0.14.11-py37h7b6447c_0.conda
https://repo.anaconda.com/pkgs/main/linux-64/python-dateutil-2.8.0-py37_0.conda
https://repo.anaconda.com/pkgs/main/linux-64/setuptools-41.0.1-py37_0.conda
https://repo.anaconda.com/pkgs/main/linux-64/terminado-0.8.2-py37_0.conda
https://repo.anaconda.com/pkgs/main/linux-64/traitlets-4.3.2-py37_0.conda
https://repo.anaconda.com/pkgs/main/linux-64/bleach-3.1.0-py37_0.conda
https://repo.anaconda.com/pkgs/main/linux-64/jinja2-2.10.1-py37_0.conda
https://repo.anaconda.com/pkgs/main/linux-64/jsonschema-3.0.1-py37_0.conda
https://repo.anaconda.com/pkgs/main/noarch/jupyter_core-4.5.0-py_0.tar.bz2
https://conda.anaconda.org/conda-forge/noarch/jupyter_qtconsole_colorschemes-0.8.1-py_1.tar.bz2
https://repo.anaconda.com/pkgs/main/noarch/pygments-2.4.2-py_0.tar.bz2
https://repo.anaconda.com/pkgs/main/linux-64/wheel-0.33.4-py37_0.conda
https://repo.anaconda.com/pkgs/main/noarch/jupyter_client-5.3.1-py_0.tar.bz2
https://repo.anaconda.com/pkgs/main/linux-64/nbformat-4.4.0-py37_0.conda
https://repo.anaconda.com/pkgs/main/linux-64/pip-19.1.1-py37_0.conda
https://repo.anaconda.com/pkgs/main/linux-64/prompt_toolkit-2.0.9-py37_0.conda
https://repo.anaconda.com/pkgs/main/linux-64/ipython-7.7.0-py37h39e3cac_0.tar.bz2
https://repo.anaconda.com/pkgs/main/noarch/nbconvert-5.5.0-py_0.tar.bz2
https://repo.anaconda.com/pkgs/main/linux-64/ipykernel-5.1.1-py37h39e3cac_0.conda
https://conda.anaconda.org/conda-forge/noarch/notedown-1.5.1-py_0.tar.bz2
https://repo.anaconda.com/pkgs/main/linux-64/jupyter_console-6.0.0-py37_0.conda
https://repo.anaconda.com/pkgs/main/linux-64/notebook-6.0.0-py37_0.tar.bz2
https://repo.anaconda.com/pkgs/main/noarch/qtconsole-4.5.2-py_0.tar.bz2
https://repo.anaconda.com/pkgs/main/linux-64/widgetsnbextension-3.5.0-py37_0.tar.bz2
https://repo.anaconda.com/pkgs/main/noarch/ipywidgets-7.5.1-py_0.tar.bz2
https://repo.anaconda.com/pkgs/main/linux-64/jupyter-1.0.0-py37_7.conda
Using this new conda environment, I get:
CMake Error at pybind11/tools/FindPythonLibsNew.cmake:127 (message):
Python config failure: Python is 0-bit, chosen compiler is 64-bit
I tried to understand what was going on by adding message(STATUS "PYTHON_VALUES = \n ${_PYTHON_VALUES}")
at line 94, and I get:
-- PYTHON_VALUES =
3.7.4.final.0
/home/tvatter/miniconda/envs/vim
/home/tvatter/miniconda/envs/vim/include/python3.7m
/home/tvatter/miniconda/envs/vim/lib/python3.7/site-packages
7.4.0
.cpython-@PYVERNODOTS@m-x86_64-linux-gnu.so
0
8
3.7m
/home/tvatter/miniconda/envs/vim/lib
x86_64-linux-gnu
So the culprit appears to be:
>>> print(s.get_config_var('SO'));
7.4.0
.cpython-@PYVERNODOTS@m-x86_64-linux-gnu.so
In the base environment, we obviously get:
>>> print(s.get_config_var('SO'));
.cpython-@PYVERNODOTS@m-x86_64-linux-gnu.so
... any idea what I could/should do?
I'm trying to publish my pybind11 stuff to pypi. I figured I would test out the output for this project. When I run the instructions from pypi test for this project, I get an error telling me that no distribution is found
:: pip install -i https://test.pypi.org/simple/ cmake-example
Looking in indexes: https://test.pypi.org/simple/
ERROR: Could not find a version that satisfies the requirement cmake-example (from versions: none)
ERROR: No matching distribution found for cmake-example
It seems that kitware maintains a wheel for cmake!
https://pypi.python.org/pypi/cmake/
This could be interesting
pybind11Config.cmake
files even on pypiIn the case of pybind11, the CMAKE_INSTALL_PREFIX
would be a parent directory to locations.distutils_scheme('pybind11', *args, **kwargs)['headers'])
I guess...
I move the test_basic.py to project root directory and change the import path.
Then, I change the target name in CMakeLists.txt and module name in test_basic.py.
Then, "mkdir build; cd build; cmake ...; make", and everything goes well.
However, when i run the test_basic.py, I get
"Traceback (most recent call last):
File "test_basic.py", line 2, in
import build.bind_example as m
ImportError: dynamic module does not define module export function (PyInit_bind_example)
".
Besides, when I change the target name back to cmake_example, the python file import module normally,
Attached files is the version which target name is changed.
CMakeLists.txt
Hello, I'm currently learning how to use CMake and pybind11 with this project. As part of the installation process, I need to build and install a C++ source file. To ensure that everything is clear, I've included the reproduction code below.
helloworld.cpp
in src/
folder.$ tree -L 2
.
├── CMakeLists.txt
├── pybind11
├── pyproject.toml
├── setup.py
└── src
├── helloworld.cpp
└── main.cpp
src/helloworld.cpp
: A trivial helloworld program. $ cat src/helloworld.cpp
#include <iostream>
int main(int argc, char **argv) {
std::cout << "Hello World!!!\n";
return 0;
}
CMakeLists.txt
: It's basically the same as CMakeLists.tx except add_executable(helloworld src/helloworld.cpp)
is added to build executable.$ cat CMakeLists.txt
cmake_minimum_required(VERSION 3.22)
project(cmake_example)
add_executable(helloworld src/helloworld.cpp)
add_subdirectory(pybind11)
pybind11_add_module(cmake_example src/main.cpp)
target_compile_definitions(cmake_example
PRIVATE VERSION_INFO=${EXAMPLE_VERSION_INFO})
pyproject.toml
:$ cat pyproject.toml
[build-system]
requires = ["setuptools>=62.0.0", "wheel", "cmake>=3.22"]
build-backend = "setuptools.build_meta"
pybind11
is a git submodule, and setup.py
is exactly the same as this setup.py.python3 -m venv venv && source venv/bin/activate && python3 -m pip install --upgrade pip
python3 -m pip install .
cmake_example
library is installed correctly but my helloworld
program is not. There is no helloworld
program in venv
.$ ls venv/lib/python3.8/site-packages/
cmake_example-0.0.1.dist-info
cmake_example.cpython-38-x86_64-linux-gnu.so
python3 -m venv venv && source venv/bin/activate && python3 -m pip install --upgrade pip
python3 -m pip install -e .
cmake_example
library is also installed correctly but my helloworld
program is not. There is no helloworld
program created in the current folder.$ ls
cmake_example.cpython-38-x86_64-linux-gnu.so cmake_example.egg-info CMakeLists.txt pybind11 pyproject.toml setup.py src venv
I actually tried to make it work by modifying setup.py
with the following way.
setup.py
in Line:47. bindir = extdir / "bin"
print(f"User's executables resides in {bindir}")
cmake_args = [
# My innovation. helloworld can be called in scripts.
f"-DCMAKE_RUNTIME_OUTPUT_DIRECTORY={bindir}{os.sep}",
f"-DCMAKE_LIBRARY_OUTPUT_DIRECTORY={extdir}{os.sep}",
f"-DPYTHON_EXECUTABLE={sys.executable}",
f"-DCMAKE_BUILD_TYPE={cfg}", # not used on MSVC, but no harm
]
This approach kind of work. Now I can do pip install .
and helloworld
program appears in venv/lib/python3.8/site-packages/bin/helloworld
. However, this approach doesn't work in editable model. I.e., I do pip install -e .
, but helloworld
program is no created anywhere in the project.
My question is how to achieve the following goal: I would like the helloworld
program to be created automatically when I run pip install .
and pip install -e .
, and I want this program to be installed in the correct Python root path in both modes. Do you have any suggestions or advice on how I can make this happen? Thank you for your help!
System info:
OS: ubuntu20.04
Python: Python3.8
Anyone has issue with test.py? When I execute the file, the console tells me that the No module named 'cmake_example'. Any one knows how to deal with this problem?
Traceback (most recent call last):
File "/Users/jiaqimo/cmake_example/tests/test.py", line 1, in
import cmake_example as m
ModuleNotFoundError: No module named 'cmake_example'
I write a library called AVP_Binding in c++ and want to import AVP_Binding in python. Everything is ok. c++ library can be compiled successfully and generate AVP-Binding.cpython-36m-x86_64-linux-gnu.so also.
My os is ubuntu 18.04, and I run pip install . in virtual enviorment in anacoda(python 3.6, cmake 3.14).
But when I run pip install . with the same setup.py in cmake_example it failed. The error follows:
Processing /home/xxx/Documents/my_project/AVP_Binding
Building wheels for collected packages: AVP-Binding
Building wheel for AVP-Binding (setup.py) ... error
ERROR: Command errored out with exit status 1:
command: /home/xxx/anaconda3/envs/habitat/bin/python -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-req-build-gvd95haj/setup.py'"'"'; __file__='"'"'/tmp/pip-req-build-gvd95haj/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' bdist_wheel -d /tmp/pip-wheel-qbwspzl2
cwd: /tmp/pip-req-build-gvd95haj/
Complete output (45 lines):
running bdist_wheel
running build
running build_ext
CMake Error: CMake was unable to find a build program corresponding to "Ninja". CMAKE_MAKE_PROGRAM is not set. You probably need to select a different build tool.
CMake Error: CMAKE_C_COMPILER not set, after EnableLanguage
CMake Error: CMAKE_CXX_COMPILER not set, after EnableLanguage
-- Configuring incomplete, errors occurred!
See also "/tmp/pip-req-build-gvd95haj/build/temp.linux-x86_64-3.6/CMakeFiles/CMakeOutput.log".
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "/tmp/pip-req-build-gvd95haj/setup.py", line 113, in <module>
zip_safe=False,
File "/home/xxx/anaconda3/envs/habitat/lib/python3.6/site-packages/setuptools/__init__.py", line 153, in setup
return distutils.core.setup(**attrs)
File "/home/xxx/anaconda3/envs/habitat/lib/python3.6/distutils/core.py", line 148, in setup
dist.run_commands()
File "/home/xxx/anaconda3/envs/habitat/lib/python3.6/distutils/dist.py", line 955, in run_commands
self.run_command(cmd)
File "/home/xxx/anaconda3/envs/habitat/lib/python3.6/distutils/dist.py", line 974, in run_command
cmd_obj.run()
File "/home/xxx/anaconda3/envs/habitat/lib/python3.6/site-packages/wheel/bdist_wheel.py", line 299, in run
self.run_command('build')
File "/home/xxx/anaconda3/envs/habitat/lib/python3.6/distutils/cmd.py", line 313, in run_command
self.distribution.run_command(command)
File "/home/xxx/anaconda3/envs/habitat/lib/python3.6/distutils/dist.py", line 974, in run_command
cmd_obj.run()
File "/home/xxx/anaconda3/envs/habitat/lib/python3.6/distutils/command/build.py", line 135, in run
self.run_command(cmd_name)
File "/home/xxx/anaconda3/envs/habitat/lib/python3.6/distutils/cmd.py", line 313, in run_command
self.distribution.run_command(command)
File "/home/xxx/anaconda3/envs/habitat/lib/python3.6/distutils/dist.py", line 974, in run_command
cmd_obj.run()
File "/home/xxx/anaconda3/envs/habitat/lib/python3.6/site-packages/setuptools/command/build_ext.py", line 79, in run
_build_ext.run(self)
File "/home/xxx/anaconda3/envs/habitat/lib/python3.6/distutils/command/build_ext.py", line 339, in run
self.build_extensions()
File "/home/xxx/anaconda3/envs/habitat/lib/python3.6/distutils/command/build_ext.py", line 448, in build_extensions
self._build_extensions_serial()
File "/home/xxx/anaconda3/envs/habitat/lib/python3.6/distutils/command/build_ext.py", line 473, in _build_extensions_serial
self.build_extension(ext)
File "/tmp/pip-req-build-gvd95haj/setup.py", line 95, in build_extension
["cmake", ext.sourcedir] + cmake_args, cwd=self.build_temp
File "/home/xxx/anaconda3/envs/habitat/lib/python3.6/subprocess.py", line 311, in check_call
raise CalledProcessError(retcode, cmd)
subprocess.CalledProcessError: Command '['cmake', '/tmp/pip-req-build-gvd95haj', '-DCMAKE_LIBRARY_OUTPUT_DIRECTORY=/tmp/pip-req-build-gvd95haj/build/lib.linux-x86_64-3.6/', '-DPYTHON_EXECUTABLE=/home/xxx/anaconda3/envs/habitat/bin/python', '-DEXAMPLE_VERSION_INFO=0.0.1', '-DCMAKE_BUILD_TYPE=Release', '-GNinja']' returned non-zero exit status 1.
----------------------------------------
ERROR: Failed building wheel for AVP-Binding
Running setup.py clean for AVP-Binding
Failed to build AVP-Binding
Installing collected packages: AVP-Binding
Running setup.py install for AVP-Binding ... error
ERROR: Command errored out with exit status 1:
command: /home/xxx/anaconda3/envs/habitat/bin/python -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-req-build-gvd95haj/setup.py'"'"'; __file__='"'"'/tmp/pip-req-build-gvd95haj/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' install --record /tmp/pip-record-vd7n5m0r/install-record.txt --single-version-externally-managed --compile --install-headers /home/xxx/anaconda3/envs/habitat/include/python3.6m/AVP-Binding
cwd: /tmp/pip-req-build-gvd95haj/
Complete output (47 lines):
running install
running build
running build_ext
CMake Error: CMake was unable to find a build program corresponding to "Ninja". CMAKE_MAKE_PROGRAM is not set. You probably need to select a different build tool.
CMake Error: CMAKE_C_COMPILER not set, after EnableLanguage
CMake Error: CMAKE_CXX_COMPILER not set, after EnableLanguage
-- Configuring incomplete, errors occurred!
See also "/tmp/pip-req-build-gvd95haj/build/temp.linux-x86_64-3.6/CMakeFiles/CMakeOutput.log".
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "/tmp/pip-req-build-gvd95haj/setup.py", line 113, in <module>
zip_safe=False,
File "/home/xxx/anaconda3/envs/habitat/lib/python3.6/site-packages/setuptools/__init__.py", line 153, in setup
return distutils.core.setup(**attrs)
File "/home/xxx/anaconda3/envs/habitat/lib/python3.6/distutils/core.py", line 148, in setup
dist.run_commands()
File "/home/xxx/anaconda3/envs/habitat/lib/python3.6/distutils/dist.py", line 955, in run_commands
self.run_command(cmd)
File "/home/xxx/anaconda3/envs/habitat/lib/python3.6/distutils/dist.py", line 974, in run_command
cmd_obj.run()
File "/home/xxx/anaconda3/envs/habitat/lib/python3.6/site-packages/setuptools/command/install.py", line 61, in run
return orig.install.run(self)
File "/home/xxx/anaconda3/envs/habitat/lib/python3.6/distutils/command/install.py", line 545, in run
self.run_command('build')
File "/home/xxx/anaconda3/envs/habitat/lib/python3.6/distutils/cmd.py", line 313, in run_command
self.distribution.run_command(command)
File "/home/xxx/anaconda3/envs/habitat/lib/python3.6/distutils/dist.py", line 974, in run_command
cmd_obj.run()
File "/home/xxx/anaconda3/envs/habitat/lib/python3.6/distutils/command/build.py", line 135, in run
self.run_command(cmd_name)
File "/home/xxx/anaconda3/envs/habitat/lib/python3.6/distutils/cmd.py", line 313, in run_command
self.distribution.run_command(command)
File "/home/xxx/anaconda3/envs/habitat/lib/python3.6/distutils/dist.py", line 974, in run_command
cmd_obj.run()
File "/home/xxx/anaconda3/envs/habitat/lib/python3.6/site-packages/setuptools/command/build_ext.py", line 79, in run
_build_ext.run(self)
File "/home/xxx/anaconda3/envs/habitat/lib/python3.6/distutils/command/build_ext.py", line 339, in run
self.build_extensions()
File "/home/xxx/anaconda3/envs/habitat/lib/python3.6/distutils/command/build_ext.py", line 448, in build_extensions
self._build_extensions_serial()
File "/home/xxx/anaconda3/envs/habitat/lib/python3.6/distutils/command/build_ext.py", line 473, in _build_extensions_serial
self.build_extension(ext)
File "/tmp/pip-req-build-gvd95haj/setup.py", line 95, in build_extension
["cmake", ext.sourcedir] + cmake_args, cwd=self.build_temp
File "/home/xxx/anaconda3/envs/habitat/lib/python3.6/subprocess.py", line 311, in check_call
raise CalledProcessError(retcode, cmd)
subprocess.CalledProcessError: Command '['cmake', '/tmp/pip-req-build-gvd95haj', '-DCMAKE_LIBRARY_OUTPUT_DIRECTORY=/tmp/pip-req-build-gvd95haj/build/lib.linux-x86_64-3.6/', '-DPYTHON_EXECUTABLE=/home/xxx/anaconda3/envs/habitat/bin/python', '-DEXAMPLE_VERSION_INFO=0.0.1', '-DCMAKE_BUILD_TYPE=Release', '-GNinja']' returned non-zero exit status 1.
----------------------------------------
ERROR: Command errored out with exit status 1: /home/xxx/anaconda3/envs/habitat/bin/python -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-req-build-gvd95haj/setup.py'"'"'; __file__='"'"'/tmp/pip-req-build-gvd95haj/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' install --record /tmp/pip-record-vd7n5m0r/install-record.txt --single-version-externally-managed --compile --install-headers /home/xxx/anaconda3/envs/habitat/include/python3.6m/AVP-Binding Check the logs for full command output.
Besides name, author, author_email and description in setup, do I need to modify anything else in this setup.py?
My project is here https://github.com/wwtx9/AVP_Binding. It may help to find problem.
my code uses a very old version of pybind: 2.6.0
and everything works fine.
I have two modules, liba
and libb
With 2.6.0
I have:
>>> import liba
>>> import libb
>>>
Same code on 2.7.1
and higher, and I get the following error.
I didn't change one single line in the code.
Importing liba still works, but libb fails.
>>> import liba
>>> import libb
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: dynamic module does not define module export function (PyInit_libb)
My module is correctly defined in a cpp
file.
PYBIND11_MODULE(libb, m)
My CMake looks like this:
if (BUILD_SHARED_LIBRARY)
set(TARGET_LINK_LIBS liba-shared Eigen3::Eigen)
target_link_libraries(objlib PUBLIC ${TARGET_LINK_LIBS})
find_package(Python REQUIRED COMPONENTS Interpreter Development)
include_directories("${Python_INCLUDE_DIRS}")
add_library(objlib-py OBJECT src/python/libb.cpp)
SET(TARGET_LINK_LIBS_PY Python::Module pybind11::pybind11 ${TARGET_LINK_LIBS})
target_include_directories(objlib-py PUBLIC ${TARGET_INCLUDE_DIRS})
target_link_libraries(objlib-py PUBLIC ${TARGET_LINK_LIBS_PY})
set_property(TARGET objlib-py PROPERTY POSITION_INDEPENDENT_CODE ON)
set(SHARED_LIB ${CMAKE_PROJECT_NAME})
add_library(${SHARED_LIB} SHARED $<TARGET_OBJECTS:objlib> $<TARGET_OBJECTS:objlib-py>)
target_compile_definitions(${SHARED_LIB} PRIVATE VERSION_INFO=${PROJECT_VERSION})
target_include_directories(${SHARED_LIB} PUBLIC ${TARGET_INCLUDE_DIRS})
target_link_libraries(${SHARED_LIB} PUBLIC ${TARGET_LINK_LIBS_PY})
list(APPEND RISK_TARGETS ${SHARED_LIB})
endif (BUILD_SHARED_LIBRARY)
And my environment:
$ python3 --version
Python 3.9.2
$ python3
Python 3.9.2 (default, Feb 28 2021, 17:03:44)
[GCC 10.2.1 20210110] on linux
I compile my libs with gcc12
I am puzzled why upgrading the version of pybind makes my imports fail. Maybe I am doing something wrong, but I can't pinpoint it.
After successfully installing cmake_example after running pip install .
command. I try to import cmake_example
module, but it shows undefined symbol
(pybind11) xx@xx:~/code/cmake_example$ pip install . --user
Looking in indexes: https://pypi.tuna.tsinghua.edu.cn/simple
Processing /home/py/code/cmake_example
Installing build dependencies ... done
Getting requirements to build wheel ... done
Preparing metadata (pyproject.toml) ... done
Building wheels for collected packages: cmake-example
Building wheel for cmake-example (pyproject.toml) ... done
Created wheel for cmake-example: filename=cmake_example-0.0.1-cp38-cp38-linux_x86_64.whl size=48911 sha256=9ebbda22de67d214c2039da9003236fe2d8e8eda90c4e2bbee1f4fa7778d7aa5
Stored in directory: /tmp/pip-ephem-wheel-cache-jcrqt4zq/wheels/15/39/14/4a8a39410655bf49353e750dd2e25ce81174f227c1bbb4635b
Successfully built cmake-example
Installing collected packages: cmake-example
Successfully installed cmake-example-0.0.1
(pybind11) xx@xx::~/code/cmake_example$ python
Python 3.8.10 (default, Nov 26 2021, 20:14:08)
[GCC 9.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import cmake_example as m
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: /home/py/.local/lib/python3.8/site-packages/cmake_example.cpython-38-x86_64-linux-gnu.so: undefined symbol: _ZTVN10__cxxabiv120__si_class_type_infoE
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.