如何使用 scikit-build 打包嵌套的 Python 模块?

问题描述 投票:0回答:0

scikit-build 无法为我打包 python 项目。这是布局

hello-cpp
├── src
|   └── hello
|       ├── OtherModule
|       |   └── __init__.py  # empty
|       └── __init__.py      # empty
|       └── hello.cpp
├── CMakeLists.txt
└── setup.py

setup.py
的内容:

from skbuild import setup
from setuptools import find_packages

setup(
    name="hello-cpp",
    version='0.0.1',
    description="a minimal example package (cpp version)",
    author="Me",
    license="MIT",
    packages=find_packages('src'),
    package_dir={'': 'src'},
    python_requires=">=3.7",
    zip_safe=False,
)

CMakeLists.txt
的内容:

cmake_minimum_required(VERSION 3.4...3.22)

project(hello)

find_package(pybind11 CONFIG REQUIRED)

pybind11_add_module(example src/hello/hello.cpp)
install(TARGETS example LIBRARY DESTINATION src/hello)

src/hello/hello.cpp
的内容:

#include <pybind11/pybind11.h>

int add(int i, int j) {
    return i + j;
}

PYBIND11_MODULE(example, m) {
    m.doc() = "pybind11 example plugin"; // optional module docstring

    m.def("add", &add, "A function that adds two numbers");
}

跑步时

python -c "from hello import example"
我得到
ModuleNotFoundError: No module named 'hello'
.

删除

src/hello/OtherModule/__init__.py
允许
scikit-build
打包模块,但我想要
hello.OtherModule
,所以这不是一个选项。

我已经尝试通过

pip install -e .
以及
python setup.py develop
在使用
conda
构建的
conda create --name so_example python=3.10 scikit-build ninja
环境中安装它并且没有安装其他任何东西。
hello.hello
C++ 模块似乎由
pybind11
正确构建,但是
hello
包本身没有正确安装,尽管
pip
声称它

成功安装hello-cpp-0.0.1

cmake setuptools python-packaging pybind11 scikit-build
© www.soinside.com 2019 - 2024. All rights reserved.