Skip to content
Advertisement

How can I create the minimum size executable with pyinstaller?

I am on Windows 10, I have anaconda installed but I want to create an executable independently in a new, clean minimal environment using python 3.5. So I did some tests:

TEST1: I created a python script test1.py in the folder testenv with only:

print('Hello World')

Then I created the environment, installed pyinstaller and created the executable

D:testenv> python -m venv venv_test
...
D:testenvvenv_testScripts>activate.bat
...
(venv_test) D:testenv>pip install pyinstaller
(venv_test) D:testenv>pyinstaller --clean -F test1.py

And it creates my test1.exe of about 6 Mb

TEST 2: I modified test1.py as follows:

import pandas as pd
print('Hello World')  

I installed pandas in the environment and created the new executable:

(venv_test) D:testenv>pip install pandas
(venv_test) D:testenv>pyinstaller --clean -F test1.py

Ant it creates my test1.exe which is now of 230 Mb!!!

if I run the command

(venv_test) D:testenv>python -V
Python 3.5.2 :: Anaconda custom (64-bit)

when I am running pyinstaller I get some messages I do not understand, for example:

INFO: site: retargeting to fake-dir 'c:\users\username\appdata\local\continuum\anaconda3\lib\site-packages\PyInstaller\fake-modules'

Also I am getting messages about matplotlib and other modules that have nothing to do with my code, for example:

INFO:   Matplotlib backend "pdf": added
INFO:   Matplotlib backend "pgf": added
INFO:   Matplotlib backend "ps": added
INFO:   Matplotlib backend "svg": added

I know there are some related questions: Reducing size of pyinstaller exe, size of executable using pyinstaller and numpy but I could not solve the problem and I am afraid I am doing something wrong with respect to anaconda.

So my questions are: what am I doing wrong? can I reduce the size of my executable?

Advertisement

Answer

The problem is that you should not be using a virtual environment and especially not anaconda. Please download default python 32 bit and use only necessary modules. Then follow the steps provided in the links, this should definitely fix it.

Although you created a virtual env, are you sure your spec file is not linking to old Anaconda entries?

If all this fails, then submit a bug as this is very strange.

User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement