How to include only needed modules in pyinstaller?

John Doe ·

1465 Views

For this you need to create a separate environment, because currently you are reading all the modules you have installed on your computer. To create environment run commands

1 - if you don't have one, create a requirements.txt file that holds all packages that you are using, you could create one with:

pip freeze > requirements.txt

2 - create env folder:

python -m venv projectName

3 - activate the environment:

source projectName/bin/activate

4 - install them:

pip install -r requirements.txt

alternatively if you know you are using only wxpython you could just pip install wxpython

5 - then finally you can run pyinstaller on your main script with the --path arg as explained in this answer:

pyinstaller --paths projectName/lib/python3.7/site-packages script.py

 

I'm using pyinstaller to generate an .exe file for my single python file, but the size is more than 30MB and the startup is very slow. From what I have gathered is that pyinstaller by default bundl...