How to specify pytorch as a package requirement on windows?

前端 未结 2 1499
时光说笑
时光说笑 2021-01-14 06:59

I have a python package which depends on pytorch and which I’d like windows users to be able to install via pip (the specific package is: https://github.com/mindsdb/lightwoo

相关标签:
2条回答
  • 2021-01-14 07:14

    For Windows, the installation can be done as follows:

    pip3 install torch===1.4.0 torchvision===0.5.0 -f https://download.pytorch.org/whl/torch_stable.html
    

    Here, you need to specify interested version. The -f is used to find links corresponding to the specific version on pytorch wheel page. You can use the direct link in requirements.txt file, which can be installed via pip as follows. For example, PyTorch 1.4, Python 3.7, Windows AMD64:

    # for torch
    https://download.pytorch.org/whl/cpu/torch-1.4.0%2Bcpu-cp37-cp37m-win_amd64.whl
    # for torchvision
    https://download.pytorch.org/whl/cpu/torchvision-0.5.0%2Bcpu-cp37-cp37m-win_amd64.whl
    

    The above links are for CPU, you can find the ones for CUDA as well.

    On the other hand, you can provide separate installation guide for Windows in your repository.

    0 讨论(0)
  • 2021-01-14 07:18

    What are the best practices for going about this ?

    If your project depends on other projects that are not distributed through PyPI then you have to inform the users of your project one way or another. I recommend the following combination:

    • clearly specify (in your project's documentation pages, or in the project's long description, or in the README, or anything like this) which dependencies are not available through PyPI (and possibly the reason why, with the appropriate links) as well as the possible locations to get them from;
    • to facilitate the user experience, publish alongside your project a pre-prepared requirements.txt file with the appropriate --find-links options.

    The reason why (or main reason, there are others), is that anyone using pip assumes that (by default) everything will be downloaded from PyPI and nowhere else. In other words anyone using pip puts some trust into pypi.org as a source for Python project distributions. If pip were suddenly to download artifacts from other sources, it would breach this trust. It should be the user's decision to download from other sources.

    So you could provide in your project's documentation an example of requirements.txt file like the following:

    # ...
    torch===1.4.0  --find-links https://download.pytorch.org/whl/torch_stable.html
    torchvision===0.5.0  --find-links https://download.pytorch.org/whl/torch_stable.html
    # ...
    

    Update

    The best solution would be to help the maintainers of the projects in question to publish Windows wheels on PyPI directly:

    • https://github.com/pytorch/pytorch/issues/24310
    • https://github.com/pytorch/vision/issues/1774
    • https://pypi.org/help/#file-size-limit
    0 讨论(0)
提交回复
热议问题