Repository navigation
Description
- I have searched the issues of this repo and believe that this is not a duplicate.
Issue
As mentioned in issue #4231 there is some confusion around installing PyTorch with CUDA but it is now somewhat resolved. It still requires a few steps, and all options have pretty serious flaws. Below are two options that 'worked' for me, on Poetry version 1.2.0.
Option 1 - wheel URLs for a specific platform
- You will need to pick the specific wheels you want. These are listed here: https://download.pytorch.org/whl/torch_stable.html. E.g. if you want CUDA 11.6, Python 3.10 and Windows, search that page for
cu116-cp310-cp310-win_amd64.whlto see the matches fortorch,torchaudioandtorchvision - In your
pyproject.tomlfile add the URLs like:
[tool.poetry.dependencies]
python = "^3.10"
numpy = "^1.23.2"
torch = { url = "https://download.pytorch.org/whl/cu116/torch-1.12.1%2Bcu116-cp310-cp310-win_amd64.whl"}
torchaudio = { url = "https://download.pytorch.org/whl/cu116/torchaudio-0.12.1%2Bcu116-cp310-cp310-win_amd64.whl"}
torchvision = { url = "https://download.pytorch.org/whl/cu116/torchvision-0.13.1%2Bcu116-cp310-cp310-win_amd64.whl"}- Run
poetry update. It will download a lot of data (many GB) and take quite some time. And this doesn't seem to cache reliably (at least, I've waited 30 minutes+ at 56 Mbps three separate times while troubleshooting this, for the exact same wheels)
Note that each subsequent poetry update will do another huge download and you'll see this message:
• Updating torch (1.12.1+cu116 -> 1.12.1+cu116 https://download.pytorch.org/whl/cu116/torch-1.12.1%2Bcu116-cp310-cp310-win_amd64.whl)
• Updating torchaudio (0.12.1+cu116 -> 0.12.1+cu116 https://download.pytorch.org/whl/cu116/torchaudio-0.12.1%2Bcu116-cp310-cp310-win_amd64.whl)
• Updating torchvision (0.13.1+cu116 -> 0.13.1+cu116 https://download.pytorch.org/whl/cu116/torchvision-0.13.1%2Bcu116-cp310-cp310-win_amd64.whl)
Option 2 - alternate source
[tool.poetry.dependencies]
python = "^3.10"
numpy = "^1.23.2"
torch = { version = "1.12.1", source="torch"}
torchaudio = { version = "0.12.1", source="torch"}
torchvision = { version = "0.13.1", source="torch"}
[[tool.poetry.source]]
name = "torch"
url = "https://download.pytorch.org/whl/cu116"
secondary = trueThis seems to have worked (although I already had the packages installed) but it reports errors like Source (torch): Authorization error accessing https://download.pytorch.org/whl/cu116/pillow/, but I think they get installed anyway (maybe a better message would be "Can't access pillow at 'https://download.pytorch.org/whl/cu116', falling back to pypi")
Also, if you later go on to do, say poetry add pandas (a completely unrelated library) you'll get a wall of messages like:
Source (torch): Authorization error accessing https://download.pytorch.org/whl/cu116/pandas/
Source (torch): Authorization error accessing https://download.pytorch.org/whl/cu116/pandas/
Source (torch): Authorization error accessing https://download.pytorch.org/whl/cu116/pytz/
Source (torch): Authorization error accessing https://download.pytorch.org/whl/cu116/python-dateutil/
Source (torch): Authorization error accessing https://download.pytorch.org/whl/cu116/numpy/
Source (torch): Authorization error accessing https://download.pytorch.org/whl/cu116/pillow/
Source (torch): Authorization error accessing https://download.pytorch.org/whl/cu116/requests/
Source (torch): Authorization error accessing https://download.pytorch.org/whl/cu116/typing-extensions/
Source (torch): Authorization error accessing https://download.pytorch.org/whl/cu116/certifi/
Source (torch): Authorization error accessing https://download.pytorch.org/whl/cu116/urllib3/
Source (torch): Authorization error accessing https://download.pytorch.org/whl/cu116/idna/
Source (torch): Authorization error accessing https://download.pytorch.org/whl/cu116/charset-normalizer/
Source (torch): Authorization error accessing https://download.pytorch.org/whl/cu116/python-dateutil/
Source (torch): Authorization error accessing https://download.pytorch.org/whl/cu116/six/
Source (torch): Authorization error accessing https://download.pytorch.org/whl/cu116/pytz/
Source (torch): Authorization error accessing https://download.pytorch.org/whl/cu116/six/
This happens with or without secondary = true in the source config.
Maintainers: please feel free to edit the text of this if I've got something wrong.
Activity
dimbleby commentedon Sep 5, 2022
Failure to cache during resolution is covered by #2415, poetry's insistence on checking all sources for all packages is discussed at #5984
variolam commentedon Sep 6, 2022
Solution 1 seems infeasible when working in a team with machines on different operating systems, due to the need of providing the complete URL of the wheel including operating system and exact version number.
Solution 2 seems to work, but it results in downloading every single PyTorch version that can found, independent on the operating system. I'm running Windows and the download looks like this:
A single installation takes around 15-20 minutes at ~250 Mbps.
neersighted commentedon Sep 6, 2022
Poetry will always download wheels for every platform when you install -- this is because there is no other way to get package metadata from a repository using PEP 503's API.
Queuecumber commentedon Sep 6, 2022
Can you elaborate a little on what metadata is needed and why downloading every conceivable version of a package yields that metadata? As mentioned this leads to a ~20min install for one package
radoering commentedon Sep 6, 2022
It's not convenient, but it should be feasible with multiple constraints dependencies.
neersighted commentedon Sep 6, 2022
Poetry requires the package's core metadata aka the
METADATAfile (most critically this includes dependencies), as well as the bdist/sdist itself for hashing purposes. Note that PEP 658 is a standard for serving theMETADATAfile that is implementable by third-party repositories, and PEP 691 specifies a (potentially) richer JSON API (including hashes) that third-party repositories could likely implement.However, Poetry is unlikely to grow support for these new APIs until PyPI does, and I think third party repos are unlikely to implement it before PyPI. Eventually support for these APIs will allow for feature and performance parity in Poetry between PyPI and third-party repositories. Until then, we are stuck with the legacy HTML API, which requires us to download every package when generating a lock file for the first time.
After your cache is warm you will not need to download again, and on other platforms you will only download the necessary files as the metadata is captured in the lock file.
Queuecumber commentedon Sep 6, 2022
What I'm not understanding is that poetry knows I'm on Linux with python 3.8 but it still downloads
Or does that wheel not contain the core metadata that is needed?
Queuecumber commentedon Sep 6, 2022
Also there seems to be a second problem going on here unless I've misunderstood the documentation
I have this in my pyproject.toml
i.e.
secondary = trueYet poetry is asking that repository for every package I try to install. I thought from the documentation that secondary meant it would go to pypi for any package unless specifically asked to go to that custom repository.
neersighted commentedon Sep 6, 2022
Poetry constructs a universal lock file -- we write hashes to the lock file for all supported platforms. Thus on the first machine you generate a lock file, you will download a wheel for every supported platform. There is no way to write hashes to the lock file for those foreign/other platform versions without downloading them first.
If you want to reduce the scope of this a bit, you can tighten your Python constraint. There is a prototype of a new feature at #4956 (though it needs resurrection, design, and testing work) to add arbitrary markers to let a project reduce its supported platforms as an opt-in.
I think it might be you misreading -- that is the intended and documented behavior. There is a proposal to introduce new repository types at #5984 (comment) as the current
secondarybehavior covers multiple use cases poorly, while being ideal for none of them.Queuecumber commentedon Sep 6, 2022
OK this makes sense now, thanks for the explanation, looking forward to that PR hopefully being merged eventually
I was misreading I see that this is intended behavior
I agree with that and I hope that these new repository types can be implemented
ZetiMente commentedon Sep 24, 2022
Can't wait for option 2 to have good performance !
neersighted commentedon Sep 25, 2022
Please 👍 on issues instead of commenting me too -- it keeps the notifications down and still shows interest. Thanks!
Revert to requirements.txt from pyproject.toml
135 remaining items
brian316 commentedon Aug 2, 2024
this seems to work for me
poetry 1.8.3
havardox commentedon Aug 18, 2024
Anyone got a working pyproject.toml for ROCm?
extraymond commentedon Aug 23, 2024
After some trial and error I think I know why it sometimes works and sometimes won't when using on rocm.
poetry works, but pytorch didn't have prebuild wheels for every combination of torch/rocm/python.
You can manually check that here: https://download.pytorch.org/whl/torch
For example, only torch 2.4 are build for rocm6.1, the old one are kept in rocm6.0 and rocm5.6.
Let's say you want
torch=^2.0andtorchvisioninstalled, which translates to finding torch on the 2.0 series and whatever torchvision that works with torch. I think the resolver will do the following:+cpu+rocm6.1^2.0and found one build for cudaSo when using rocm, I think manually check the version available in the source and directly specify it will works better.
Here's my declaration:
be sure to check the python version marker too! if one aren't build for rocm you will face the same issue.
fede-bello commentedon Sep 25, 2024
I'm having the same issue here. When running just
poetry installI'm not having any issue, but when specifyingcpuorgputo install pytorch I'm getting:r-Larch commentedon Sep 26, 2024
When trying @tfha approach I get
MemoryErrorso I was needed to use--no-cache.Produces:
Solution:
Found here #7250 (comment)
Adding
--no-cachesolves the issue.clarkh-ncino commentedon Oct 3, 2024
If you have an intel chip mac, any version past 2.2.2 is unsupported without leveraging conda pytorch/pytorch#114602
rbudnar commentedon Oct 9, 2024
The solutions described above here and here mostly work, but I noticed that if I re-run the install command (with or without with the sync flag) again after an install, poetry will flip the install to the other version regardless of which flags I've passed. For example, I cloned the repo provided by @lucaspar and simply ran the suggested command over and over:
And poetry 1.8.3 would toggle between the CPU and GPU versions indefinitely:

leolcao commentedon Dec 24, 2024
for my side, I find poetry can not use some mirror url, like the aliyun mirror, I don't know it is poetry's issue or not.
my pyproject.toml
If i use the source
aliyun-torch, poetry install will throw the error message:But, I can use the url way to set the aliyun source, like the commented parts from above pyproject.toml.
does anyone know why? the poetry version is 1.8.4.
Node-serialportainsley commentedon Feb 7, 2025
Observe this https://pythoner.space/questions/error-generated-due-to-unsupported-locale-setting-in-a-dockerfile-built-with-python crucial insight
psibre commentedon Feb 7, 2025
Problems (and solutions!) for setting the locale inside Docker containers are easy to find on the web, e.g., https://stackoverflow.com/a/28406007.
That has nothing at all to do with this issue, or even Python in general.
0x26res commentedon Feb 19, 2025
Has anyone managed to get this to work using the PEP 621 way of specifying dependencies, and what would the syntax be?
amadou-6e commentedon Mar 26, 2025
In the age of machine learning, not being able to install something as basic as torch, would make poetry obsolete when compare with conda where this is a one liner
MaKaNu commentedon Mar 26, 2025
@amadou-6e I would not compare poetry with conda. The issue here is more on metas way of distributing the software. The same issue appears on other package managers, which provide dependency resolving similar to poetry.
Just because one library is weird how they distribute does not make this tool obsolete.
bverhoeve commentedon Jun 3, 2025
I've been struggling with this for a while as well now. We use the CPU version of torch as our use case is quite limited. My current
pyproject.tomlfile looks as follows:When generating a
poetry.lockfile, everything works fine. When installing usingpoetry installon macos I consistently run into the following error:So even though
pyproject.tomlindicates that the CPU version is NOT to be used ondarwin(it isn't even present in the torch repo), Poetry somehow insists on installing the cpu extras. Any ideas?EDIT: just using
torch = 2.6.0does work although that does install the CUDA dependencies as well even when not used on Intel siliconRishabh-Choudhry commentedon Jul 16, 2025
Found this repo quite useful: https://github.com/lucaspar/poetry-torch