Calling `poetry.core.masonry.api.get_requires_for_build_editable()` DEBUG No workspace root found, using project root DEBUG Calling `poetry.core.masonry.api.prepare_metadata_for_build_editable()` DEBUG Traceback (most recent call last): DEBUG File "<string>", line 14, in <module> DEBUG File "C:\Users\g30036847\AppData\Local\uv\cache\builds-v0\.tmp1pLFqS\Lib\site-packages\poetry\core\masonry\api.py", line 43, in prepare_metadata_for_build_wheel DEBUG builder = WheelBuilder(poetry, config_settings=config_settings) DEBUG ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ DEBUG File "C:\Users\g30036847\AppData\Local\uv\cache\builds-v0\.tmp1pLFqS\Lib\site-packages\poetry\core\masonry\builders\wheel.py", line 67, in __init__ DEBUG super().__init__(poetry, executable=executable, config_settings=config_settings) DEBUG File "C:\Users\g30036847\AppData\Local\uv\cache\builds-v0\.tmp1pLFqS\Lib\site-packages\poetry\core\masonry\builders\builder.py", line 40, in __init__ DEBUG raise RuntimeError( DEBUG RuntimeError: Building a package is not possible in non-package mode. DEBUG Released lock at `C:\Users\g30036847\AppData\Local\uv\cache\sdists-v9\editable\30f9bc5ef56419f1\.lock` DEBUG Released lock at `D:\projects\AI\dify-huawei\api\.venv\.lock` error: Failed to generate package metadata for `dify-api @ editable+.` Caused by: The build backend returned an error Caused by: Call to `poetry.core.masonry.api.prepare_metadata_for_build_editable` failed (exit code: 1) [stderr] Traceback (most recent call last): File "<string>", line 14, in <module> File "C:\Users\g30036847\AppData\Local\uv\cache\builds-v0\.tmp1pLFqS\Lib\site-packages\poetry\core\masonry\api.py", line 43, in prepare_metadata_for_build_wheel builder = WheelBuilder(poetry, config_settings=config_settings) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\g30036847\AppData\Local\uv\cache\builds-v0\.tmp1pLFqS\Lib\site-packages\poetry\core\masonry\builders\wheel.py", line 67, in __init__ super().__init__(poetry, executable=executable, config_settings=config_settings) File "C:\Users\g30036847\AppData\Local\uv\cache\builds-v0\.tmp1pLFqS\Lib\site-packages\poetry\core\masonry\builders\builder.py", line 40, in __init__ raise RuntimeError( RuntimeError: Building a package is not possible in non-package mode. hint: This usually indicates a problem with the package or the build environment.
时间: 2025-07-10 08:11:17 浏览: 17
当使用 Poetry 构建 Python 包时,如果遇到错误提示 `Building a package is not possible in non-package mode`,这通常意味着当前目录中缺少有效的 `pyproject.toml` 文件,或者该文件未正确配置为可构建的包。
### 原因分析
Poetry 要求项目必须具备一个符合 PEP 517 和 PEP 518 标准的 `pyproject.toml` 文件。如果没有这个文件,或其内容未定义 `build-system` 和 `tool.poetry` 部分,则无法进入包构建模式(package mode),从而导致上述错误[^1]。
### 解决方案
#### 1. 确保存在 `pyproject.toml`
如果当前目录中没有 `pyproject.toml` 文件,请运行以下命令初始化:
```bash
poetry init
```
此命令会引导你创建一个基本的 `pyproject.toml` 文件,包含必要的元数据和依赖项信息[^1]。
#### 2. 检查 `pyproject.toml` 内容
确保 `pyproject.toml` 文件中包含正确的 `tool.poetry` 配置,并且至少定义了 `name`, `version`, `description`, `authors` 等字段。例如:
```toml
[tool.poetry]
name = "my-package"
version = "0.1.0"
description = "My Python Package"
authors = ["Your Name <[email protected]>"]
[tool.poetry.dependencies]
python = "^3.8"
[build-system]
requires = ["poetry-core>=1.0.0"]
build-backend = "poetry.core.masonry.api"
```
#### 3. 使用 `poetry build` 构建包
在确保 `pyproject.toml` 正确无误后,运行以下命令进行构建:
```bash
poetry build
```
该命令将生成 `dist/` 目录,并在里面放置 `.tar.gz` 和 `.whl` 格式的包文件[^1]。
#### 4. 可编辑安装包
如果你希望以可编辑模式安装包,请使用:
```bash
poetry install --editable
```
或者简写为:
```bash
poetry install -e
```
这将允许你在开发过程中对代码的修改立即生效,而无需每次重新安装包[^1]。
---
阅读全文
相关推荐













