title: OSError: Can't get source for <function swish_jit at 0x000001BA57F0C288>. TorchScript requires source access
body: <p>I am trying to create an executable. My code <strong>test.py</strong> works well when running with python, but the generated executable file fails with <strong>OsError</strong> error. I tried to add some hiddenimports and data to the spec file, but I am still getting the same error.</p>
  <p><a href="https://i.stack.imgur.com/UqsMx.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/UqsMx.png" alt="enter image description here" /></a></p>
  <p>You can find my <strong>test.py</strong> and <strong>test.spec</strong> files here.</p>
  <p><strong>test.py</strong></p>
  <pre><code>from lungmask import mask
  import SimpleITK as sitk
  import nibabel as nib
  import glob
  import shutil
  from ttictoc import tic,toc
  import os
  import torch.multiprocessing as mp
  import sys
  import cv2
  import numpy as np
  import albumentations as albu
  import torch
  import segmentation_models_pytorch as smp
  import efficientnet_pytorch
  
  
  if __name__ == '__main__':
      print('hello world')
  </code></pre>
  <hr />
  <p><strong>test.spec</strong></p>
  <pre><code># -*- mode: python ; coding: utf-8 -*-
  from pathlib import Path
  import torch
  import inspect
  import efficientnet_pytorch
  from os import path
  
  block_cipher = None
  
  #Excluded_modules = ['Torch.Distributions'] # Add this line
  site_packages='C:\\Users\\pc\\Anaconda3\\envs\\pytorch-3.7\\Lib\\site-packages'
  
  def collect_source_files(modules):
      datas = []
      for module in modules:
          source = inspect.getsourcefile(module)
          dest = f&quot;src.{module.__name__}&quot;  # use &quot;src.&quot; prefix
          datas.append((source, dest))
      return datas
  
  a = Analysis(['test.py'],
               pathex=['E:\\COVID-19\\New folder'],
               binaries=[('C:\\Users\\pc\\Anaconda3\\envs\\pytorch-3.7\\Lib\\site-packages\\torch\\lib\\caffe2_nvrtc.dll','.')],
               datas=[(path.join(site_packages,&quot;torch&quot;), &quot;torch&quot;),
                      (path.join(site_packages,&quot;torchvision&quot;), &quot;torchvision&quot;),
                      (path.join(site_packages,&quot;efficientnet_pytorch&quot;), &quot;efficientnet_pytorch&quot;)],
               hiddenimports=['pydicom', 'pydicom.encoders', 'pydicom.encoders.gdcm', 'pydicom.encoders.pylibjpeg', 'fill_voids', 'fastremap', 'nibabel', 'nibabel.nifti1','torch','av', 'fvcore','torchvision', 'detectron2','efficientnet_pytorch','segmentation_models_pytorch'],
               hookspath=[],
               hooksconfig={},
               runtime_hooks=[],
               excludes= [],  #Excluded_modules
               win_no_prefer_redirects=False,
               win_private_assemblies=False,
               cipher=block_cipher,
               noarchive=False)
               
               
               
  MISSING_LIBS = (
  Path(r'C:\Windows\System32\nvcuda.dll'),
  )
  
  a.binaries += TOC([(lib.name, str(lib.resolve()),'BINARY') for lib in MISSING_LIBS])
  
  MISSING_LIBS = (
  Path(r'C:\Users\pc\Anaconda3\envs\pytorch-3.7\Library\bin\nvrtc64_101_0.dll'),
  )
  
  a.binaries += TOC([(lib.name, str(lib.resolve()),'BINARY') for lib in MISSING_LIBS])
  
  source_files = collect_source_files([torch])  # return same structure as `collect_data_files()`
  source_files_toc = TOC((name, path, 'DATA') for path, name in source_files)
  
  pyz = PYZ(a.pure, a.zipped_data, source_files_toc,
               cipher=block_cipher)
  
  exe = EXE(pyz,
            a.scripts, 
            [],
            exclude_binaries=True,
            name='test',
            debug=False,
            bootloader_ignore_signals=False,
            strip=False,
            upx=True,
            console=True,
            disable_windowed_traceback=False,
            target_arch=None,
            codesign_identity=None,
            entitlements_file=None )
  coll = COLLECT(exe,
                 a.binaries,
                 a.zipfiles,
                 a.datas, 
                 strip=False,
                 upx=True,
                 upx_exclude=[],
                 name='test')
  </code></pre>