Field Note

Packaging a Python application using Pyinstaller and virtual environments

python package application pyinstaller
Posted on Friday, April the 5th 2024
1 min read

Let’s say you have an application in a virtual environment like so

python -m venv /home/myapp/.venv
source /home/myapp/.venv/bin/activate
# ... install dependencies
deactivate

then you may point Pyinstaller to use the dependencies installed in the virtual environment .venv by adding it’s lib/site-packages/python<the-python-version>/site-packages to the dependencies included in the packaged executable via the --paths option even when you’re outside the virtual environment

pyinstaller --paths /home/myapp/.venv/lib/site-packages/python<the-python-version>/site-packages /home/myapp/main.py

Replace <the-python-version> with the Python version you are using in your virtual environment.

friedrichkurz.me

© 2025 Friedrich Kurz

Privacy Policy