Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can't install detectron2 #2113

Closed
3 tasks done
ghost opened this issue Feb 29, 2020 · 30 comments
Closed
3 tasks done

Can't install detectron2 #2113

ghost opened this issue Feb 29, 2020 · 30 comments
Labels
kind/bug Something isn't working as expected

Comments

@ghost
Copy link

ghost commented Feb 29, 2020

  • I am on the latest Poetry version.
  • I have searched the issues of this repo and believe that this is not a duplicate.
  • If an exception occurs when executing a command, I executed it again in debug mode (-vvv option).
  • OS version and name: Arch Linux
  • Poetry version: 1.0.5
  • Contents of your pyproject.toml file:
[tool.poetry]
name = "a"
version = "0.1.0"
description = ""
authors = ["a"]

[tool.poetry.dependencies]
python = "^3.6"
detectron2 = { git = "https://github.com/facebookresearch/detectron2.git" }

[tool.poetry.dev-dependencies]

[build-system]
requires = ["poetry>=0.12"]
build-backend = "poetry.masonry.api"

Issue

Poetry can't figure out the version of detectron2. I've tried to debug this myself but the error messages don't tell me anything useful:

$ /tmp/poetry/bin/poetry install -vvv

Creating virtualenv a-1_qs6r2x-py3.8 in /home/x/.cache/pypoetry/virtualenvs
Using virtualenv: /home/x/.cache/pypoetry/virtualenvs/a-1_qs6r2x-py3.8
Updating dependencies
Resolving dependencies...
   1: fact: a is 0.1.0
   1: derived: a
   1: fact: a depends on detectron2 (*)
   1: selecting a (0.1.0)
   1: derived: detectron2 (*)
   1: Version solving took 3.842 seconds.
   1: Tried 1 solutions.

[RuntimeError]
Unable to retrieve the package version for /tmp/pypoetry-git-detectron2683igqav

Traceback (most recent call last):
  File "/tmp/poetry/lib/poetry/_vendor/py3.8/clikit/console_application.py", line 131, in run
    status_code = command.handle(parsed_args, io)
  File "/tmp/poetry/lib/poetry/_vendor/py3.8/clikit/api/command/command.py", line 120, in handle
    status_code = self._do_handle(args, io)
  File "/tmp/poetry/lib/poetry/_vendor/py3.8/clikit/api/command/command.py", line 171, in _do_handle
    return getattr(handler, handler_method)(args, io, self)
  File "/tmp/poetry/lib/poetry/_vendor/py3.8/cleo/commands/command.py", line 92, in wrap_handle
    return self.handle()
  File "/tmp/poetry/lib/poetry/console/commands/install.py", line 63, in handle
    return_code = installer.run()
  File "/tmp/poetry/lib/poetry/installation/installer.py", line 74, in run
    self._do_install(local_repo)
  File "/tmp/poetry/lib/poetry/installation/installer.py", line 161, in _do_install
    ops = solver.solve(use_latest=self._whitelist)
  File "/tmp/poetry/lib/poetry/puzzle/solver.py", line 36, in solve
    packages, depths = self._solve(use_latest=use_latest)
  File "/tmp/poetry/lib/poetry/puzzle/solver.py", line 180, in _solve
    result = resolve_version(
  File "/tmp/poetry/lib/poetry/mixology/__init__.py", line 7, in resolve_version
    return solver.solve()
  File "/tmp/poetry/lib/poetry/mixology/version_solver.py", line 80, in solve
    next = self._choose_package_version()
  File "/tmp/poetry/lib/poetry/mixology/version_solver.py", line 355, in _choose_package_version
    packages = self._provider.search_for(dependency)
  File "/tmp/poetry/lib/poetry/puzzle/provider.py", line 130, in search_for
    packages = self.search_for_vcs(dependency)
  File "/tmp/poetry/lib/poetry/puzzle/provider.py", line 167, in search_for_vcs
    package = self.get_package_from_vcs(
  File "/tmp/poetry/lib/poetry/puzzle/provider.py", line 204, in get_package_from_vcs
    package = cls.get_package_from_directory(tmp_dir, name=name)
  File "/tmp/poetry/lib/poetry/puzzle/provider.py", line 343, in get_package_from_directory
    raise RuntimeError(

Is poetry unable to get dynamically generated versions?

@ghost ghost added the kind/bug Something isn't working as expected label Feb 29, 2020
@malcolmgreaves
Copy link

Came to file a bug about not being able to install detectron2 -- as of poetry 1.1.3 it's still not installable.

detectron2 needs torch to install:

$ poetry install
Updating dependencies
Resolving dependencies... (4.5s)

  PackageInfoError

  Unable to determine package info for path: /tmp/pypoetry-git-detectron2dazfvgem

  Fallback egg_info generation failed.

  Command ['/tmp/tmpp_0xdcph/.venv/bin/python', 'setup.py', 'egg_info'] errored with the following return code 1, and output:
  Traceback (most recent call last):
    File "setup.py", line 10, in <module>
      import torch
  ModuleNotFoundError: No module named 'torch'

  at ~/.poetry/lib/poetry/inspection/info.py:503 in _pep517_metadata
      499│                     venv.run("python", "setup.py", "egg_info")
      500│                     return cls.from_metadata(path)
      501│                 except EnvCommandError as fbe:
      502│                     raise PackageInfoError(
    → 503│                         path, "Fallback egg_info generation failed.", fbe
      504│                     )
      505│                 finally:
      506│                     os.chdir(cwd.as_posix())
      507│

Even though I explicitly have torch as a dependency:

[tool.poetry]
name = "my_project"
version = "0.0.0"
description = ""
authors = ["Me <me@me.com>"]
license = "None"

[tool.poetry.dependencies]
python = "^3.7"
torch = "1.4"
detectron2 = { git = "https://github.com/facebookresearch/detectron2.git", branch = "master" }

[tool.poetry.dev-dependencies]

[build-system]
requires = ["poetry-core>=1.1.3"]
build-backend = "poetry.core.masonry.api"

Curiously, if I remove the detectron2 line, do poetry install, then add back the detectron2 line and do poetry shell, I am able to follow the project's installation instructions successfully:

poetry
python -m pip install 'git+https://github.com/facebookresearch/detectron2.git'

But, even if I do the above w/o manually doing python -m pip, i.e. a poetry update instead, (so there's still torch) it doesn't work (same error).

@malcolmgreaves
Copy link

malcolmgreaves commented Oct 17, 2020

I imagine this might be a difficult problem (building wheels from general setup.pys). Any chance that there's a way to have poetry try to install other dependencies first before doing git installable ones? (Does this even make sense? @finswimmer if you have any time to look into this 🙏 )

@abn
Copy link
Member

abn commented Oct 17, 2020

@malcolmgreaves the issue is that the library does not add torch to it's build-backend.requires. This is not something poetry can resolve, even if we install torch into the project's virtualenv. The build for detectron happens in it's own isolated environment with whatever it declares as it's build requirements.

The fix is for the project to add a pyproject.toml with the relevant build-system section.

@malcolmgreaves
Copy link

malcolmgreaves commented Oct 17, 2020

😭 Oh that's very unfortunate! I appreciate the very prompt reply @abn 💯 I'll try and bug the FAIR folk to see if this can be done.

@abn
Copy link
Member

abn commented Oct 17, 2020

No worries. Wish it was a more helpful response. You can just send them a PR with a minimal pyproject.toml. In the interim, you can use a branch on your fork with the change.

@malcolmgreaves
Copy link

malcolmgreaves commented Oct 17, 2020

@abn Would the minimum viable pyproject.toml be to specify that torch, alongside setuptools and wheel, is a requirement of the build system? i.e. does this formulation make sense?
https://github.com/malcolmgreaves/detectron2/pull/2/files malcolmgreaves/detectron2@3a42efe

(I originally first thought that I should make it a poetry project https://github.com/malcolmgreaves/detectron2/pull/1/files#diff-50c86b7ed8ac2cf95bd48334961bf0530cdc77b5a56f852c5c61b89d735fd711 But then realized that it should be possible to keep their build current build system, but just indicate that building the wheel requires torch too, right?)

@malcolmgreaves
Copy link

🎉 I have answered my own question -- just adding torch to requires in the build-system section is all that's necessary to get poetry to understand how to build the detectron2 wheel! 🎉

[build-system]
requires = ["setuptools", "wheel", "torch"]

@abn
Copy link
Member

abn commented Oct 17, 2020

@malcolmgreaves for completeness this is what you need to keep legacy build.

[build-system]
requires = ["setuptools", "wheel", "torch"]
build-backend = "setuptools.build_meta:__legacy__"

@malcolmgreaves
Copy link

malcolmgreaves commented Oct 17, 2020

Wonderful! Thank you a ton 💯 💯 🤗

@abn
Copy link
Member

abn commented Oct 17, 2020

I am going to close this issue as the original issue has been resolved and the current issue has to do with lack of PEP 517 metadata in the package source.

@abn abn closed this as completed Oct 17, 2020
@joostmeulenbeld
Copy link

joostmeulenbeld commented Oct 21, 2020

@malcolmgreaves I have this exact same issue, did you open an issue or pull request at the original Detectron2 repo?

@malcolmgreaves
Copy link

@joostmeulenbeld I have a workaround here -- you can poetry install this as a { git = ... } dependency
https://github.com/malcolmgreaves/detectron2

@iamlucaswolf
Copy link

@malcolmgreaves I just tried your workaround to integrate detectron2 with an existing project but still get errors... 😕

My pyproject.toml looks like this:

[tool.poetry.dependencies]
...
detectron2 = { git = "https://github.com/facebookresearch/detectron2.git"}

[build-system]
requires = ["setuptols", "wheel", "torch"]
build-backend = "setuptools.build_meta:__legacy__"

However, when I run poetry install, I get:

PackageInfoError

  Unable to determine package info for path: /tmp/pypoetry-git-detectron20h25u89n
  
  Fallback egg_info generation failed.
  
  Command ['/tmp/tmpi8lubyub/.venv/bin/python', 'setup.py', 'egg_info'] errored with the following return code 1, and output: 
  Traceback (most recent call last):
    File "/tmp/pypoetry-git-detectron20h25u89n/setup.py", line 10, in <module>
      import torch
  ModuleNotFoundError: No module named 'torch'

  at ~/.poetry/lib/poetry/inspection/info.py:502 in _pep517_metadata
      498try:
      499venv.run("python", "setup.py", "egg_info")
      500return cls.from_metadata(path)
      501except EnvCommandError as fbe:
    → 502raise PackageInfoError(
      503path, "Fallback egg_info generation failed.", fbe
      504│                     )
      505finally:
      506os.chdir(cwd.as_posix())

Any idea why that might be the case?

@lucinvitae
Copy link

I'm also still seeing this same issue with installing detectron2 using poetry 1.1.6 despite adding the poetry configuration mentioned in #2113 (comment)

Relevant poetry configuration:

[tool.poetry.dependencies]
python = "^3.8"
detectron2 = { git = "https://github.com/facebookresearch/detectron2.git", branch = "master" }

[build-system]
requires = ["poetry-core>=1.0.0", "setuptools", "wheel", "torch"]
build-backend = "setuptools.build_meta:__legacy__"

Exception stacktrace for poetry lock:

$ poetry lock
Updating dependencies
Resolving dependencies... (11.9s)

  PackageInfoError

  Unable to determine package info for path: /var/folders/1p/flnst32s2vv8gl821zrsn_hh0000gp/T/pypoetry-git-detectron2_rgh_58o

  Fallback egg_info generation failed.

  Command ['/var/folders/1p/flnst32s2vv8gl821zrsn_hh0000gp/T/tmpa6vvz2kw/.venv/bin/python', 'setup.py', 'egg_info'] errored with the following return code 1, and output:
  Traceback (most recent call last):
    File "setup.py", line 10, in <module>
      import torch
  ModuleNotFoundError: No module named 'torch'

  at ~/.pyenv/versions/3.8.9/envs/layoutlmv2_lib/lib/python3.8/site-packages/poetry/inspection/info.py:502 in _pep517_metadata
      498│                 try:
      499│                     venv.run("python", "setup.py", "egg_info")
      500│                     return cls.from_metadata(path)
      501│                 except EnvCommandError as fbe:
    → 502│                     raise PackageInfoError(
      503│                         path, "Fallback egg_info generation failed.", fbe
      504│                     )
      505│                 finally:
      506│                     os.chdir(cwd.as_posix())

poetry install fails similarly.

@abn I see that you closed this due to "lack of PEP 517 metadata in the package source.". However, is there the possibility of changing the way the detectron2 package is installed by adding the torch dependency beforehand somehow? e.g.

detectron2 = { git = "https://github.com/facebookresearch/detectron2.git", branch = "master", install_requires = "torch" }

I realize this may come across as a new feature request, but I'm not sure how else to proceed without forking the detectron2 project. If you see here, the maintainers of the detectron2 project do not appear open to fixing this issue on their side:

Because poetry does not support selecting cuda version #2145 there is no reasonable way to support detectron2.

For now, this is our workaround, in a project Dockerfile 😢

RUN poetry install -vvv --no-root \
    && pip uninstall poetry -y \
    && rm -rf ~/.config/pypoetry

# Workaround for issue where detectron2 cannot be installed with poetry:
# - https://github.com/python-poetry/poetry/issues/2113
# - https://github.com/facebookresearch/detectron2/issues/2644
RUN python -m pip install 'git+https://github.com/facebookresearch/detectron2.git'

@ppwwyyxx
Copy link

the maintainers of the detectron2 project do not appear open to fixing this issue on their side

We are open as long as there is a reasonable fix. From what I can see that's not the case due to limitations in poetry (and all other python package management tools).

@lucinvitae
Copy link

Thanks for chiming in, @ppwwyyxx, good to know that you are open to helping solve this issue. Maybe @abn or another maintainer (@sdispater?) from the poetry side has an idea how to remove such limitations.

The comments that @abn made above [1, 2] led me to believe this was something that needed to be addressed on the detectron2 project-side, and not the poetry side.

Perhaps the poetry maintainers require more information as to how they could remove the limitations you are mentioning. It's not clear to me, but for now, the result is that we cannot use poetry to install detectron2.

@mzhadigerov
Copy link

mzhadigerov commented Oct 29, 2021

I'm getting the same error as @lucinvitae . All I want to do is something similar to

pip install "git+https://github.com/facebookresearch/detectron2.git@v0.5#egg=detectron2"

@abn
Copy link
Member

abn commented Oct 30, 2021

@lucinvitae as far as I can tell, the issue here is the package build specification does to convey that it needs torch to successfully build the package. Let me know if this is not the case.

Fro poetry's perspective, we first need to build the bdist of the package if a compatible one is not already available on the configured indices. This will lead to a poetry attempting to build the package's wheel, this happens inside an ephemeral isolated build environment according to PEP-517. When creating this environment, the build-system requirements are installed. In this case, since the build scripts need torch available (#2113 (comment)). Essentially, something similar to the following is what happens under the hood.

root@c9958409c9fd:/# python -m pip wheel --disable-pip-version-check --use-pep517 git+https://github.com/facebookresearch/detectron2.git
Collecting git+https://github.com/facebookresearch/detectron2.git
  Cloning https://github.com/facebookresearch/detectron2.git to /tmp/pip-req-build-ax2ddphy
  Running command git clone -q https://github.com/facebookresearch/detectron2.git /tmp/pip-req-build-ax2ddphy
  Resolved https://github.com/facebookresearch/detectron2.git to commit c081505af16f54c5a013916b81636d03f7c0a8fd
  Installing build dependencies ... done
  Getting requirements to build wheel ... error
  ERROR: Command errored out with exit status 1:
   command: /usr/local/bin/python /usr/local/lib/python3.8/site-packages/pip/_vendor/pep517/in_process/_in_process.py get_requires_for_build_wheel /tmp/tmphk82qqi5
       cwd: /tmp/pip-req-build-ax2ddphy
  Complete output (18 lines):
  Traceback (most recent call last):
    File "/usr/local/lib/python3.8/site-packages/pip/_vendor/pep517/in_process/_in_process.py", line 349, in <module>
      main()
    File "/usr/local/lib/python3.8/site-packages/pip/_vendor/pep517/in_process/_in_process.py", line 331, in main
      json_out['return_val'] = hook(**hook_input['kwargs'])
    File "/usr/local/lib/python3.8/site-packages/pip/_vendor/pep517/in_process/_in_process.py", line 117, in get_requires_for_build_wheel
      return hook(config_settings)
    File "/tmp/pip-build-env-slhwwdsz/overlay/lib/python3.8/site-packages/setuptools/build_meta.py", line 154, in get_requires_for_build_wheel
      return self._get_build_requires(
    File "/tmp/pip-build-env-slhwwdsz/overlay/lib/python3.8/site-packages/setuptools/build_meta.py", line 135, in _get_build_requires
      self.run_setup()
    File "/tmp/pip-build-env-slhwwdsz/overlay/lib/python3.8/site-packages/setuptools/build_meta.py", line 258, in run_setup
      super(_BuildMetaLegacyBackend,
    File "/tmp/pip-build-env-slhwwdsz/overlay/lib/python3.8/site-packages/setuptools/build_meta.py", line 150, in run_setup
      exec(compile(code, __file__, 'exec'), locals())
    File "setup.py", line 10, in <module>
      import torch
  ModuleNotFoundError: No module named 'torch'
  ----------------------------------------
WARNING: Discarding git+https://github.com/facebookresearch/detectron2.git. Command errored out with exit status 1: /usr/local/bin/python /usr/local/lib/python3.8/site-packages/pip/_vendor/pep517/in_process/_in_process.py get_requires_for_build_wheel /tmp/tmphk82qqi5 Check the logs for full command output.
ERROR: Command errored out with exit status 1: /usr/local/bin/python /usr/local/lib/python3.8/site-packages/pip/_vendor/pep517/in_process/_in_process.py get_requires_for_build_wheel /tmp/tmphk82qqi5 Check the logs for full command output.

However, as @ppwwyyxx identified, there are other limitations that limit the options you have at the moment - ie. you cannot discover automatically the pre-built wheels provided by detectron2 nor can they distribute CUDA wheels on PyPI.

For instance, poetry resolver today does not handle local tags well neither does using link repositories work. This means that you cannot use the indices described in https://github.com/facebookresearch/detectron2/blob/main/INSTALL.md#install-pre-built-detectron2. However, you can use the direct links to the wheels here, but this assumes everwhere you install your package the same wheel can be used (this should be fine for cpu, alternatively you can have various extras. This is being fixed (partially done).

That said, I do not think the python packaging ecosystem has a decent solution for gpu packages anyway - eg. there is no standard way to determine if a cuda enabled wheel can be used in active environment.

Having the dependency metadata specify something like { ..., extra-build-requires = ["torch"] } might be an option, but I am not sure if we should start doing this. On the one hand, this enables poetry users to consume packages where similar issues exist more cleanly (this won't solve the gpu issue), on the other hand this is a workaround for lack of standard metadata.

Another option is to allow for something like { ..., build-allow-system-site = true }. In this case, the system packages are allowed for package builds.

What poetry should do in the near future are the following:

  1. Allow for --find-link type sources in projects.
  2. Support local version tags for dependency resolution and package installation.

I still think that the torch dependency need to be declared in the project's metadata (not in downstream packages) if it is required at build time, so that PEP-517 builds can work correctly.

As for the gpu specific versions, I am not sure where this needs to go. Ideally, there will be a packaging PEP that will help tools like 'poetry' to implement a standardised approach.

@abn
Copy link
Member

abn commented Oct 30, 2021

Also, I'd recommend this moves to a discussion instead of this closed issue.

@mzhadigerov
Copy link

What's the solution, then? How to add detectron2 using poetry? @abn

devcsrj added a commit to devcsrj/detectron2 that referenced this issue Dec 17, 2021
The new pyproject.toml specifies the minimum requirements necessary to build
the project's wheel. This makes this project up to the PEP-518 standard.

Specifically, this change adds torch as a build-time dependency. The
version of torch can be set by the installer when they specify a version
of torch in their own project settings (e.g. a pyproject.toml,
requirements.txt, setup.py, environment.yaml, etc.). Alteratively,
if torch is in the current installing environment, that version will be
used. If not specified, the latest torch version will be used.

This change preserves using `setup.py` for project building.

python-poetry/poetry#2113
@satishjasthi
Copy link

@malcolmgreaves for completeness this is what you need to keep legacy build.

[build-system]
requires = ["setuptools", "wheel", "torch"]
build-backend = "setuptools.build_meta:__legacy__"

Thanks a lot this solution works
once you update it, just use
poetry add path_to_detectron2_wheel_file

@Maciej-Zwolinski
Copy link

This seems to no longer work - or at least not in the general case.

The issue that everyone seems to be missing - please correct me if I'm wrong about it - is that simply specifying torch or even torch==1.10.2 in build-system section of detectron2 does not solve the true problem - that is that torch version you install - whatever that version might be - has to be compiled for the same CUDA version you have on your machine.

Since torch available @pypi is compiled by default with CUDA 10.2 (or at least newer versions are), this FORCES CUDA 10.2 onto your system - something the authors of detectron2 have no chance of fixing. @ppwwyyxx

The problem runs even deeper. Even if detectron2 is forked, and proper version of torch is required in the minimal pyproject.toml, there is seems to be no way (@1) of forcing build process to download and use custom wheel - such as available at https://download.pytorch.org/whl/cu113 - which would be required to build detectron2 using specific CUDA version...

^1. please confirm this, I'm new to setuptools and custom package building in general.

@helpmefindaname
Copy link

I managed to get it run by specifying:

[build-system]
requires = ["setuptools", "wheel", "torch==1.10.2+cu113", "torchvision==0.11.3+cu113", "ninja2"]
build-backend = "setuptools.build_meta:__legacy__"

in a detectron2 fork

using the following config

[tool.poetry]
name = "test_detectron_poetry"
version = "0.1.0"
description = ""
authors = ["Benedikt Fuchs <benedikt.fuchs.staw@hotmail.com>"]

[[tool.poetry.source]]
name = "torch"
url = "https://download.pytorch.org/whl/"
secondary = true
default = false

[tool.poetry.dependencies]
python = "3.8.*"
torch = {version = "1.10.2+cu113", source = "torch"}
torchvision = "0.11.3+cu113"
detectron2 = {git = "https://github.com/helpmefindaname/detectron2.git", rev = "main"}

[tool.poetry.dev-dependencies]

[build-system]
requires = ["poetry-core>=1.0.0"]
build-backend = "poetry.core.masonry.api"

using poetry==1.2.0b2 following this issue, it is important to mention that this file will not work on the latest non-beta release

and additionally adding https://download.pytorch.org/whl as an extra index in the global git config file

The last step is necessary, as PEP-518 specifies to use isolated builds for building wheels, so the index specified in poetry won't be used. However, globally configured indexes will also be used by the newly isolated venv.

Some side notes:

  • on ubuntu, you need to have gcc and g++ version below 10.*, so you might have to manually downgrade the versions.
  • I tried to get it to run on windows first, however there venv didn't manage to copy the isolated venv to a temp folder, failing the build before any detectron2 related code was executed. I suppose this is not related to this issue. I don't understand why that happens or if that is specific to my setup or not.
  • You can expect to take a very long time for the first time. Even with setting python="3.8.*" it will download wheels for a veriety of python versions. You might want to ensure that pip cache lost is working before starting installing it. I had it disabled for some reason, which made it frustrating when my internet crashed, and I had to start downloading some wheels again.

@swicaksono
Copy link

Hi, does anyone have any solution to this issue? I still can't find a way to install detectron2. I tried #2113 (comment) but got an error:

Resolving dependencies... (7.9s)

  CalledProcessError

  Command '['/tmp/tmpbzglt_2o/.venv/bin/python', '-']' returned non-zero exit status 1.

  at ~/.pyenv/versions/3.8.11/lib/python3.8/subprocess.py:516 in run
       512│             # We don't call process.wait() as .__exit__ does that for us.
       513│             raise
       514│         retcode = process.poll()
       515│         if check and retcode:
    →  516│             raise CalledProcessError(retcode, process.args,
       517│                                      output=stdout, stderr=stderr)
       518│     return CompletedProcess(process.args, retcode, stdout, stderr)
       519│ 
       520│ 

The following error occurred when trying to handle this error:


  EnvCommandError

  Command ['/tmp/tmpbzglt_2o/.venv/bin/python', '-'] errored with the following return code 1, and output: 
  ERROR: Could not find a version that satisfies the requirement torchvision==0.11.3+cu113 (from versions: 0.1.6, 0.1.7, 0.1.8, 0.1.9, 0.2.0, 0.2.1, 0.2.2, 0.2.2.post2, 0.2.2.post3, 0.5.0, 0.6.0, 0.6.1, 0.7.0, 0.8.0, 0.8.1, 0.8.2, 0.9.0, 0.9.1, 0.10.0, 0.10.1, 0.11.0, 0.11.1, 0.11.2, 0.11.3, 0.12.0, 0.13.0, 0.13.1)
  ERROR: No matching distribution found for torchvision==0.11.3+cu113
  WARNING: You are using pip version 21.1.1; however, version 22.2.2 is available.
  You should consider upgrading via the '/tmp/build-env-wccfwciw/bin/python -m pip install --upgrade pip' command.
  Traceback (most recent call last):
    File "<stdin>", line 15, in <module>
    File "/tmp/tmpbzglt_2o/.venv/lib/python3.8/site-packages/build/env.py", line 211, in install
      _subprocess(cmd)
    File "/tmp/tmpbzglt_2o/.venv/lib/python3.8/site-packages/build/env.py", line 81, in _subprocess
      raise e
    File "/tmp/tmpbzglt_2o/.venv/lib/python3.8/site-packages/build/env.py", line 78, in _subprocess
      subprocess.check_output(cmd, stderr=subprocess.STDOUT)
    File "/home/sonywicaksono/.pyenv/versions/3.8.11/lib/python3.8/subprocess.py", line 415, in check_output
      return run(*popenargs, stdout=PIPE, timeout=timeout, check=True,
    File "/home/sonywicaksono/.pyenv/versions/3.8.11/lib/python3.8/subprocess.py", line 516, in run
      raise CalledProcessError(retcode, process.args,
  subprocess.CalledProcessError: Command '['/tmp/build-env-wccfwciw/bin/python', '-Im', 'pip', 'install', '--use-pep517', '--no-warn-script-location', '-r', '/tmp/build-reqs-u1urbb0b.txt']' returned non-zero exit status 1.
  input was : import build
  import build.env
  import pep517
  
  source = '/tmp/pypoetry-git-detectron2qmhb669o'
  dest = '/tmp/tmpbzglt_2o/dist'
  
  with build.env.IsolatedEnvBuilder() as env:
      builder = build.ProjectBuilder(
          srcdir=source,
          scripts_dir=env.scripts_dir,
          python_executable=env.executable,
          runner=pep517.quiet_subprocess_runner,
      )
      env.install(builder.build_system_requires)
      env.install(builder.get_requires_for_build('wheel'))
      builder.metadata_path(dest)
  

  at ~/.pyenv/versions/3.8.11/lib/python3.8/site-packages/poetry/utils/env.py:1421 in _run
      1417│                 output = subprocess.check_output(
      1418│                     cmd, stderr=subprocess.STDOUT, env=env, **kwargs
      1419│                 )
      1420│         except CalledProcessError as e:
    → 1421│             raise EnvCommandError(e, input=input_)
      1422│ 
      1423│         return decode(output)
      1424│ 
      1425│     def execute(self, bin: str, *args: str, **kwargs: Any) -> int | None:

The following error occurred when trying to handle this error:


  CalledProcessError

  Command '['/tmp/tmpbzglt_2o/.venv/bin/python', 'setup.py', 'egg_info']' returned non-zero exit status 1.

  at ~/.pyenv/versions/3.8.11/lib/python3.8/subprocess.py:516 in run
       512│             # We don't call process.wait() as .__exit__ does that for us.
       513│             raise
       514│         retcode = process.poll()
       515│         if check and retcode:
    →  516│             raise CalledProcessError(retcode, process.args,
       517│                                      output=stdout, stderr=stderr)
       518│     return CompletedProcess(process.args, retcode, stdout, stderr)
       519│ 
       520│ 

The following error occurred when trying to handle this error:


  EnvCommandError

  Command ['/tmp/tmpbzglt_2o/.venv/bin/python', 'setup.py', 'egg_info'] errored with the following return code 1, and output: 
  Traceback (most recent call last):
    File "setup.py", line 10, in <module>
      import torch
  ModuleNotFoundError: No module named 'torch'
  

  at ~/.pyenv/versions/3.8.11/lib/python3.8/site-packages/poetry/utils/env.py:1421 in _run
      1417│                 output = subprocess.check_output(
      1418│                     cmd, stderr=subprocess.STDOUT, env=env, **kwargs
      1419│                 )
      1420│         except CalledProcessError as e:
    → 1421│             raise EnvCommandError(e, input=input_)
      1422│ 
      1423│         return decode(output)
      1424│ 
      1425│     def execute(self, bin: str, *args: str, **kwargs: Any) -> int | None:

The following error occurred when trying to handle this error:


  PackageInfoError

  Unable to determine package info for path: /tmp/pypoetry-git-detectron2qmhb669o
  
  Fallback egg_info generation failed.
  
  Command ['/tmp/tmpbzglt_2o/.venv/bin/python', 'setup.py', 'egg_info'] errored with the following return code 1, and output: 
  Traceback (most recent call last):
    File "setup.py", line 10, in <module>
      import torch
  ModuleNotFoundError: No module named 'torch'

@neersighted
Copy link
Member

Hi, does anyone have any solution to this issue? I still can't find a way to install detectron2. I tried #2113 (comment) but got an error:

Resolving dependencies... (7.9s)

  CalledProcessError

  Command '['/tmp/tmpbzglt_2o/.venv/bin/python', '-']' returned non-zero exit status 1.

  at ~/.pyenv/versions/3.8.11/lib/python3.8/subprocess.py:516 in run
       512│             # We don't call process.wait() as .__exit__ does that for us.
       513│             raise
       514│         retcode = process.poll()
       515│         if check and retcode:
    →  516│             raise CalledProcessError(retcode, process.args,
       517│                                      output=stdout, stderr=stderr)
       518│     return CompletedProcess(process.args, retcode, stdout, stderr)
       519│ 
       520│ 

The following error occurred when trying to handle this error:


  EnvCommandError

  Command ['/tmp/tmpbzglt_2o/.venv/bin/python', '-'] errored with the following return code 1, and output: 
  ERROR: Could not find a version that satisfies the requirement torchvision==0.11.3+cu113 (from versions: 0.1.6, 0.1.7, 0.1.8, 0.1.9, 0.2.0, 0.2.1, 0.2.2, 0.2.2.post2, 0.2.2.post3, 0.5.0, 0.6.0, 0.6.1, 0.7.0, 0.8.0, 0.8.1, 0.8.2, 0.9.0, 0.9.1, 0.10.0, 0.10.1, 0.11.0, 0.11.1, 0.11.2, 0.11.3, 0.12.0, 0.13.0, 0.13.1)
  ERROR: No matching distribution found for torchvision==0.11.3+cu113
  WARNING: You are using pip version 21.1.1; however, version 22.2.2 is available.
  You should consider upgrading via the '/tmp/build-env-wccfwciw/bin/python -m pip install --upgrade pip' command.
  Traceback (most recent call last):
    File "<stdin>", line 15, in <module>
    File "/tmp/tmpbzglt_2o/.venv/lib/python3.8/site-packages/build/env.py", line 211, in install
      _subprocess(cmd)
    File "/tmp/tmpbzglt_2o/.venv/lib/python3.8/site-packages/build/env.py", line 81, in _subprocess
      raise e
    File "/tmp/tmpbzglt_2o/.venv/lib/python3.8/site-packages/build/env.py", line 78, in _subprocess
      subprocess.check_output(cmd, stderr=subprocess.STDOUT)
    File "/home/sonywicaksono/.pyenv/versions/3.8.11/lib/python3.8/subprocess.py", line 415, in check_output
      return run(*popenargs, stdout=PIPE, timeout=timeout, check=True,
    File "/home/sonywicaksono/.pyenv/versions/3.8.11/lib/python3.8/subprocess.py", line 516, in run
      raise CalledProcessError(retcode, process.args,
  subprocess.CalledProcessError: Command '['/tmp/build-env-wccfwciw/bin/python', '-Im', 'pip', 'install', '--use-pep517', '--no-warn-script-location', '-r', '/tmp/build-reqs-u1urbb0b.txt']' returned non-zero exit status 1.
  input was : import build
  import build.env
  import pep517
  
  source = '/tmp/pypoetry-git-detectron2qmhb669o'
  dest = '/tmp/tmpbzglt_2o/dist'
  
  with build.env.IsolatedEnvBuilder() as env:
      builder = build.ProjectBuilder(
          srcdir=source,
          scripts_dir=env.scripts_dir,
          python_executable=env.executable,
          runner=pep517.quiet_subprocess_runner,
      )
      env.install(builder.build_system_requires)
      env.install(builder.get_requires_for_build('wheel'))
      builder.metadata_path(dest)
  

  at ~/.pyenv/versions/3.8.11/lib/python3.8/site-packages/poetry/utils/env.py:1421 in _run
      1417│                 output = subprocess.check_output(
      1418│                     cmd, stderr=subprocess.STDOUT, env=env, **kwargs
      1419│                 )
      1420│         except CalledProcessError as e:
    → 1421│             raise EnvCommandError(e, input=input_)
      1422│ 
      1423│         return decode(output)
      1424│ 
      1425│     def execute(self, bin: str, *args: str, **kwargs: Any) -> int | None:

The following error occurred when trying to handle this error:


  CalledProcessError

  Command '['/tmp/tmpbzglt_2o/.venv/bin/python', 'setup.py', 'egg_info']' returned non-zero exit status 1.

  at ~/.pyenv/versions/3.8.11/lib/python3.8/subprocess.py:516 in run
       512│             # We don't call process.wait() as .__exit__ does that for us.
       513│             raise
       514│         retcode = process.poll()
       515│         if check and retcode:
    →  516│             raise CalledProcessError(retcode, process.args,
       517│                                      output=stdout, stderr=stderr)
       518│     return CompletedProcess(process.args, retcode, stdout, stderr)
       519│ 
       520│ 

The following error occurred when trying to handle this error:


  EnvCommandError

  Command ['/tmp/tmpbzglt_2o/.venv/bin/python', 'setup.py', 'egg_info'] errored with the following return code 1, and output: 
  Traceback (most recent call last):
    File "setup.py", line 10, in <module>
      import torch
  ModuleNotFoundError: No module named 'torch'
  

  at ~/.pyenv/versions/3.8.11/lib/python3.8/site-packages/poetry/utils/env.py:1421 in _run
      1417│                 output = subprocess.check_output(
      1418│                     cmd, stderr=subprocess.STDOUT, env=env, **kwargs
      1419│                 )
      1420│         except CalledProcessError as e:
    → 1421│             raise EnvCommandError(e, input=input_)
      1422│ 
      1423│         return decode(output)
      1424│ 
      1425│     def execute(self, bin: str, *args: str, **kwargs: Any) -> int | None:

The following error occurred when trying to handle this error:


  PackageInfoError

  Unable to determine package info for path: /tmp/pypoetry-git-detectron2qmhb669o
  
  Fallback egg_info generation failed.
  
  Command ['/tmp/tmpbzglt_2o/.venv/bin/python', 'setup.py', 'egg_info'] errored with the following return code 1, and output: 
  Traceback (most recent call last):
    File "setup.py", line 10, in <module>
      import torch
  ModuleNotFoundError: No module named 'torch'

Please refer to the thread -- detectron has undeclared build-time dependencies and needs to be patched to either declare them or not require them. The correct incantations in pyproject.toml in detectron (most users having issues incorrectly added them to their project) are posted above. An upstream issue on this topic is locked, here: facebookresearch/detectron2#2644

See this user's commit for an example of the patch:

devcsrj/detectron2@c37c1fd

If you have more questions, please start a Discussion or join Discord -- this issue is not a great forum for support as problems in Poetry are already solved, and we are notifying many users unnecessarily.

jim80net added a commit to RamTank/detectron2 that referenced this issue Apr 5, 2023
The missing pyproject.toml results in an inability to install detectron2 via poetry.

fixes python-poetry/poetry#2113
@codingbutstillalive
Copy link

Has this issue been solved?

@ppwwyyxx
Copy link

All the claimed "solutions" or patches so far are incorrect, as explained in #2113 (comment). This is why detectron2 did not accept any of these solutions.

@codingbutstillalive
Copy link

@lucinvitae as far as I can tell, the issue here is the package build specification does to convey that it needs torch to successfully build the package. Let me know if this is not the case.

Fro poetry's perspective, we first need to build the bdist of the package if a compatible one is not already available on the configured indices. This will lead to a poetry attempting to build the package's wheel, this happens inside an ephemeral isolated build environment according to PEP-517. When creating this environment, the build-system requirements are installed. In this case, since the build scripts need torch available (#2113 (comment)). Essentially, something similar to the following is what happens under the hood.

root@c9958409c9fd:/# python -m pip wheel --disable-pip-version-check --use-pep517 git+https://github.com/facebookresearch/detectron2.git

Collecting git+https://github.com/facebookresearch/detectron2.git

  Cloning https://github.com/facebookresearch/detectron2.git to /tmp/pip-req-build-ax2ddphy

  Running command git clone -q https://github.com/facebookresearch/detectron2.git /tmp/pip-req-build-ax2ddphy

  Resolved https://github.com/facebookresearch/detectron2.git to commit c081505af16f54c5a013916b81636d03f7c0a8fd

  Installing build dependencies ... done

  Getting requirements to build wheel ... error

  ERROR: Command errored out with exit status 1:

   command: /usr/local/bin/python /usr/local/lib/python3.8/site-packages/pip/_vendor/pep517/in_process/_in_process.py get_requires_for_build_wheel /tmp/tmphk82qqi5

       cwd: /tmp/pip-req-build-ax2ddphy

  Complete output (18 lines):

  Traceback (most recent call last):

    File "/usr/local/lib/python3.8/site-packages/pip/_vendor/pep517/in_process/_in_process.py", line 349, in <module>

      main()

    File "/usr/local/lib/python3.8/site-packages/pip/_vendor/pep517/in_process/_in_process.py", line 331, in main

      json_out['return_val'] = hook(**hook_input['kwargs'])

    File "/usr/local/lib/python3.8/site-packages/pip/_vendor/pep517/in_process/_in_process.py", line 117, in get_requires_for_build_wheel

      return hook(config_settings)

    File "/tmp/pip-build-env-slhwwdsz/overlay/lib/python3.8/site-packages/setuptools/build_meta.py", line 154, in get_requires_for_build_wheel

      return self._get_build_requires(

    File "/tmp/pip-build-env-slhwwdsz/overlay/lib/python3.8/site-packages/setuptools/build_meta.py", line 135, in _get_build_requires

      self.run_setup()

    File "/tmp/pip-build-env-slhwwdsz/overlay/lib/python3.8/site-packages/setuptools/build_meta.py", line 258, in run_setup

      super(_BuildMetaLegacyBackend,

    File "/tmp/pip-build-env-slhwwdsz/overlay/lib/python3.8/site-packages/setuptools/build_meta.py", line 150, in run_setup

      exec(compile(code, __file__, 'exec'), locals())

    File "setup.py", line 10, in <module>

      import torch

  ModuleNotFoundError: No module named 'torch'

  ----------------------------------------

WARNING: Discarding git+https://github.com/facebookresearch/detectron2.git. Command errored out with exit status 1: /usr/local/bin/python /usr/local/lib/python3.8/site-packages/pip/_vendor/pep517/in_process/_in_process.py get_requires_for_build_wheel /tmp/tmphk82qqi5 Check the logs for full command output.

ERROR: Command errored out with exit status 1: /usr/local/bin/python /usr/local/lib/python3.8/site-packages/pip/_vendor/pep517/in_process/_in_process.py get_requires_for_build_wheel /tmp/tmphk82qqi5 Check the logs for full command output.

However, as @ppwwyyxx identified, there are other limitations that limit the options you have at the moment - ie. you cannot discover automatically the pre-built wheels provided by detectron2 nor can they distribute CUDA wheels on PyPI.

For instance, poetry resolver today does not handle local tags well neither does using link repositories work. This means that you cannot use the indices described in https://github.com/facebookresearch/detectron2/blob/main/INSTALL.md#install-pre-built-detectron2. However, you can use the direct links to the wheels here, but this assumes everwhere you install your package the same wheel can be used (this should be fine for cpu, alternatively you can have various extras. This is being fixed (partially done).

That said, I do not think the python packaging ecosystem has a decent solution for gpu packages anyway - eg. there is no standard way to determine if a cuda enabled wheel can be used in active environment.

Having the dependency metadata specify something like { ..., extra-build-requires = ["torch"] } might be an option, but I am not sure if we should start doing this. On the one hand, this enables poetry users to consume packages where similar issues exist more cleanly (this won't solve the gpu issue), on the other hand this is a workaround for lack of standard metadata.

Another option is to allow for something like { ..., build-allow-system-site = true }. In this case, the system packages are allowed for package builds.

What poetry should do in the near future are the following:

  1. Allow for --find-link type sources in projects.

  2. Support local version tags for dependency resolution and package installation.

I still think that the torch dependency need to be declared in the project's metadata (not in downstream packages) if it is required at build time, so that PEP-517 builds can work correctly.

As for the gpu specific versions, I am not sure where this needs to go. Ideally, there will be a packaging PEP that will help tools like 'poetry' to implement a standardised approach.

Has this been addressed / solved in the meantime? The standard installation still does not work. But what about the many suggested modifications to poetry that you outlined. Have they been implemented? How can you install detectron2 now with poetry?

@zengjie617789
Copy link

just using the executable python to run the setup script, like: cd ../detectron2 && /root/.cache/pypoetry/virtualenvs/image-inpainting-WGCBfPov-py3.10/bin/python setup.py install

Copy link

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Feb 29, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
kind/bug Something isn't working as expected
Projects
None yet
Development

No branches or pull requests