如何将UPX与pyinstaller结合使用?

2024-09-26 17:56:26 发布

您现在位置:Python中文网/ 问答频道 /正文

如何将UPX与pyinstaller一起使用?

我在看医生。

我已经下载了UPX。

我的文件看起来像:

import csv
import selenium
import pandas

print('Hello')

然后我跑:

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

这不会影响文件的大小。

你知道我怎样才能让它工作吗?

# -*- 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 )

Tags: 文件importnonefalseblockexeuserscipher
3条回答

添加一个新的答案,因为现在(2019年9月)PyInstaller似乎比当前的答案和评论建议的更有帮助。

如果UPX正在工作,我会在构建的早期看到输出934 INFO: UPX is available.

另外,我可以看到PyInstaller调用upx的许多输出行。

我没有指定--upx-dir,但是在我的$PATH环境变量中有upx.exe可用。

除了GlennS的注释:确切的说,这种行为在pyinstaller文档中有说明。因此,在这方面,这并不是一个无证的意外收益。
https://pyinstaller.readthedocs.io/en/v3.3.1/usage.html#using-upx

需要指定UPX目录,而不是UPX可执行文件:

例如:

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

相关问题 更多 >

    热门问题