(Notice: The most up-to-date version of this post is always at the Pipenv project site, since I can't maintain the same edits in multiple places forever.)
This technique is the correct one and it's documented here:
https://pipenv.pypa.io/en/latest/advanced/#specifying-package-indexes
Basically, you add a new "source repository" to your Pipfile. And you should always use verify_ssl = true for extra security when possible.
Anyway, there's a shortcut to adding a custom repository without editing the pipfile. The --extra-index-url shortcut says "Add this PEP 503-standard repo URL":
- Version that uses CUDA Toolkit 11.3, with GPU acceleration (this toolkit is required by NVIDIA Ampere (RTX 30x0) GPUs and newer):
pipenv install --extra-index-url https://download.pytorch.org/whl/cu113/ "torch==1.10.1+cu113"
- Version that uses CUDA Toolkit 10.2, with GPU acceleration:
pipenv install --extra-index-url https://download.pytorch.org/whl/ "torch==1.10.1+cu102"
- Version that uses CPU instead:
pipenv install --extra-index-url https://download.pytorch.org/whl/ "torch==1.10.1+cpu"
Now you may notice something: There's no ".html" in my repo filenames.
That's because the repos with a HTML filename (such as https://download.pytorch.org/whl/torch_stable.html) are NON-STANDARD repos that ONLY pip understands.
You CANNOT use those URLs in Pipenv.
Pipenv uses PEP 503 standardized repos. Torch publishes those at the URLs WITHOUT ".html" filenames. So remove the filename to get the proper repo URLs for Pipenv usage.
This fact is documented here, when Torch's team decided to finally publish PEP 503 repos: https://github.com/pytorch/pytorch/issues/25639#issuecomment-861707149
You may notice something else: I always specify a version with +cpu or +cu113 or whatever.
This is NECESSARY, because otherwise Pipenv doesn't know which version to install and won't get GPU acceleration. The "architecture" (GPU vs CPU vs different CUDA toolkits) is baked into the version number. It's literally what Torch decided to do, and the ONLY correct way to download them is to specify the exact version and architecture (such as +cu113) you want.
If you want to figure out the URL to the correct repos/versions in the future, do as follows:
Go to pytorch.org and select "Stable, Pip, Python, CUDA 11.3" (or whatever is the latest CUDA you may be using), and then the command textbox will reveal the repo URL for the latest CUDA toolkit. You MUST then remove the HTML filename because that's the pip-specific repo.
Visit the resulting URL, such as https://download.pytorch.org/whl/cu113/, and navigate into the desired library folder. Then search for the version you wanted, and be sure to specify its FULL version specifier, such as 1.10.1+cu113.
Oh and sometimes, the Torch team forgets to upload the latest version to the PEP 503 repo, such as right now, where 1.10.2 is available but only in the non-standard pip-style repo. That's why you should always visit the PEP 503 repo to see the latest version they've uploaded into that repo. (I would love if they completely stop providing the old-school pip-repo at all, since pip supports PEP 503 too, so they should focus on the standards-compliant repo...)
See my examples above for perfect installation instructions for the current versions as of this writing.
One final note: ALWAYS RESPECT THE TORCH PYTHON VERSIONS.
The packages will have names such as "cp37", "cp38", "cp39". As of this writing, the highest version they have created is for Python 3.9. There's no Python 3.10 version of Torch.
Therefore, it helps to install Pyenv and specify an exact Python version in your Pipenv via pipenv install --python=3.9 to ensure that you have the latest version that Torch supports and not anything "too new/unsupported". :)