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 = "^3.8" torch = { url = "https://download.pytorch.org/whl/cu111/torch-1.8.0%2Bcu111-cp38-cp38-linux_x86_64.whl"} torchvision = { url = "https://download.pytorch.org/whl/cu111/torchvision-0.9.0%2Bcu111-cp38-cp38-linux_x86_64.whl" }
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 = "^3.8" torch = { url = "https://download.pytorch.org/whl/cu111/torch-1.8.0%2Bcu111-cp38-cp38-linux_x86_64.whl"} - torchvision = { url = "https://download.pytorch.org/whl/cu111/torchvision-0.9.0%2Bcu111-cp38-cp38-linux_x86_64.whl"} + torchvision = "*"
In this case, I received the following error
AttributeError 'EmptyConstraint' object has no attribute 'allows'.
Please tell me how to solve this error.
Advertisement
Answer
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 = "^3.8" torch = { version = "=1.8.0+cu111", source = "pytorch" } torchvision = { version = "=0.9.0+cu111", source = "pytorch" } [[tool.poetry.source]] name = "pytorch" url = "https://download.pytorch.org/whl/cu111/" 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..