2017-07-11 137 views
0

我编译了一个.py文件的exe文件,但问题是它是200mb + 我想删除无用的软件包(例如我没有使用的scipy)。PyInstaller:不能排除模块

我还没有清楚PyInstaller的正确语法。

让我们从头开始......平时我做CMD:

cd myFolder 
C:\Python27\Scripts\Pyinstaller.exe MyFile.py 

,这让我在dist文件夹中的exe文件。

如果我想设置一些正确的配置方式吗?

C:\Python27\Scripts\Pyinstaller.exe MyFile.py Config.py 

C:\Python27\Scripts\Pyinstaller.exe Config.py 

,因为在网上我发现他们两个,但我无法分辨。

如果它是最后一个我试图运行:

lock_cipher = None 
a = Analysis(['Main.py'], 
    pathex=['C:\Users\myname\Desktop\myFolder'], 
    binaries=None, 
    datas=None, 
    hiddenimports=[], 
    hookspath=None, 
    runtime_hooks=None, 
    excludes=None, 
    cipher=block_cipher) 
a.binaries = [x for x in a.binaries if not x[0].startswith("scipy")] 
pyz = PYZ(a.pure, a.zipped_data, 
    cipher=block_cipher) 
exe = EXE(pyz) 
coll = COLLECT(exe) 

但它不工作。我错在哪里?

回答

3

我的建议是,你使用的虚拟env只包含所需的模块。这是一个更好的开发实践。

此外,您还可以使用--exclude-module标志列出所有你要排除的模块。 (Pyinstaller automatically includes unneeded modules

+0

感谢你有什么关注点1和命令--exclude模块将被包含在cmd中有很好的指导?没有办法用我发布的代码修复它。非常感谢 – Thegamer23

+0

你可以在这里看到答案:https://pythonhosted.org/PyInstaller/usage.html – brotherperes