最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

python - Create a small one-file .exe that uses numpy - Stack Overflow

programmeradmin4浏览0评论

I am trying to create a small .exe file for a sponsor. The python code performs calculations that use the numpy library, specifically numpy arrays. When I compile the code with pyinstaller, the exe file is relatively large (250 MB). But when I try to get rid of numpy and perform similar calculations using only lists and basic operations, the file is only 20 MB.

I tried using tricks like upx but it didn't do much.

Is there a way to import essential modules from numpy without generating a huge file. I just need simple stuff such as array representation, np.diff(), and np.interp().

Thanks!

I am trying to create a small .exe file for a sponsor. The python code performs calculations that use the numpy library, specifically numpy arrays. When I compile the code with pyinstaller, the exe file is relatively large (250 MB). But when I try to get rid of numpy and perform similar calculations using only lists and basic operations, the file is only 20 MB.

I tried using tricks like upx but it didn't do much.

Is there a way to import essential modules from numpy without generating a huge file. I just need simple stuff such as array representation, np.diff(), and np.interp().

Thanks!

Share Improve this question asked Feb 15 at 21:22 Quentin PLOUSSARDQuentin PLOUSSARD 313 bronze badges 8
  • 1 stackoverflow/questions/66224879/… might look irrelevant but it is the actual solution to your problem. – Ahmed AEK Commented Feb 15 at 21:47
  • Thanks @AhmedAEK. I do have a hard time understanding how that thread relates to my issue. Are you implying that if I install nomkl in my environment before using pyinstaller, it will make the exe file smaller? – Quentin PLOUSSARD Commented Feb 15 at 22:57
  • 2 Numpy contains different parts and the most elementary part is Numpy-Core. It is the biggest part of Numpy once compiled (at least on my machine). The biggest part of Core is the super big file defining most array operation and the mini-SIMD library which is needed by most Core functions. You can make your own Numpy package but it should not be massively smaller (maybe 3 times smaller). There is something strange though. Numpy takes about 50 MiB on my Windows. You should inpect the generate binary so to see what files/directory are so big. – Jérôme Richard Commented Feb 16 at 0:20
  • If space is so critical for you that this is Ok to decrease performance, then you could compile Numpy with optimizations minimizing the size of the target binaries. Note that this can significantly slow down some functions (non-uniformly). By the way, I fot OpenBLAS which takes about 30 MiB on top of the 50 MiB of Numpy. It is needed for matrix multiplications, np.dot and linear algebra functions using it internally. – Jérôme Richard Commented Feb 16 at 0:26
  • Note that with a good compression (7zip), Numpy+OpenBLAS take only 13 MiB on my machine (<30 MiB even in Zip). What about compressing the installer alternatively if this is the problem? – Jérôme Richard Commented Feb 16 at 0:34
 |  Show 3 more comments

1 Answer 1

Reset to default 0

Alright, nomkl defintely improved things, even when importing the entire numpy, pandas, and matplotlib package in the code.

Here is the yml I used to set up the environment in conda:

name: my_env
channels:
  - defaults
dependencies:
  - pyinstaller
  - pip
  - pip: 
    - nomkl
    - numpy
    - matplotlib
    - ortools=9.11.4210
发布评论

评论列表(0)

  1. 暂无评论