How do I use UPX with pyinstaller?

user9062171 picture user9062171 · Dec 9, 2017 · Viewed 22.3k times · Source

How do I use UPX with pyinstaller?

I am following the docs.

I have downloaded UPX.

My file looks like:

import csv
import selenium
import pandas

print('Hello')

I then run:

pyinstaller -F --upx-dir C:\Users\DD\Downloads\upx394w\upx394w\123\upx308w\upx.exe zz.spec

This does not affect the size of the file.

Any idea how I can get this to work?

# -*- mode: python -*-

block_cipher = None


a = Analysis(['zz.py'],
             pathex=['C:\\Users\\DA\\13\\14'],
             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='zz',
          debug=False,
          strip=False,
          upx=True,
          runtime_tmpdir=None,
          console=True )

Answer

denfromufa picture denfromufa · Dec 14, 2017

The UPX directory, not UPX executable needs to be specified:

e.g.:

pyinstaller myfile.py --upx-dir=..\upx391w -y --onefile