Optional dependencies ordering

I am trying to packaging using the following pyproject.toml file :

name = "mypkg"
version = "0.0.1"
requires-python = ">=3.8"
classifiers = [
    "Programming Language :: Python :: 3",
    "License :: OSI Approved :: MIT License",
    "Operating System :: OS Independent",
dependencies = [

requires = ["setuptools"]
build-backend = "setuptools.build_meta"

torch = ["torch","torchinterp1d@git+https://github.com/aliutkus/torchinterp1d"]

When installing my package into a fresh virtual environment using

pip install .[torch]

I obtain an error because torch is needed to install the torchinterp1 dependency:

  │ exit code: 1
  ╰─> [13 lines of output]
      Traceback (most recent call last):
        File "/tmp/pip-install-7ybk_fq5/torchinterp1d_298c86f7d4de431592653b4512b7b4c9/setup.py", line 8, in <module>
          import torch
      ModuleNotFoundError: No module named 'torch'

When installing torch alone and trying again, the package installation works fine. Is there a way to ensure that torch installation is done before the installation of torchinterp1? Thanks!

I consider torchinterp1d to be in error, as its setup.py imports torch in order to ensure that it’s installed, yet the setup.py makes no use of torch after that, and the package already declares torch as a runtime dependency anyway (so normal package installation will already ensure that torch is installed — except that, because of the torch import, the requirements can’t even be determined when installing from source unless torch is already in the environment). I suggest you file a PR with the project to remove these lines.


Thank you very much, I will do a pull request as you suggested.

Done here, thank you again.