添加一个最小的 `pyproject.toml` 悄悄地破坏了我的构建

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

我正在尝试在基于

their cpp example repo
的最小存储库中使用
pybind11
scikit-build。当尝试通过
pip install -e .
构建它时,pip 声称该文件“已成功安装”,但实际上并没有构建任何东西(我怀疑它甚至从未在
setup
中运行
setup.py
函数)。鉴于尝试使用该模块时出现错误消息
ImportError: cannot import name 'example' from 'hello'
,我可以确认它不起作用。

有趣的是,当我要么

    直接运行
  1. python setup.py develop
    (从而绕过
    pyproject.toml
    ,有压力)。为此,我通过
    setuptools
    scikit-build
    cmake
    pybind11
    ninja
    conda install X
    安装到相应的版本。
  2. 删除
  3. pyproject.toml
    ,依赖预安装的构建时依赖项。
我不明白我的

pyproject.toml

文件会有什么问题。谁能帮我找出问题所在?

我的项目布局是

hello-cpp ├── hello | └── __init__.py (empty) | └── hello.cpp ├── CMakeLists.txt ├── pyproject.toml ├── setup.py
setup.py:

from skbuild import setup setup( name="hello-cpp", version="1.2.3", description="a minimal example package (cpp version)", author="Me", license="MIT", packages=["hello"], python_requires=">=3.7", )
CMakeLists.txt:

cmake_minimum_required(VERSION 3.4...3.22) project(hello) find_package(pybind11 CONFIG REQUIRED) pybind11_add_module(example hello/hello.cpp) install(TARGETS example LIBRARY DESTINATION hello)
pyproject.toml(我会注意到,即使这里没有限制版本,问题仍然存在):

[build-system] requires = ["setuptools==65.6.3", "scikit-build==0.15.0", "cmake>=3.18", "pybind11==2.9.1", "ninja" ] build-backend = "setuptools.build_meta"
src/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"); }
我正在 Ubuntu 20 中尝试这个。

编辑: 我正在尝试在

conda

 环境中构建它,该环境除了 python=3.10(以及默认情况下捆绑的任何包)之外没有安装其他包。在
conda install
ing上面提到的包之后我也试过了。

在添加

ImportError

 时失败并显示 
pyproject.toml
 的 python 脚本是

python -c "from hello import example"
    
cmake setuptools python-packaging pybind11 scikit-build
© www.soinside.com 2019 - 2024. All rights reserved.