-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
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
GUIDE: How to install PyTorch via Pipenv (and how to add other 3rd Party Repositories). #4961
Comments
edit: Solved, see below. It's Torch's fault, not Pipenv's. |
Alright I've figured it out. Pipenv only supports standardized PEP 503 repositories. Torch, by default, gives us the URL for a non-standard "pip" bastard repo. I will post a followup comment with the full answer/solution for people. |
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 Anyway, there's a shortcut to adding a custom repository without editing the pipfile. The
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: pytorch/pytorch#25639 (comment) You may notice something else: I always specify a version with
|
I've gone on a posting spree in various incorrect topics (pretty much all of them were wrong), and linking people here so that random interwebs cybersurfers can find the correct way to install PyTorch and other PEP 503 repos in Pipenv! Hopefully this will stop the flow of misinformation and "wrong solutions" that's currently out there! 😄 Welcome, everyone! |
Thanks for this guide, but when I try to do: I get an The full error is:
|
Edit for anyone reading this thread in the future: You can skip the back and forth testing between me and Daniel. There is/was a bug in Pipenv that prevents installation of PEP 503 packages. There are multiple bug report tickets about it. The last known working version of Pipenv was 2022.1.8. The March 2022 versions are broken. I expect that Pipenv versions made after March 2022 will be fixed soon.@DanielPerezJensen Thanks for posting the full traceback. It shows that your error is just a bug inside The bug is on this line of code in pipenv, where their code tries to do a
PS: There are newer versions of Torch out now. Check my guide steps above for how you can update the commands to the latest version. You will need to follow my guide steps to set the correct, new version number in the command. |
Thanks for the quick response! In my case I need that previous version, and I figured since I could find the proper version in the link it should work. After updating pipenv I still get an error when I run the command:
The error trace is detailed below:
I get the same error when trying to use the latest version with the command What exactly am I doing wrong? |
@DanielPerezJensen You aren't doing anything wrong! :) Your Python runtime is a bad version or an unsupported version (such as the "M" version instead of standard Python). I did a test with your command for the latest Torch version, and I used the latest version of the official CPython 3.8 (since I see that you use Python 3.8).
Be sure that you have the latest 64-bit version of CPython, not some alternative interpreter or weird version of Python. Because that would mean that it can't find the package, since the Torch packages are only made for CPython 64-bit. Also be sure that you have the latest patch for your version of Python. In your case it means Python 3.8.13. Furthermore, Torch is only made for Linux + Windows. There are no Mac versions. You're going to have to change Python interpreter to one that Torch supports, that's for sure. |
You are of course under no obligation to help me, so thanks a ton already. I am a bit confused about your statement regarding my interpreter. What commands should I use to determine my CPython version, for example? I am using Ubuntu 20.04, with the default Python 3.8.10. I am not using some non-standard version of Python/CPython. The way I have installed PyTorch currently is by simply using pip in my pipenv. This has worked thus far, so I am pretty sure there are no installation problems from that end. Sorry for my vague, non-specific response, but I am simply not sure what else to specify. Perhaps I can give more detail about my system? |
@DanielPerezJensen No problem, but I don't have much more time today and have to go now. My suggestion is to bypass the system-wide Ubuntu version of Python since they may have messed with its source code. Ubuntu/Debian always messes with packages and does a ton of patching/backporting/modifications. You can install the official Python from source quite easily by installing You can then use commands such as You can also manually call
You should see some line such as "Using /home/mxuser/.pyenv/versions/3.8.13/bin/python3.8 (3.8.13) to create virtualenv...", then you know that pipenv has selected the pyenv version of Python. PS: The setuptools line is there to fix a bug in some Python versions. Certain versions of Python or setuptools need that extra environment flag to be compiled successfully (see https://bugs.python.org/issue46401 and pypa/setuptools#3031 if you are curious). I'll share my full I hope that this works out for you. At least, you'll finally have PythonPyenv (Python Version Management)
Pipenv (Python Project Environment Management)
|
Thanks for being so helpful, I will definetely look into this. Isolating my Python versions seems like a prudent thing to do, as I've had many problems with overlapping installs in the past (especially before using virtual environments) |
After going through your guide, and verifying that indeed I am now using the Python version from pyenv, I still get the same error. Here is a trace: daniel@daniel-desktop:~/Documents/test$ pipenv install
Creating a virtualenv for this project...
Pipfile: /home/daniel/Documents/test/Pipfile
Using /home/daniel/.pyenv/versions/3.8.12/bin/python3.8 (3.8.12) to create virtualenv...
⠹ Creating virtual environment...created virtual environment CPython3.8.12.final.0-64 in 120ms
creator CPython3Posix(dest=/home/daniel/.local/share/virtualenvs/test-Kb_OZVBf, clear=False, no_vcs_ignore=False, global=False)
seeder FromAppData(download=False, pip=bundle, setuptools=bundle, wheel=bundle, via=copy, app_data_dir=/home/daniel/.local/share/virtualenv)
added seed packages: pip==22.0.4, setuptools==61.0.0, wheel==0.37.1
activators BashActivator,CShellActivator,FishActivator,NushellActivator,PowerShellActivator,PythonActivator
✔ Successfully created virtual environment!
Virtualenv location: /home/daniel/.local/share/virtualenvs/test-Kb_OZVBf
Installing dependencies from Pipfile.lock (db4242)...
🐍 ▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉ 0/0 — 00:00:00
To activate this project's virtualenv, run pipenv shell.
Alternatively, run a command inside the virtualenv with pipenv run. (test) daniel@daniel-desktop:~/Documents/test$ 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 As you can see in the first trace I am using the proper version from pyenv, and in the second trace I get the same error. I followed all your instructions I believe. No idea what might be causing this.
My pipfile looks like this now, after running that command. It just fails to lock this I suppose. Not sure how to go about fixing that. |
@DanielPerezJensen Wow, that is ridiculous. Everything should work now. You have the exact same self-compiled version of 64-bit CPython 3.8.12 as I do. And we both used the exact same pipenv pytorch install command. It could be two remaining things:
|
Yeah, I wish I had a more thorough understanding of these things. But I
simply cannot come up with a reason for this, and I can't really find
anyone else with the same problem.
The error about cu113 not existing is also quite weird, since I can see the
package in the provided link.
…On Tue, 29 Mar 2022, 17:37 Bananaman, ***@***.***> wrote:
@DanielPerezJensen <https://github.com/DanielPerezJensen> Wow, that is
ridiculous. Everything should work now. You have the *exact* same
self-compiled version of 64-bit CPython 3.8.12 as I do. And we both used
the exact same pipenv pytorch install command.
It could be two remaining things:
1. A pipenv bug. I will update my pipenv, clear the pipenv package
cache, and try a new install with your exact commands.
2. A CDN problem. The error message you get says that there is no
"+cu113" version in the repo you added:
CRITICAL:pipenv.patched.notpip._internal.resolution.resolvelib.factory:Could
—
Reply to this email directly, view it on GitHub
<#4961 (comment)>, or
unsubscribe
<https://github.com/notifications/unsubscribe-auth/AHRZGW5OJAXXN7RRADIT3RTVCMPSRANCNFSM5OZM7KTA>
.
You are receiving this because you were mentioned.Message ID:
***@***.***>
|
If this works, you may want to do a quick test by creating a Fedora 35 virtual machine, install pyenv and pipenv in it (easy with my guide), and then see if the installation finds the package in there. I use Fedora, not Ubuntu/Debian. Maybe there is some issue at the Ubuntu/Debian system level, although I can't think of how that would work since we custom-compile Python and isolate the virtualenv packages. The only other potential issue, if Fedora fails too, is that PyTorch's CDN is hiding the packages from you. Anyway, we'll soon know if the command fails for me too now that I've updated pyenv and pipenv to the latest. |
I will replicate the exact steps you take, so we can compare. This should be as fresh as it's gonna get installation-wise. Hopefully we can create more clarity. Thanks for all the help so far! |
I just ran them all, the command did not take half an hour on my machine. I get the same error: 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 |
@DanielPerezJensen Good news (for you). It's a bug in the newest version of Pipenv.The question is which commit/update to Pipenv broke Pipenv.
|
Interesting, perhaps we can raise this as an issue on Pipenv's repo. If it's not intended behaviour. |
@DanielPerezJensen Yes a bug report ticket is necessary. Can you write it and link to this ticket? It's a very simple bug to describe: The latest version of Pipenv no longer finds PyTorch even though older versions of Pipenv did. |
Seems others also have this issue for other packages. |
Rolling back to version 2022.1.8 seems to allow me to install pytorch in this fashion. Although locking is taking a long time right now (more than 5 minutes atm), but I think that is normal? |
Yep all will be fine now! :)
It's normal as I mentioned here: #4961 (comment) They need to improve Pipenv someday to be more intelligent about what it downloads from PEP 503 repos. You can read more about why this is a hard problem for them to solve, in the linked ticket in that comment. :) It's a small design flaw in Pipenv which becomes really painful in this situation due to the huge size of PyTorch's packages. For most other packages they're so small that you don't notice anything. For me it takes ~30 minutes to install Torch on a 100mbit connection. After that, the packages are cached and install/reinstall instantly. |
Are there any plans to fix this bug in future versions of pipenv? |
Sorry @noamsgl, it is not clear which issue you are referring to. |
Thanks @matteius for the reply. Downgrading to pipenv v. 2022.1.8 fixed the issue. |
@noamsgl Probably you are asking about index restricted packages, and how to specify the package index going forward, is the short answer. There are several places it has been discussed already and the documentation was recently updated: https://pipenv.pypa.io/en/latest/advanced/#specifying-package-indexes See also these for starters: |
The latest version
As mentioned above in the comments, the |
@rlleshi What does your Pipfile look like? |
|
@rlleshi This is because your default index is pypi, so you need to specify the package index for Now my Pipfile looks like:
This is the Pipfile.lock:
latest |
aha, in the latest versions of pipenv the I used |
@rlleshi We removed support of the |
When I run try to run I get the following error: With: |
Is this functionality still broken? I could not manage to install pytorch using pipenv, with all attempts failing to find any pytorch package ("Could not find a version that satisfies the requirement" error with no available versions listed). I tried the solutions described in this thread to no avail. I managed to install pytorch and other dependencies using a manually created venv just fine. |
@marcospgp perhaps open a new issue, but what command are you running --I just ran @dmexs command and it worked fine:
✔ Successfully created virtual environment! |
Python 3.10.5 (then tried 3.7.0, same result) global scope (no venv) pip freeze:
|
@marcospgp Are you running from within a virtual machine or on bare metal hardware? Also not sure if it matters, but why are you invoking These are the available distros of "torch==1.13.1+cpu":
Which python version and which platform and CPU are you on? |
@matteius Running on windows 10 bare metal. I'm running pipenv through
mentioned above, and I'm not sure CPU matters since |
Can I search the CPU version by doing this? |
@thinker0 |
Something that tripped me up is that it seems torch and torchvision must be installed with the same bugfix version. For example,
Trying to use torchvision==0.14.0+cu117 will not work! (I know this is because torch and torchvision are very closely tied; I just didn't realize that extended to the bugfix version).
It fails with this error (which is not that helpful; it would be nice if it mentioned torch or torchvision):
|
Since searching for "pipenv install torch" refers to this guide, can we update the first solution? |
That did not work for me, but
|
Use the Pytorch whl download page, https://download.pytorch.org/whl/torch_stable.html, to determine the versions you want to install. Command
Output Installing torch==2.0.1+cu118...
Resolving torch==2.0.1+cu118...
Installation Succeeded
Installing torchvision==0.15.2+cu118...
Resolving torchvision==0.15.2+cu118...
Installation Succeeded
Installing torchaudio==2.0.2+cu118...
Resolving torchaudio==2.0.2+cu118...
Installation Succeeded
Pipfile.lock (343c5a) out of date, updating to (b56edd)...
Locking [packages] dependencies...
Building requirements...
Resolving dependencies...
Success!
...
Downloading file torch-2.0.1+cu118-cp311-cp311-win_amd64.whl to obtain hash...
Downloading file torchvision-0.15.2+cu118-cp311-cp311-win_amd64.whl to obtain
hash...
Downloading file torchaudio-2.0.2+cu118-cp311-cp311-win_amd64.whl to obtain
hash...
Locking [dev-packages] dependencies...
Updated Pipfile.lock (<hash>)!
Installing dependencies from Pipfile.lock (<hash>)...
To activate this project's virtualenv, run pipenv shell.
Alternatively, run a command inside the virtualenv with pipenv run. |
Although this threat has helped me a lot, I was set back an hour because I did not know that torch is not compatible with python >3.12. Be advised. I finally figured out the error using the compatibility matrix here: https://github.com/pytorch/pytorch/blob/main/RELEASE.md#release-compatibility-matrix Also, even with python 3.8, I was unable to get pipenv to install pytorch 1.7.0 , which was specified by my target codebase. I still have no idea why. Running on an intel mac with pyenv and pipenv. Cpu specific commands did not help. As a note to pipenv developers. |
Issue description
Try this Pipfile on 64-bit Linux. It fails to find the specified version:
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.
The text was updated successfully, but these errors were encountered: