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