title: Reducing size of pyinstaller exe
body: <p>I have a simple pandas pyinstaller exe which is over 40MB.</p>
  
  <p>My exe example:</p>
  
  <pre><code>import collections
  import csv
  import selenium
  import pandas
  
  print('hi')
  </code></pre>
  
  <p>40MB+ for this seems a bit overkill.</p>
  
  <p>How can I reduce this as much as possible?</p>
  
  <p>One method:</p>
  
  <pre><code>pyinstaller --onefile --exclude matplotlib --exclude scipy --exclude pandas --exclude numpy.py
  </code></pre>
  
  <p>This however is not practical considering how big the exclusion list would be.</p>
  
  <p>How do I select a folder for pyinstaller to get modules from and exclude everything else so I may have a small application?</p>
  
  <p>Spec file:</p>
  
  <pre><code>a = Analysis(['123.py'],
               pathex=['C:\\Users\\AA\\ZZ'],
               binaries=[],
               datas=[],
               hiddenimports=[],
               hookspath=[],
               runtime_hooks=[],
               excludes=[],
               win_no_prefer_redirects=False,
               win_private_assemblies=False,
               cipher=block_cipher)
  pyz = PYZ(a.pure, a.zipped_data,
               cipher=block_cipher)
  exe = EXE(pyz,
            a.scripts,
            a.binaries,
            a.zipfiles,
            a.datas,
            name='123',
            debug=False,
            strip=False,
            upx=True,
            runtime_tmpdir=None,
            console=True )
  </code></pre>
  
  <p>It's also worth mentioning.  By default, Pyinstaller does not detect pandas. </p>
  
  <p>Add:</p>
  
  <pre><code>hiddenimports = ['pandas._libs.tslibs.timedeltas']
  
  To: C:\Users\&lt;NAME&gt;\AppData\Local\Programs\Python\Python36\Lib\site-packages\PyInstaller\hooks
  </code></pre>
  
  <p>A possible <a href="https://stackoverflow.com/questions/47610050/importing-python-modules-from-a-select-location">solution</a> when using multiple executables, could be to link each executable to a separate folder or executable with all imports. </p>