How to include an .exe in a package and run it from a py script?

I have a python script that calls an external .exe program and captures the output using The script needs to run in an environment where all dependencies need to be covered in the script itself or in python packages. I’m able to build a package that includes the .exe using, but how do I reference the .exe in the python script?
include src/kubectl.exe

1 Like

Hi Gary, I think you can use importlib.resources (or its backport) to locate the file inside the package (e.g. via as_file).

Then you can use to run this file.

(In theory, should share the same environment variables with the spawned process, so if you activated a virtualenv with the dependencies installed, this should be visible right?)

1 Like

Also, if you’re specifying it in, make sure you set include_package_data = True if using Setuptools (or the equivalent for other build backends), so the .exe gets bundled into the wheel.

And of course, make sure you have and follow the appropriate license to distribute the external binary.


Gary, there is some documentation about that in Data Files Support - setuptools documentation. Please feel free to post in the setuptools GitHub discussions if you have problems with that.

1 Like

This is all very helpful, thank you!