Cannot install the gpu version of torch and torchvision in poetry due to a dependency problem
I am trying to create a virtual environment for machine learning using poetry. So, I am using pytorch as a framework for deep learning. I will extract the relevant part of my pyproject.toml.
[tool.poetry.dependencies].
python = &quot;^3.8&quot;
torch = { url = &quot;https://download.pytorch.org/whl/cu111/torch-1.8.0%2Bcu111-cp38-cp38-linux_x86_64.whl&quot;}
torchvision = { url = &quot;https://download.pytorch.org/whl/cu111/torchvision-0.9.0%2Bcu111-cp38-cp38-linux_x86_64.whl&quot; }

Since pytroch uses the GPU, you need to install it by specifying the whl file. If you install it this way, the version of pytroch will be 1.8.0+cu111. torchvision corresponding to 1.8.0 of pytorch is 0.9.0. The version of pytroch that this torchvision depends on is 1.8.0 (without cu111). Therefore, I cannot create a virtual environment using poetry with the following error.

  SolverProblemError

  Because torchvision (0.9.0) depends on torch (1.8.0)
   and mdwithpriorenergy depends on torch (1.8.0+cu111), torchvision is forbidden.
  So, because mdwithpriorenergy depends on torchvision (0.9.0), version solving failed.

So, because [env name] depends on torchvision (0.9.0), version solving failed. 


I also made the following changes to torchvision in pyproject.toml above, but they did not work.
[tool.poetry.dependencies].
python = &quot;^3.8&quot;
torch = { url = &quot;https://download.pytorch.org/whl/cu111/torch-1.8.0%2Bcu111-cp38-cp38-linux_x86_64.whl&quot;}
- torchvision = { url = &quot;https://download.pytorch.org/whl/cu111/torchvision-0.9.0%2Bcu111-cp38-cp38-linux_x86_64.whl&quot;}
+ torchvision = &quot;*&quot;

In this case, I received the following error
  AttributeError

  'EmptyConstraint' object has no attribute 'allows'.


Please tell me how to solve this error.

As far as I know, this does not yet supported in poetry (without ugly hacks), see Issue 2613.
That said, there is a fork I am maintaining called relaxed-poetry. It is a very young fork but it supports what you want with the following configuration:
[tool.poetry.dependencies]
python = &quot;^3.8&quot;
torch = { version = &quot;=1.8.0+cu111&quot;, source = &quot;pytorch&quot; }
torchvision = { version = &quot;=0.9.0+cu111&quot;, source = &quot;pytorch&quot; }

[[tool.poetry.source]]
name = &quot;pytorch&quot;
url = &quot;https://download.pytorch.org/whl/cu111/&quot;
secondary = true

If you think it can help you, you can install it side by side with poetry and use the command rp instead
Do note though that the installation is going to take some time as this is a large dependency and a relatively slow source..
