Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ERROR: No matching distribution found for torch==1.11.0+cu113 when using --extra-index-url #5022

Closed
DanielPerezJensen opened this issue Mar 29, 2022 · 25 comments · Fixed by #5029
Assignees
Labels
Priority: Medium This item is medium priority and will be resolved whenever possible. reported bug triage Type: Possible Bug This issue describes a possible bug in pipenv.

Comments

@DanielPerezJensen
Copy link

It seems that this error is also a problem when installing from other sources, such as in #5021.

Issue description

After lots of debugging and trial and error, we have run into a bug with pipenv relating to installing libraries while using another index url (--extra-index-url).

When trying to install PyTorch using the following command pipenv install --extra-index-url https://download.pytorch.org/whl/cu113/ "torch==1.11.0+cu113" Installing torch==1.11.0+cu113, as specified under this issue: #4961, we get the following error: ERROR: No matching distribution found for torch==1.11.0+cu113.

According to @Bananaman this was possible to do in a previous version of pipenv.

Expected result

Expected an installation using a 3rd party index url, in this case PyTorch.

Actual result

daniel@daniel-desktop:~/Documents$ pipenv install --extra-index-url https://download.pytorch.org/whl/cu113/ "torch==1.11.0+cu113"
Installing torch==1.11.0+cu113...
Adding torch to Pipfile's [packages]...
✔ Installation Succeeded 
Pipfile.lock (db4242) out of date, updating to (7d86a3)...
Locking [dev-packages] dependencies...
Locking [packages] dependencies...
Building requirements...
Resolving dependencies...
✘ Locking Failed! 

CRITICAL:pipenv.patched.notpip._internal.resolution.resolvelib.factory:Could not find a version that satisfies the requirement torch==1.11.0+cu113 (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)
[ResolutionFailure]:   File "/home/daniel/.local/lib/python3.8/site-packages/pipenv/resolver.py", line 743, in _main
[ResolutionFailure]:       resolve_packages(pre, clear, verbose, system, write, requirements_dir, packages, dev)
[ResolutionFailure]:   File "/home/daniel/.local/lib/python3.8/site-packages/pipenv/resolver.py", line 704, in resolve_packages
[ResolutionFailure]:       results, resolver = resolve(
[ResolutionFailure]:   File "/home/daniel/.local/lib/python3.8/site-packages/pipenv/resolver.py", line 685, in resolve
[ResolutionFailure]:       return resolve_deps(
[ResolutionFailure]:   File "/home/daniel/.local/lib/python3.8/site-packages/pipenv/utils.py", line 1398, in resolve_deps
[ResolutionFailure]:       results, hashes, markers_lookup, resolver, skipped = actually_resolve_deps(
[ResolutionFailure]:   File "/home/daniel/.local/lib/python3.8/site-packages/pipenv/utils.py", line 1127, in actually_resolve_deps
[ResolutionFailure]:       resolver.resolve()
[ResolutionFailure]:   File "/home/daniel/.local/lib/python3.8/site-packages/pipenv/utils.py", line 905, in resolve
[ResolutionFailure]:       raise ResolutionFailure(message=str(e))
[pipenv.exceptions.ResolutionFailure]: Warning: Your dependencies could not be resolved. You likely have a mismatch in your sub-dependencies.
  You can use $ pipenv install --skip-lock to bypass this mechanism, then run $ pipenv graph to inspect the situation.
  Hint: try $ pipenv lock --pre if it is a pre-release dependency.
ERROR: No matching distribution found for torch==1.11.0+cu113

Steps to replicate

Be sure to use the latest version of pipenv, if I use a previous version (latest confirmed is 2022.1.8) the error goes away.

  1. Create clean environment
  2. pipenv install --extra-index-url https://download.pytorch.org/whl/cu113/ "torch==1.11.0+cu113"
  3. Error should appear on latest version of pipenv

$ pipenv --support

Pipenv version: '2022.3.28'

Pipenv location: '/home/daniel/.local/lib/python3.8/site-packages/pipenv'

Python location: '/usr/bin/python3'

Python installations found:

  • 3.8.12: /home/daniel/.pyenv/versions/3.8.12/bin/python
  • 3.8.10: /usr/bin/python3
  • 3.8.10: /usr/bin/python3.8
  • 3.8.10: /bin/python3
  • 3.8.10: /bin/python3.8

PEP 508 Information:

{'implementation_name': 'cpython',
 'implementation_version': '3.8.10',
 'os_name': 'posix',
 'platform_machine': 'x86_64',
 'platform_python_implementation': 'CPython',
 'platform_release': '5.13.0-37-generic',
 'platform_system': 'Linux',
 'platform_version': '#42~20.04.1-Ubuntu SMP Tue Mar 15 15:44:28 UTC 2022',
 'python_full_version': '3.8.10',
 'python_version': '3.8',
 'sys_platform': 'linux'}

System environment variables:

  • SHELL
  • SESSION_MANAGER
  • QT_ACCESSIBILITY
  • COLORTERM
  • PYENV_SHELL
  • XDG_CONFIG_DIRS
  • XDG_MENU_PREFIX
  • GNOME_DESKTOP_SESSION_ID
  • MANDATORY_PATH
  • LC_ADDRESS
  • GNOME_SHELL_SESSION_MODE
  • LC_NAME
  • SSH_AUTH_SOCK
  • XMODIFIERS
  • DESKTOP_SESSION
  • LC_MONETARY
  • SSH_AGENT_PID
  • GTK_MODULES
  • PWD
  • LOGNAME
  • XDG_SESSION_DESKTOP
  • XDG_SESSION_TYPE
  • GPG_AGENT_INFO
  • XAUTHORITY
  • GJS_DEBUG_TOPICS
  • WINDOWPATH
  • HOME
  • USERNAME
  • IM_CONFIG_PHASE
  • LC_PAPER
  • LANG
  • LS_COLORS
  • XDG_CURRENT_DESKTOP
  • VTE_VERSION
  • GNOME_TERMINAL_SCREEN
  • INVOCATION_ID
  • MANAGERPID
  • GJS_DEBUG_OUTPUT
  • LESSCLOSE
  • XDG_SESSION_CLASS
  • SETUPTOOLS_USE_DISTUTILS
  • TERM
  • LC_IDENTIFICATION
  • DEFAULTS_PATH
  • LESSOPEN
  • USER
  • GNOME_TERMINAL_SERVICE
  • DISPLAY
  • SHLVL
  • LC_TELEPHONE
  • QT_IM_MODULE
  • LC_MEASUREMENT
  • LD_LIBRARY_PATH
  • XDG_RUNTIME_DIR
  • PYENV_ROOT
  • LC_TIME
  • JOURNAL_STREAM
  • XDG_DATA_DIRS
  • PATH
  • GDMSESSION
  • DBUS_SESSION_BUS_ADDRESS
  • LC_NUMERIC
  • OLDPWD
  • _
  • PIP_SHIMS_BASE_MODULE
  • PIP_DISABLE_PIP_VERSION_CHECK
  • PYTHONDONTWRITEBYTECODE
  • PIP_PYTHON_PATH
  • PYTHONFINDER_IGNORE_UNSUPPORTED

Pipenv–specific environment variables:

Debug–specific environment variables:

  • PATH: /home/daniel/.pyenv/shims:/home/daniel/.pyenv/bin:/usr/local/cuda-11.3/bin:/home/daniel/.local/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin
  • SHELL: /bin/bash
  • LANG: en_US.UTF-8
  • PWD: /home/daniel/Documents

@Arcitec
Copy link

Arcitec commented Mar 29, 2022

Excellent, thanks for creating the ticket. I have managed to verify that 2022.1.8 version of Pipenv works:

pip install --user pipenv==2022.1.8

I have not checked all of the March 2022 releases but I know for a fact that Pipenv 2022.3.28 is broken.

So the bug was introduced somewhere in the March releases.

@matteius
Copy link
Member

Please seem my comment here, I suspect this is an edge case of the fix for package index restrictions. If you name the index and specify you want it from the named index it should work on newer versions. Can you verify that point?
#5021 (comment)

What do you expect the Pipfile to look like when you are using the --extra-index-url argument (try on the older 2022.1.8 release)?

@matteius
Copy link
Member

matteius commented Mar 29, 2022

I was looking in the pipenv docs for where it talks about --extra-index-url and not finding it. The index examples are generally named, or pypi mirrors. Ref: https://pipenv.pypa.io/en/latest/advanced/#specifying-package-indexes

I do see in the code base we have that option, and the help text is:
URLs to the extra PyPI compatible indexes to query for package look-ups.

Likely a regression that we never had a test case for, but more thought will need to go into it, especially considering the security concerns of package indexes.

I have a hunch that for your use case you really should be restricting the package index by name, otherwise pip will still go look in pypi and potentially pick something from there if the version is newer. If you truly want to ensure you are using the specific index that hosts your torch distribution, I would pin to that.

@DanielPerezJensen
Copy link
Author

@matteius

Under the older release my Pipfile looks like this:

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

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

[packages]
torch = "==1.11.0+cu113"
numpy = "*"

[dev-packages]

[requires]
python_version = "3.8"

How do I name the index?

@matteius
Copy link
Member

@DanielPerezJensen It would be like this:

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

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

[packages]
torch = {index="downloadpytorch", version="==1.11.0+cu113"}
numpy = "*"

[dev-packages]

[requires]
python_version = "3.8"

@DanielPerezJensen
Copy link
Author

@matteius Would I have to specify that in the Pipfile then by hand or is there a way to get it written like that through terminal commands?

@Arcitec
Copy link

Arcitec commented Mar 29, 2022

@DanielPerezJensen It seems very likely that the breaking change was the "stricter index searching" which @matteius mentioned.

Indeed, the non-CUDA versions of Torch are listed as candidates in the error message, which suggests that Pipenv is searching on PyPi for Torch and is ignoring the Torch index.

The Pipfile now needs a "index=XYZ" line to explicitly say "get torch from the downloadpytorch index/source".

It's a bug/regression in Pipenv which makes it ignore the contents of the specified extra sources even though we want them.

And @matteius: The --extra-index-url is just for adding another source. It doesn't seem to create a package pin/lock to that repo. Which is fine in Torch's cases since the versions we want only exist on the Torch repo/index.

@Arcitec
Copy link

Arcitec commented Mar 29, 2022

@matteius I can confirm that manually editing the Pipfile to force Pipenv to get the package from PyTorch's repo works as a temporary solution.

Any ideas if the general bug can be fixed so that Pipenv scans the additional repos again without having to be forcibly told to use them per-package?

Related ticket: #4983

A fix may be something like:

  • If "index" is specified on a Pipfile's package line, use that index.
  • If no index is specified, prefer the non-PyPi sources (because the user added extra sources for a reason!), then lastly PyPi as fallback.

@matteius
Copy link
Member

The --extra-index-url is just for adding another source. It doesn't seem to create a package pin/lock to that repo. Which is fine in Torch's cases since the versions we want only exist on the Torch repo/index.

Understood, but I know from triaging your other reports that it does in fact check pypi when you are using the extra index url, and that seems dangerous and takes additional time to do the locking and install than just being explicit about where you know that you want the package from.

Any ideas if the general bug can be fixed so that Pipenv scans the additional repos again without having to be forcibly told to use them per-package?

I will be studying the code more to consider your use case, will have to consider what might be possible before getting back to you on the solution wrt to that.

If no index is specified, prefer the non-PyPi sources, then lastly PyPi as fallback.

This part will likely not be possible because this is a pip behavior and we try to use pip in a way that does not modify its internals wherever possible and that would be quite the modification to do -- in fact pip prefers PyPi and says its recommended that if you want to avoid pypi but need pypi packages that your mirror should contain all pypi packages that you need (or mirror pypi). We might be able to get back the old behavior if no index is specified though.

@Arcitec
Copy link

Arcitec commented Mar 29, 2022

Understood, but I know from triaging your other reports that it does in fact check pypi when you are using the extra index url, and that seems dangerous and takes additional time to do the locking and install than just being explicit about where you know that you want the package from.

Is there any way to modify --extra-index-url so that it means "add this index (if missing) AND force the packages (on the same command line) to use this index" then? Otherwise --extra-index-url is totally useless now since packages aren't being read from it.

May wanna remove --extra-index-url and add --use-index-url or --set-index-url though, to be explicit about that flag's new behavior.

This part will likely not be possible because this is a pip behavior and we try to use pip in a way that does not modify its internals wherever possible and that would be quite the modification to do -- in fact pip prefers PyPi and says its recommended that if you want to avoid pypi but need pypi packages that your mirror should contain all pypi packages that you need (or mirror pypi). We might be able to get back the old behavior if no index is specified though.

I see. So you're internally calling the pip program and telling it to install from the pip/index?

I guess all of this is fixed/good enough if --extra-index-url is modified to pin all packages on the same command line to use that index.

It's all a bit weird now though. It used to be possible to do something like pipenv install --extra-index-url url1 --extra-index-url url2 somepacgefrompypi somepackagefromurl1 somepackagefromurl1 somepackagefromurl2 to do it all at once, since Pipenv was able to look for the package name and version in all extra repos in addition to checking PyPi.

That behavior was the best. If someone has a reason to manually pin a package to an exact index in the Pipfile then so be it. But for general easy usage, "pick the matching package and version from any repo that has it" was great.

@matteius
Copy link
Member

Is there any way to modify --extra-index-url so that it means "add this index (if missing) AND force the packages (on the same command line) to use this index" then? Otherwise --extra-index-url is totally useless now since packages aren't being read from it.

pipenv install "torch==1.11.0+cu113" --index https://download.pytorch.org/whl/cu113/ -v
This yields pip command:
python -m pip install --verbose --upgrade --exists-action=i -r 'c:\users\matte\appdata\local\temp\pipenv-v6p5_r5y-requi rements\pipenv-gwi7sw6w-requirement.txt' -i https://download.pytorch.org/whl/cu113/ --extra-index-url https://pypi.org/simple --extra-index-url https://pypi.org/simple

It's still running because its a huge package with multiple matching wheels, so debugging this will take some time.

May wanna remove --extra-index-url and add --use-index-url or --set-index-url though, to be explicit about that flag's new behavior.

Going to give it more thought, ideally we get the prior behavior working again for you folks that don't use index restrictions, but that is going to require some thinking time.

I see. So you're internally calling the pip program and telling it to install from the pip/index?

Yes, and more complicated than that is we vendor (copy in a specific version of pip) to the pipenv code base, and we call internal APIs of pip to do magical things that even pip itself doesn't do. For more insights into that, I have a recent thread in pip that goes into some detail around some of the complexities: pypa/pip#10964 (comment)

It's all a bit weird now though. It used to be possible to do something like pipenv install --extra-index-url url1 --extra-index-url url2 somepacgefrompypi somepackagefromurl1 somepackagefromurl1 somepackagefromurl2 to do it all at once, since Pipenv was able to look for the package name and version in all extra repos in addition to checking PyPi.

Yeah, I think that is why it will be necessary to contemplate getting that prior behavior working again without breaking index restrictions. I have to note, when calling out that many extra index urls, its still going to prefer pypi and its going to cause more churn on the resolver/locking to find your packages.

That behavior was the best.

Debatable :-) It is also great for package confusion attackers because how do you know for sure where you are pulling your package from in that scenario?

"pick the matching package and version from any repo that has it"

So imagine someone can poison the DNS for one of the package servers and put up a private pypi with a version that is malicious -- now your resolver goes and gets that because it matches version="==1.11.0+cu113" even though its not at all the version you wanted.

I'm glad to have having this discussion and thankful you opened the reports, so it will get investigated. For now you have two workaround, the prior version or being more explicit in your package needs which will I think benefit you more in the long run. For example, @Bananaman did you ever consider my other comment about calling out the wheel you specifically want to avoid downloading all 8 and having them in the lockfile? It really depends on if you need the lockfile to have all 8 hashes for the different system architectures or if you are just trying to support the one for your system. Ref: #4963 (comment)

@DanielPerezJensen
Copy link
Author

The installing of specific wheels also serves well for repo's that might not conform to PEP503. For example, PyTorch Geometric

@matteius
Copy link
Member

@matteius Would I have to specify that in the Pipfile then by hand or is there a way to get it written like that through terminal commands?

@DanielPerezJensen Yes it seems that this works: pipenv install "torch==1.11.0+cu113" --index https://download.pytorch.org/whl/

Generated this Pipfile:

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

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

[[source]]
url = "https://download.pytorch.org/whl/"
verify_ssl = true
name = "downloadpytorch-390"

[packages]
torch = {version = "==1.11.0+cu113", index = "downloadpytorch-390"}

[dev-packages]

[requires]
python_version = "3.10"

Initial reaction here is I am kind of surprised it has 3 sources, but it seemed to have worked. Generated this Pipfile.lock ... actually this doesn't look right either because it doesn't have the package hashes in the lockfile.

{
    "_meta": {
        "hash": {
            "sha256": "dd84b90e2afa892488dc59130dc48898573afeee5ba3aa45d8c64c54be6be39c"
        },
        "pipfile-spec": 6,
        "requires": {
            "python_version": "3.10"
        },
        "sources": [
            {
                "name": "pypi",
                "url": "https://pypi.org/simple",
                "verify_ssl": true
            },
            {
                "name": "downloadpytorch",
                "url": "https://download.pytorch.org/whl/cu113/",
                "verify_ssl": true
            },
            {
                "name": "downloadpytorch-390",
                "url": "https://download.pytorch.org/whl/",
                "verify_ssl": true
            }
        ]
    },
    "default": {
        "torch": {
            "index": "downloadpytorch-390",
            "version": "==1.11.0+cu113"
        },
        "typing-extensions": {
            "hashes": [
                "sha256:1a9462dcc3347a79b1f1c0271fbe79e844580bb598bafa1ed208b94da3cdcd42",
                "sha256:21c85e0fe4b9a155d0799430b0ad741cdce7e359660ccbd8b530613e8df88ce2"
            ],
            "markers": "python_version >= '3.6'",
            "version": "==4.1.1"
        }
    },
    "develop": {}
}

Side-note: I was having some buggy experiences earlier using git shell in windows to the locking, and I can only figure the size of the wheel files were freezing up the shell. I just had a much much better experience using Windows Powershell, it was very fast actually. I wonder if the reason its so fast is because its not pulling the hash values anymore.

@DanielPerezJensen
Copy link
Author

@matteius

I think you might have 3 sources because you put in a different command the second time around, namely your index is different.

https://download.pytorch.org/whl/ and https://download.pytorch.org/whl/cu113

@DanielPerezJensen
Copy link
Author

When I run that first command I get a relatively clean Pipfile and Pipfile.lock. But the problem of 8 hashes persists.

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

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

[packages]
torch = {version = "==1.11.0+cu113", index = "downloadpytorch"}

[dev-packages]

[requires]
python_version = "3.8"
{
    "_meta": {
        "hash": {
            "sha256": "5e59083c7931419685a04fc9eb3772702bb73d79b2d1a8d29ddd018d1e847729"
        },
        "pipfile-spec": 6,
        "requires": {
            "python_version": "3.8"
        },
        "sources": [
            {
                "name": "pypi",
                "url": "https://pypi.org/simple",
                "verify_ssl": true
            },
            {
                "name": "downloadpytorch",
                "url": "https://download.pytorch.org/whl/cu113",
                "verify_ssl": true
            }
        ]
    },
    "default": {
        "torch": {
            "hashes": [
                "sha256:7fd4751bbf39bbb04ec6116c7243ce6528aded4197afcf380537340e1eebd19a",
                "sha256:a68c33657a546131eb9bc44e2a98d2fa704aafae861460b051b82813852ccb44",
                "sha256:b6a799bdb6ee3d914e5e62bddb4276d4a10248c1af4f2d217738e5f9ee27485b",
                "sha256:ddc57495195aa2456e78bfc7d8d3f45dabbb8b7b268b3b5dbed4f0e4db492f33",
                "sha256:e4bb14d953db9aad5bdb945a328410638721d77e3e622d0a8d77063c01daf40b",
                "sha256:e9126b0a5d95704bee40a9d0ef1cbd82d8dc7863e4638a376bef702dfd659370",
                "sha256:e9df65c1fb2d80283b276114878fd38f411b70880e0b406c451d000e6159f451",
                "sha256:f56333470daea3c97078b37607e0035cccf72fc5c36fd84546e1a4b8d9944f2b"
            ],
            "index": "downloadpytorch",
            "version": "==1.11.0+cu113"
        },
        "typing-extensions": {
            "hashes": [
                "sha256:1a9462dcc3347a79b1f1c0271fbe79e844580bb598bafa1ed208b94da3cdcd42",
                "sha256:21c85e0fe4b9a155d0799430b0ad741cdce7e359660ccbd8b530613e8df88ce2"
            ],
            "markers": "python_version >= '3.6'",
            "version": "==4.1.1"
        }
    },
    "develop": {}
}

But, for now, it does seem to solve the issue of being unable to install PyTorch using pipenv. Although downloading 16GBs is of course unnecessary.

@matteius
Copy link
Member

@DanielPerezJensen Can you confirm what version of pipenv you are on? I think the newer version of pipenv have a bug where its only pulling the one hash instead of 8 -- that is what I got on the newer versions (or at least my branch where I try to fix the hash at all for these).

But if you are getting 8, that is technically working by design that there would be 8 hashes for that package, the reason why is you are calling out "==1.11.0+cu113" which there are 8 matching wheels for. Pipenv has logic to ignore_compatibility_finder when seeking out the hashes and generate all hashes for the matching package, this is because while you may be installing it on python 3.8, those wheels also support python 3.7, 3.9, and 3.10, for both windows and linux architectures, that makes 8,

[torch-1.11.0+cu113-cp310-cp310-linux_x86_64.whl](https://download.pytorch.org/whl/cu113/torch-1.11.0%2Bcu113-cp310-cp310-linux_x86_64.whl)
[torch-1.11.0+cu113-cp310-cp310-win_amd64.whl](https://download.pytorch.org/whl/cu113/torch-1.11.0%2Bcu113-cp310-cp310-win_amd64.whl)
[torch-1.11.0+cu113-cp37-cp37m-linux_x86_64.whl](https://download.pytorch.org/whl/cu113/torch-1.11.0%2Bcu113-cp37-cp37m-linux_x86_64.whl)
[torch-1.11.0+cu113-cp37-cp37m-win_amd64.whl](https://download.pytorch.org/whl/cu113/torch-1.11.0%2Bcu113-cp37-cp37m-win_amd64.whl)
[torch-1.11.0+cu113-cp38-cp38-linux_x86_64.whl](https://download.pytorch.org/whl/cu113/torch-1.11.0%2Bcu113-cp38-cp38-linux_x86_64.whl)
[torch-1.11.0+cu113-cp38-cp38-win_amd64.whl](https://download.pytorch.org/whl/cu113/torch-1.11.0%2Bcu113-cp38-cp38-win_amd64.whl)
[torch-1.11.0+cu113-cp39-cp39-linux_x86_64.whl](https://download.pytorch.org/whl/cu113/torch-1.11.0%2Bcu113-cp39-cp39-linux_x86_64.whl)
[torch-1.11.0+cu113-cp39-cp39-win_amd64.whl](https://download.pytorch.org/whl/cu113/torch-1.11.0%2Bcu113-cp39-cp39-win_amd64.whl)

The understanding is that when you are generating a Pipfile.lock its generally to be shared across systems. Now there is this ticket, which is more of a feature request, #4963
That would make it so having a pinned python version would only consider the wheels for that version instead of all versions, if we could get to that point it would be two wheels instead of 8 that have to get fetched in this example.

Since you may just be using pipenv for yourself and only truly need the one wheel in your lockfile, you can do something like this to install the single wheel file.
pipenv install --index https://download.pytorch.org/whl/cu113/ https://download.pytorch.org/whl/cu113/torch-1.11.0%2Bcu113-cp310-cp310-win_amd64.whl which will yield a Pipfile.lock such as:

{
    "_meta": {
        "hash": {
            "sha256": "24abb649a5ce32770fb8155cf6f434bda0dc0f79811c581e70836851b3ce2ad8"
        },
        "pipfile-spec": 6,
        "requires": {
            "python_version": "3.10"
        },
        "sources": [
            {
                "name": "pypi2",
                "url": "https://pypi.org/simple",
                "verify_ssl": true
            },
            {
                "name": "downloadpytorch",
                "url": "https://download.pytorch.org/whl/cu113/",
                "verify_ssl": true
            }
        ]
    },
    "default": {
        "torch": {
            "file": "https://download.pytorch.org/whl/cu113/torch-1.11.0%2Bcu113-cp310-cp310-win_amd64.whl",
            "hashes": [
                "sha256:ddc57495195aa2456e78bfc7d8d3f45dabbb8b7b268b3b5dbed4f0e4db492f33"
            ],
            "index": "downloadpytorch",
            "version": "==1.11.0+cu113"
        },
        "typing-extensions": {
            "hashes": [
                "sha256:1a9462dcc3347a79b1f1c0271fbe79e844580bb598bafa1ed208b94da3cdcd42",
                "sha256:21c85e0fe4b9a155d0799430b0ad741cdce7e359660ccbd8b530613e8df88ce2"
            ],
            "markers": "python_version >= '3.6'",
            "version": "==4.1.1"
        }
    },
    "develop": {}
}

@DanielPerezJensen
Copy link
Author

@matteius I am currently on version pipenv==2022.1.8

@matteius
Copy link
Member

@DanielPerezJensen Would you be able to test with pipenv==2022.3.28 -- I suspect that the hashes are not being set for some of the index restricted packages (or maybe all of them) and have a PR out working on that edge case. I have a commit that passed the CI and added the singular hash value, but I was trying to debug it further to get back to including all relevant wheel's hashes and that broke a handful of tests. If I could get confirmation that you are seeing the same issue with the new version, that will help me address #5023 because you may be able to help test my PR once I get it to where I want it.

@matteius matteius added Type: Possible Bug This issue describes a possible bug in pipenv. reported bug Priority: Medium This item is medium priority and will be resolved whenever possible. triage labels Mar 30, 2022
@DanielPerezJensen
Copy link
Author

DanielPerezJensen commented Mar 31, 2022

@matteius

Running pipenv install "torch==1.11.0+cu113" --index https://download.pytorch.org/whl/cu113/ -v yields the following pip command: /home/daniel/.local/share/virtualenvs/test-Kb_OZVBf/bin/python -m pip install --verbose --upgrade --exists-action=i -r /tmp/pipenv-zz18ayop-requirements/pipenv-edwy4lp9-requirement.txt -i https://download.pytorch.org/whl/cu113/ --extra-index-url https://pypi.org/simple --extra-index-url https://pypi.org/simple. This is with Python 3.8.12, and pipenv 2022.3.28.

The verbose output is this:

(test) daniel@daniel-desktop:~/Documents/test$ pipenv install "torch==1.11.0+cu113" --index https://download.pytorch.org/whl/cu113/ -v
Installing torch==1.11.0+cu113...
Installing package: torch==1.11.0+cu113
Writing supplied requirement line to temporary file: 'torch==1.11.0+cu113'
Installing 'torch'
⠸ Installing torch...$ /home/daniel/.local/share/virtualenvs/test-Kb_OZVBf/bin/python -m pip install --verbose --upgrade --exists-action=i -r /tmp/pipenv-zz18ayop-requirements/pipenv-edwy4lp9-requirement.txt -i https://download.pytorch.org/whl/cu113/ --extra-index-url https://pypi.org/simple --extra-index-url https://pypi.org/simple
Using source directory: '/home/daniel/.local/share/virtualenvs/test-Kb_OZVBf/src'
Adding torch to Pipfile's [packages]...
✔ Installation Succeeded 
Pipfile.lock not found, creating...
Locking [dev-packages] dependencies...
Locking [packages] dependencies...
Building requirements...
Resolving dependencies...
Reporter.starting()
INFO:pipenv.patched.notpip._internal.resolution.resolvelib.reporter:Reporter.starting()
Reporter.adding_requirement(SpecifierRequirement('torch==1.11.0+cu113'), None)
INFO:pipenv.patched.notpip._internal.resolution.resolvelib.reporter:Reporter.adding_requirement(SpecifierRequirement('torch==1.11.0+cu113'), None)
Reporter.starting_round(0)
INFO:pipenv.patched.notpip._internal.resolution.resolvelib.reporter:Reporter.starting_round(0)
Reporter.adding_requirement(SpecifierRequirement('typing-extensions'), LinkCandidate('https://download.pytorch.org/whl/cu113/torch-1.11.0%2Bcu113-cp38-cp38-linux_x86_64.whl (from https://download.pytorch.org/whl/cu113/torch/)'))
INFO:pipenv.patched.notpip._internal.resolution.resolvelib.reporter:Reporter.adding_requirement(SpecifierRequirement('typing-extensions'), LinkCandidate('https://download.pytorch.org/whl/cu113/torch-1.11.0%2Bcu113-cp38-cp38-linux_x86_64.whl (from https://download.pytorch.org/whl/cu113/torch/)'))
Reporter.pinning(LinkCandidate('https://download.pytorch.org/whl/cu113/torch-1.11.0%2Bcu113-cp38-cp38-linux_x86_64.whl (from https://download.pytorch.org/whl/cu113/torch/)'))
INFO:pipenv.patched.notpip._internal.resolution.resolvelib.reporter:Reporter.pinning(LinkCandidate('https://download.pytorch.org/whl/cu113/torch-1.11.0%2Bcu113-cp38-cp38-linux_x86_64.whl (from https://download.pytorch.org/whl/cu113/torch/)'))
Reporter.ending_round(0, state)
INFO:pipenv.patched.notpip._internal.resolution.resolvelib.reporter:Reporter.ending_round(0, state)
Reporter.starting_round(1)
INFO:pipenv.patched.notpip._internal.resolution.resolvelib.reporter:Reporter.starting_round(1)
Reporter.pinning(LinkCandidate('https://files.pythonhosted.org/packages/45/6b/44f7f8f1e110027cf88956b59f2fad776cca7e1704396d043f89effd3a0e/typing_extensions-4.1.1-py3-none-any.whl#sha256=21c85e0fe4b9a155d0799430b0ad741cdce7e359660ccbd8b530613e8df88ce2 (from https://pypi.org/simple/typing-extensions/) (requires-python:>=3.6)'))
INFO:pipenv.patched.notpip._internal.resolution.resolvelib.reporter:Reporter.pinning(LinkCandidate('https://files.pythonhosted.org/packages/45/6b/44f7f8f1e110027cf88956b59f2fad776cca7e1704396d043f89effd3a0e/typing_extensions-4.1.1-py3-none-any.whl#sha256=21c85e0fe4b9a155d0799430b0ad741cdce7e359660ccbd8b530613e8df88ce2 (from https://pypi.org/simple/typing-extensions/) (requires-python:>=3.6)'))
Reporter.ending_round(1, state)
INFO:pipenv.patched.notpip._internal.resolution.resolvelib.reporter:Reporter.ending_round(1, state)
Reporter.starting_round(2)
INFO:pipenv.patched.notpip._internal.resolution.resolvelib.reporter:Reporter.starting_round(2)
Reporter.ending(State(mapping=OrderedDict([('torch', LinkCandidate('https://download.pytorch.org/whl/cu113/torch-1.11.0%2Bcu113-cp38-cp38-linux_x86_64.whl (from https://download.pytorch.org/whl/cu113/torch/)')), ('typing-extensions', LinkCandidate('https://files.pythonhosted.org/packages/45/6b/44f7f8f1e110027cf88956b59f2fad776cca7e1704396d043f89effd3a0e/typing_extensions-4.1.1-py3-none-any.whl#sha256=21c85e0fe4b9a155d0799430b0ad741cdce7e359660ccbd8b530613e8df88ce2 (from https://pypi.org/simple/typing-extensions/) (requires-python:>=3.6)'))]), criteria={'torch': Criterion((SpecifierRequirement('torch==1.11.0+cu113'), via=None)), 'typing-extensions': Criterion((SpecifierRequirement('typing-extensions'), via=LinkCandidate('https://download.pytorch.org/whl/cu113/torch-1.11.0%2Bcu113-cp38-cp38-linux_x86_64.whl (from https://download.pytorch.org/whl/cu113/torch/)')))}))
INFO:pipenv.patched.notpip._internal.resolution.resolvelib.reporter:Reporter.ending(State(mapping=OrderedDict([('torch', LinkCandidate('https://download.pytorch.org/whl/cu113/torch-1.11.0%2Bcu113-cp38-cp38-linux_x86_64.whl (from https://download.pytorch.org/whl/cu113/torch/)')), ('typing-extensions', LinkCandidate('https://files.pythonhosted.org/packages/45/6b/44f7f8f1e110027cf88956b59f2fad776cca7e1704396d043f89effd3a0e/typing_extensions-4.1.1-py3-none-any.whl#sha256=21c85e0fe4b9a155d0799430b0ad741cdce7e359660ccbd8b530613e8df88ce2 (from https://pypi.org/simple/typing-extensions/) (requires-python:>=3.6)'))]), criteria={'torch': Criterion((SpecifierRequirement('torch==1.11.0+cu113'), via=None)), 'typing-extensions': Criterion((SpecifierRequirement('typing-extensions'), via=LinkCandidate('https://download.pytorch.org/whl/cu113/torch-1.11.0%2Bcu113-cp38-cp38-linux_x86_64.whl (from https://download.pytorch.org/whl/cu113/torch/)')))}))
Warning: Error generating hash for torch
⠋ Locking...
✔ Success! 
Updated Pipfile.lock (20805a)!
Installing dependencies from Pipfile.lock (20805a)...
  🐍   ▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉ 0/0 — 00:00:00

With the following Pipfile:

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

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

[packages]
torch = {version = "==1.11.0+cu113", index = "downloadpytorch"}

[dev-packages]

[requires]
python_version = "3.8"

Importing torch python -c "import torch" yields:

(test) daniel@daniel-desktop:~/Documents/test$ python -c "import torch"
/home/daniel/.local/share/virtualenvs/test-Kb_OZVBf/lib/python3.8/site-packages/torch/_masked/__init__.py:223: UserWarning: Failed to initialize NumPy: numpy.core.multiarray failed to import (Triggered internally at  ../torch/csrc/utils/tensor_numpy.cpp:68.)
  example_input = torch.tensor([[-3, -2, -1], [0, 1, 2]])

The numpy dependency not being installed is a "problem" that I have seen many times when installing PyTorch through their index. Installing numpy solves the issue and torch can be imported.

Furthermore running some test code to verify that the gpu is being used shows that indeed the GPU is getting used.

@matteius
Copy link
Member

@DanielPerezJensen Thanks for checking that, and I assume that if you look in the Pipfile.lock that you generated with 2022.3.28 I am guessing that there is no hashes markers for the torch are missing? Something like this:

    "default": {
        "torch": {
            "index": "downloadpytorch-390",
            "version": "==1.11.0+cu113"
        },
        "typing-extensions": {
            "hashes": [
                "sha256:1a9462dcc3347a79b1f1c0271fbe79e844580bb598bafa1ed208b94da3cdcd42",
                "sha256:21c85e0fe4b9a155d0799430b0ad741cdce7e359660ccbd8b530613e8df88ce2"
            ],
            "markers": "python_version >= '3.6'",
            "version": "==4.1.1"
        }
    },
    "develop": {}
}

@DanielPerezJensen
Copy link
Author

My Pipfile lock looks like this (with numpy installed as well):

{
    "_meta": {
        "hash": {
            "sha256": "f71a2ebd5be7510ec7d0d1c717387b9e2432060b0ca046de7d4605f4ddd42b7b"
        },
        "pipfile-spec": 6,
        "requires": {
            "python_version": "3.8"
        },
        "sources": [
            {
                "name": "pypi",
                "url": "https://pypi.org/simple",
                "verify_ssl": true
            },
            {
                "name": "downloadpytorch",
                "url": "https://download.pytorch.org/whl/cu113/",
                "verify_ssl": true
            }
        ]
    },
    "default": {
        "numpy": {
            "hashes": [
                "sha256:07a8c89a04997625236c5ecb7afe35a02af3896c8aa01890a849913a2309c676",
                "sha256:08d9b008d0156c70dc392bb3ab3abb6e7a711383c3247b410b39962263576cd4",
                "sha256:201b4d0552831f7250a08d3b38de0d989d6f6e4658b709a02a73c524ccc6ffce",
                "sha256:2c10a93606e0b4b95c9b04b77dc349b398fdfbda382d2a39ba5a822f669a0123",
                "sha256:3ca688e1b9b95d80250bca34b11a05e389b1420d00e87a0d12dc45f131f704a1",
                "sha256:48a3aecd3b997bf452a2dedb11f4e79bc5bfd21a1d4cc760e703c31d57c84b3e",
                "sha256:568dfd16224abddafb1cbcce2ff14f522abe037268514dd7e42c6776a1c3f8e5",
                "sha256:5bfb1bb598e8229c2d5d48db1860bcf4311337864ea3efdbe1171fb0c5da515d",
                "sha256:639b54cdf6aa4f82fe37ebf70401bbb74b8508fddcf4797f9fe59615b8c5813a",
                "sha256:8251ed96f38b47b4295b1ae51631de7ffa8260b5b087808ef09a39a9d66c97ab",
                "sha256:92bfa69cfbdf7dfc3040978ad09a48091143cffb778ec3b03fa170c494118d75",
                "sha256:97098b95aa4e418529099c26558eeb8486e66bd1e53a6b606d684d0c3616b168",
                "sha256:a3bae1a2ed00e90b3ba5f7bd0a7c7999b55d609e0c54ceb2b076a25e345fa9f4",
                "sha256:c34ea7e9d13a70bf2ab64a2532fe149a9aced424cd05a2c4ba662fd989e3e45f",
                "sha256:dbc7601a3b7472d559dc7b933b18b4b66f9aa7452c120e87dfb33d02008c8a18",
                "sha256:e7927a589df200c5e23c57970bafbd0cd322459aa7b1ff73b7c2e84d6e3eae62",
                "sha256:f8c1f39caad2c896bc0018f699882b345b2a63708008be29b1f355ebf6f933fe",
                "sha256:f950f8845b480cffe522913d35567e29dd381b0dc7e4ce6a4a9f9156417d2430",
                "sha256:fade0d4f4d292b6f39951b6836d7a3c7ef5b2347f3c420cd9820a1d90d794802",
                "sha256:fdf3c08bce27132395d3c3ba1503cac12e17282358cb4bddc25cc46b0aca07aa"
            ],
            "index": "pypi",
            "version": "==1.22.3"
        },
        "torch": {
            "index": "downloadpytorch",
            "version": "==1.11.0+cu113"
        },
        "typing-extensions": {
            "hashes": [
                "sha256:1a9462dcc3347a79b1f1c0271fbe79e844580bb598bafa1ed208b94da3cdcd42",
                "sha256:21c85e0fe4b9a155d0799430b0ad741cdce7e359660ccbd8b530613e8df88ce2"
            ],
            "markers": "python_version >= '3.6'",
            "version": "==4.1.1"
        }
    },
    "develop": {}
}

@matteius
Copy link
Member

Thanks for confirming this @DanielPerezJensen -- I have a commit that ensure that the 1-hash that gets installed for "torch" or other index restricted packages gets included, but I've had more difficulties getting it to include all 8 hashes again. I think the ideal, would be it includes the two hashes that match your required python_version or all of them (all 8) if a version is not specified. I will be looking to find more time to look into this, at a minimum will ship new version in April that includes at least the matching hash, but ideally will figure out how to include all the relevant hashes as well for private index restricted packages.

@matteius
Copy link
Member

Also, I just checked the wheel archive torch-1.11.0+cu113-cp310-cp310-win_amd64.whl and I don't see where it would ever figure out that it need numpy implicitly -- probably something you always have to manually install or add to the Pipfile as well I am guessing with that particular archive.

@matteius
Copy link
Member

matteius commented Apr 1, 2022

@DanielPerezJensen I have a branch that appears to correct include all 8 hashes again for this example, and thus should fix the hash collection for all index restricted packages in pipenv. If you care to try it out, the branch is here and you can install it using python setup.py develop --user #5024

@goranobradovic
Copy link

I could not get python to work properly without having the latest installed, so I worked around this by manually changing install scripts, wherever there was python replace with python3.7, and also ran python3.7 -m ensurepip --upgrade, then creating venv with python3.7 -m venv .

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Priority: Medium This item is medium priority and will be resolved whenever possible. reported bug triage Type: Possible Bug This issue describes a possible bug in pipenv.
Projects
None yet
4 participants