1{ lib
2, stdenv
3, buildPythonPackage
4, fetchurl
5, isPy37
6, isPy38
7, isPy39
8, isPy310
9, patchelf
10, pillow
11, python
12, torch-bin
13}:
14
15let
16 pyVerNoDot = builtins.replaceStrings [ "." ] [ "" ] python.pythonVersion;
17 srcs = import ./binary-hashes.nix version;
18 unsupported = throw "Unsupported system";
19 version = "0.13.1";
20in buildPythonPackage {
21 inherit version;
22
23 pname = "torchvision";
24
25 format = "wheel";
26
27 src = fetchurl srcs."${stdenv.system}-${pyVerNoDot}" or unsupported;
28
29 disabled = !(isPy37 || isPy38 || isPy39 || isPy310);
30
31 nativeBuildInputs = [
32 patchelf
33 ];
34
35 propagatedBuildInputs = [
36 pillow
37 torch-bin
38 ];
39
40 # The wheel-binary is not stripped to avoid the error of `ImportError: libtorch_cuda_cpp.so: ELF load command address/offset not properly aligned.`.
41 dontStrip = true;
42
43 pythonImportsCheck = [ "torchvision" ];
44
45 postFixup = let
46 rpath = lib.makeLibraryPath [ stdenv.cc.cc.lib ];
47 in ''
48 # Note: after patchelf'ing, libcudart can still not be found. However, this should
49 # not be an issue, because PyTorch is loaded before torchvision and brings
50 # in the necessary symbols.
51 patchelf --set-rpath "${rpath}:${torch-bin}/${python.sitePackages}/torch/lib:" \
52 "$out/${python.sitePackages}/torchvision/_C.so"
53 '';
54
55 meta = with lib; {
56 description = "PyTorch vision library";
57 homepage = "https://pytorch.org/";
58 changelog = "https://github.com/pytorch/vision/releases/tag/v${version}";
59 # Includes CUDA and Intel MKL, but redistributions of the binary are not limited.
60 # https://docs.nvidia.com/cuda/eula/index.html
61 # https://www.intel.com/content/www/us/en/developer/articles/license/onemkl-license-faq.html
62 license = licenses.bsd3;
63 sourceProvenance = with sourceTypes; [ binaryNativeCode ];
64 platforms = platforms.linux;
65 maintainers = with maintainers; [ junjihashimoto ];
66 };
67}