【问题标题】:Transition from single to multi module project with python SIP使用 python SIP 从单模块项目过渡到多模块项目
【发布时间】:2021-01-26 16:52:48
【问题描述】:

我在 foo_b 中导入 foo_a 时遇到问题。假设在两个 .toml 文件中定义的顶级包将被称为 foo.sip。 这意味着例如foo_b 的 pyproject.toml 看起来像这样:

# Specify sip v6 as the build system for the package.
[build-system]
requires = ["sip >=6, <7"]
build-backend = "sipbuild.api"

# Specify the PEP 566 metadata for the project.
[tool.sip.metadata]
name = "foo-foo_b"
requires-dist = "foo-foo_a"

# Configure the building of the project bindings.
[tool.sip.bindings.foo_b]
<dependencies ...>

[tool.sip.project]
sip-module = "foo.sip"

我有以下项目结构:

  • dir_a

    • foo_b.cpp
    • foo_b.h
    • pyproject.toml
    • foo_b.sip
    • test_b.py
  • dir_b

    • foo_a.cpp
    • foo_a.h
    • pyproject.toml
    • foo_a.sip
    • test_a.py

如果我删除 [tool.sip.project] 下的 sip-module 条目

sip-module = foo.sip

从foo_a的.toml文件中导入foo_a

from foo import foo_a

在 test_a.py 中工作正常。但是如果我尝试用这个条目构建一个包项目,就会出现以下错误:

ModuleNotFoundError: No module named 'foo.sip'

系统上的安装是用sip-install完成的,先在dir_a,然后在dir_b。

I tried to structure my package project like it is in this example more or less described

但我错过了什么?

【问题讨论】:

    标签: python python-packaging python-sip


    【解决方案1】:

    在我发布的示例项目的链接中,有一个创建 sdist 的步骤。必须先安装 sdist 以准备创建顶级包。 对于 foo 示例,我执行了以下操作:

    sip-module --sdist foo.sip
    pip install foo_sip...tar.gz
    cd dir_a
    sip-install
    cd ../dir_b
    sip-install
    

    更新: 从 sdist 和其他子项目中构建一个轮子并使用 pip 安装所有东西对我来说是最好的方法。

    【讨论】:

      猜你喜欢
      • 2014-09-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-07-21
      • 2018-02-06
      • 2017-09-20
      • 1970-01-01
      相关资源
      最近更新 更多