how to exclude source code from bdist_wheel python

Viewed 2727

We want to exclude the Python source code from the package we create. But after configuring setup.py, I failed excluding the py files. I have been using python setup.py bdist_wheel as command. Is there any way to exclude to source code from Python package? Basically we do not want to expose the source codes.

3 Answers

The wheel plugin for setuptools that handles bdist_wheel does not have the --exclude_source_files which is only supported by bdist_egg. The egg packages are however deprecated and not supported by pip for example. What you can do however:

pip3 install wheel
python3 setup.py bdist_egg --exclude-source-files
wheel convert dist/mypackage-1.0-py3.6.egg

The wheel utility takes a source-stripped egg and converts it into whl package.

This came up for us putting Python libs on an embedded system with very minimal available memory.

It can be achieved with:

./setup.py bdist_egg --exclude_source_files

Works for both distutils and setuptools.

Well, we also encountered this issue (around 2 years ago) and didn't find a sensible automation process for it. So I wrote my own.

You're welcomed to it: setup.py template

Related