How do I use UPX with pyinstaller?

折月煮酒 提交于 2020-06-11 17:09:09

问题


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 )

回答1:


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

e.g.:

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




回答2:


Adding a new answer, since it appears that PyInstaller is more helpful now (in September 2019) than the current answer and comments suggest.

I see the output 934 INFO: UPX is available. early in the build if UPX is working.

Additionally, I can see many lines of output where PyInstaller is calling upx.

I didn't specify --upx-dir, but did have upx.exe available in my $PATH environment variable.




回答3:


In addition to GlennS' comment: exact this behaviour is stated in the pyinstaller documentation. so this is not an undocumented accidental benefit in this regard.
See https://pyinstaller.readthedocs.io/en/v3.3.1/usage.html#using-upx



来源:https://stackoverflow.com/questions/47730240/how-do-i-use-upx-with-pyinstaller

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!