Search code examples
pythonpipsetuptoolspypipython-packaging

'No matching distribution found for setuptools' while building my own pip package


I am building a Python package using setuptools. This is the basic structure:

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

This is the content of pyproject.toml

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

and this is the content of 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*

I can run successfully python -m build. Then, if I pip install it locally, i.e., pointing directly to the .tar file that was built, I can install it.

However, if I upload it to test.pypi and then I pip install it from test.pypi, I get the following error:

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.

Looks like an issue with setuptools, but I really cannot figure out how to fix it. Any suggestions?


Solution

  • However, if I upload it to test.pypi and then I pip install it from test.pypi

    I assume this means you're using --index-url https://test.pypi.org/simple/, which is confirmed by the build output Looking in indexes: https://test.pypi.org/simple/. That tells pip to use TestPyPI exclusively as the package index. You will only be able to install packages that are published to TestPyPI, which setuptools is not.

    If you want to install packages from both TestPyPI and PyPI during the same pip install command, you can use --extra-index-url instead of index-url. Note that this means that any package can be installed from either TestPyPI or PyPI, with no guarantees as to which packages come from which index. If you want install particular packages from particular indices (e.g. my_package from TestPyPI, and everything else from PyPI), you can try the solutions from Install specific package from specific index.