“在构建我自己的 pip 包时找不到 setuptools 的匹配发行版”

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

我正在使用 setuptools 构建一个 Python 包。这是基本结构:

/path/to/project/
    ├── myproj/                    
    │   ├── __init__.py             
    │   └── my_module.py       
    ├── pyproject.toml              
    ├── setup.cfg                   
    └── ## other stuff                               

这就是

pyproject.toml

的内容
[build-system]
requires = [
    "setuptools",
    "setuptools-scm"]
build-backend = "setuptools.build_meta"

这就是

setup.cfg

的内容
[project]
name = "my_package"
author = 'my name'
requires-python = ">=3.8"
keywords = ["one", "two"]
license = {text = "BSD-3-Clause"}
classifiers = []
dependencies = []

[metadata]
version = attr: my_package.__version__

[options]

zip_safe = True
packages = my_package
include_package_data = True
install_requires =
    matplotlib==3.6.0
    spacy==3.7.2
    networkx>=2.6.3
    nltk>=3.7
    shapely>=1.8.4
    pandas>=1.3.5
    community>=1.0.0b1
    python-louvain>=0.16
    numpy==1.23.4
    scipy


[options.package_data]
my_package = ## pointers to data

[options.packages.find]
exclude =
    examples*
    demos*

我可以成功运行了

python -m build
。然后,如果我在本地
pip install
它,即直接指向构建的
.tar
文件,我就可以安装它。

但是,如果我将其上传到 test.pypi,然后从 test.pypi

pip install
它,我会收到以下错误:

pip subprocess to install build dependencies did not run successfully.
  │ exit code: 1
  ╰─> [3 lines of output]
      Looking in indexes: https://test.pypi.org/simple/
      ERROR: Could not find a version that satisfies the requirement setuptools (from versions: none)
      ERROR: No matching distribution found for setuptools
      [end of output]
  
  note: This error originates from a subprocess, and is likely not a problem with pip.
error: subprocess-exited-with-error

× pip subprocess to install build dependencies did not run successfully.
│ exit code: 1
╰─> See above for output.

note: This error originates from a subprocess, and is likely not a problem with pip.

看起来像是安装工具的问题,但我真的不知道如何解决它。有什么建议吗?

python pip setuptools pypi python-packaging
1个回答
0
投票

但是,如果我将其上传到 test.pypi,然后从 test.pypi 进行 pip 安装

我认为这意味着您正在使用

--index-url https://test.pypi.org/simple/
,这已由构建输出
Looking in indexes: https://test.pypi.org/simple/
证实。这告诉 pip 使用 TestPyPI exclusively 作为包索引。您只能安装发布到 TestPyPI 的软件包,而 setuptools 则不能安装

如果您想在同一个

pip install
命令中同时安装来自 TestPyPI 和 PyPI 的软件包,您可以使用
--extra-index-url
而不是
index-url
。请注意,这意味着 any 包可以从 TestPyPI 或 PyPI 安装,但不能保证哪些包来自哪个索引。如果您想从特定索引安装特定包(例如 TestPyPI 中的
my_package
,以及 PyPI 中的其他所有内容),您可以尝试 从特定索引安装特定包中的解决方案。

© www.soinside.com 2019 - 2024. All rights reserved.