【问题标题】:Fixing Python Dependencies The Right Way以正确的方式修复 Python 依赖项
【发布时间】:2021-03-09 22:01:24
【问题描述】:

我刚刚开始设置我的第一个 Python 环境。一切都很顺利,而且似乎启用了 GPU 和所有这些好东西。

但是,我有一个问题,不知道如何解决。在获得正确的火炬安装命令后,它通知了这个问题:

Installing collected packages: torch
ERROR: pip's dependency resolver does not currently take into account all the packages that are installed. This behaviour is the source of the following dependency conflicts.
torchvision 0.8.2 requires torch==1.7.1, but you have torch 1.8.0+cu111 which is incompatible.
Successfully installed torch-1.8.0+cu111

据我所知,torchvision 0.8.2 是最新版本。

目前环境似乎很愉快,因为所有这些命令都返回了预期的内容:

import torch
print(torch.__version__)
torch.cuda.get_device_name(0)

我见过一些人谈论“修补需​​求文件”或更新依赖项。但我不确定解决这个问题的最佳方法。

【问题讨论】:

    标签: python pytorch torchvision


    【解决方案1】:

    您可以在需求文件中锁定包的版本。该文件具有适当的值。

    requirements.txt:

    torch==1.7.1
    torchvision==0.8.2
    

    软件包通过pip 安装,如下所示:

    pip install -r requirements.txt
    

    您可能有此项目的其他依赖项。在这种情况下,您也可以使用pip 生成 requirements.txt 文件:

    pip freeze > requirements.txt
    

    查看documentation 关于使用pip 管理依赖项

    【讨论】:

    • 太棒了,我是如何错过那个链接的,这是一个谜。再次感谢。
    猜你喜欢
    • 2022-10-24
    • 1970-01-01
    • 2022-07-04
    • 2020-01-08
    • 2020-09-15
    • 1970-01-01
    • 1970-01-01
    • 2021-03-29
    • 1970-01-01
    相关资源
    最近更新 更多