George
George

Reputation: 4011

How to specify pytorch as a package requirement on windows?

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/lightwood, but I don’t think this is very relevant to my question).

What are the best practices for going about this ?

Are there some project I could use as examples ?

It seems like the pypi hosted version of torch & torchvision aren’t windows compatible and the “getting started” section suggests installing from the custom pytorch repository, but beyond that I’m not sure what the ideal solution would be to incorporate this as part of a setup script.

Upvotes: 4

Views: 3747

Answers (1)

sinoroc
sinoroc

Reputation: 22305

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:

Upvotes: 2

Related Questions