Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
495 views
in Technique[技术] by (71.8m points)

python - How to remove/exclude modules and files from pyInstaller?

I'm trying to shrink the size of my python exe file, I've been looking around but I can't seem to find a good answer for removing extra modules. At the moment, I'm discovering that it's deleting modules I need instead of the ones I'm telling it to. The documentation is rather unhelpful and neither are examples I've found so far.

My spec file:

a = Analysis(['D:\<path>\<scriptName>.py'],
         pathex=['c:\bin\pyinstaller-2.0'],
         hiddenimports=[],
         hookspath=None,
         )

pyz = PYZ(a.pure)
exe = EXE(pyz,
      a.zipfiles,
      a.scripts,
      a.binaries,
      a.datas + [('data/Sounds/Cycle.wav', 'D:\<path>\data\Sounds\Cycle.wav','DATA'),
       ('data/Sounds/Hold.wav', 'D:\<path>\data\Sounds\Hold.wav','DATA'),
       ('data/Sounds/Timer.wav', 'D:\<path>\data\Sounds\Timer.wav','DATA'),
       ('data/Sounds/Warn.wav', 'D:\<path>\data\Sounds\Warn.wav','DATA'),
       ],
      name=os.path.join('dist', 'timer.exe'),
      debug=False,
      strip=False,
      upx=False,
      icon=r"D:<path>Icon.ico",
      console=True )

Now, I want to start excluding things, but there doesn't seem to be a very explanation of how to exclude things.

These are things I had excluded when using py2exe:

'win32', 'unittest', _ssl, 'python25.dll', 'w9xpopen.exe', 'wx'
'python25.dll', 'API*', 'KERNALBASE.dll', 'DEVOBJ.dll','CRMGR32.dll',
'POWERPROF.dll', 'msvcm90.dll', 'msvcp90.dll', 'msvcr90.dll'

Though if I add any of these into the a.binaries as

a.binaries -[('wx')],

it deletes the PyQt4.dll files instead. Same holds true for the others. I do not follow that logic. I would think, at the very least, if it couldn't find them in the first place it would just skip over them instead of deleting other things.

py2exe makes me a 26mb files + three files (exe, library.zip, and w9xpopen.exe) pyInstaller makes me an 11mb file, and one file.

I feel I can make it smaller, but this excludes thing is confusing me. It straight up ignores the msv dll files and puts them in anyway.

Using Python 2.7, PyQt4 4.9.x

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

I would remove some like this:

a.binaries = a.binaries - TOC([
  ('sqlite3.dll', None, None),
  ('tcl85.dll', None, None),
  ('tk85.dll', None, None),
  ('_sqlite3', None, None),
  ('_ssl', None, None),
  ('_tkinter', None, None)
])

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...