question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

GUIDE: How to install PyTorch via Pipenv (and how to add other 3rd Party Repositories).

See original GitHub issue

Issue description

Try this Pipfile on 64-bit Linux. It fails to find the specified version:

[[source]]
url = "https://pypi.org/simple"
verify_ssl = true
name = "pypi"

[[source]]
url = "https://download.pytorch.org/whl/cu113/torch_stable.html"
verify_ssl = true
name = "pytorch-cu113"

[packages]
torch = {version = "==1.10.2+cu113", index = "pytorch-cu113"}

[dev-packages]

[requires]
python_version = "3.9"

Edit: The problem has been found. Torch’s repo (the URL I used) is a non-standardized repo that only pip understands. Pipenv only reads the PEP 503-standardized repos. See solution in my followup comments below.

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:2
  • Comments:37

github_iconTop GitHub Comments

23reactions
Bananamancommented, Feb 20, 2022

Solved: This is how to install Torch CORRECTLY in Pipenv. Most people do this incorrectly even in various “solutions” I’ve seen from other people… I’ve researched to the bottom of this problem and found out the real, intended solution that everyone should use.

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”. 😃

Good luck.

4reactions
dmexscommented, Nov 23, 2022

When I run try to run pipenv install --index https://download.pytorch.org/whl/ "torch==1.13.1+cpu"

I get the following error: ERROR: Could not find a version that satisfies the requirement torch==1.13.1+cpu (from versions: 1.4.0, 1.5.0, 1.5.1, 1.6.0, 1.7.0, 1.7.1, 1.8.0, 1.8.1, 1.9.0, 1.9.1, 1.10.0, 1.10.1, 1.10.2, 1.11.0, 1.12.0, 1.12.1, 1.13.0) ERROR: No matching distribution found for torch==1.13.1+cpu

With: Python 3.8.5 pipenv 2022.11.11 pip 22.3.1

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to install PyTorch with pipenv and save it to Pipfile and ...
Look at the other answers, which tell how to add pytorch as a repository in pipenv so that it can find the torch...
Read more >
How To Install Pytorch With Pipenv And Save It To ... - ADocLib
My tutorial will include a walkthrough of using Singularity to run a GPUaccelerated PyTorch program on an HPC cluster ... Let's install another...
Read more >
pipenv Documentation - Read the Docs
The recommended way to install pipenv on most platforms is to install from pypi using pip: $ pip install --user pipenv. Or, if...
Read more >
Advanced Usage of Pipenv - Python Packaging Authority
You may install a package such as the example torch from the named index pytorch using the CLI by running the following command:...
Read more >
Install External Libraries and Kernels in Notebook Instances
The different Jupyter kernels in Amazon SageMaker notebook instances are separate conda ... Using an alternative repository to install packages with pip ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found