How to exclude *.pyc and __pycache__ from python wheels? How to exclude *.pyc and __pycache__ from python wheels? python-3.x python-3.x

How to exclude *.pyc and __pycache__ from python wheels?


Why would you be doing that? The __pycache__ directory will be generated anyway when a project is run for the first time on the target machine.It's simply an optimised bytecode representation of Python.

But anyway, you can write an script that unpacks the .whl file and does the modifications and then repacks the wheel.


I have never had that problem.

Here's an excerpt from my setup.py:

   name='aenum',   version='2.0.2',   url='https://bitbucket.org/stoneleaf/aenum',   packages=['aenum'],   package_data={       'aenum' : [           'LICENSE',           'README',           'doc/aenum.rst',           'doc/aenum.pdf',           ]       },   include_package_data=True,   license='BSD License',   description="Advanced Enumerations (compatible with Python's stdlib Enum), NamedTuples, and NamedConstants",   long_description=long_desc,   provides=['aenum'],   author='Ethan Furman',   author_email='...',   classifiers=[        ...        ],

and my MANIFEST.in:

exclude aenum/*include setup.pyinclude READMEinclude aenum/__init__.pyinclude aenum/test.pyinclude aenum/test_v3.pyinclude aenum/LICENSEinclude aenum/CHANGESinclude aenum/READMEinclude aenum/doc/aenum.pdfinclude aenum/doc/aenum.rst

I would say the exclude aenum/* is what does the trick for me, so probably an exclude <package_name>/__pycache__ would work for you.


find_packages from setuptools does that, additionally you may specify direrctories to exclude, like:

packages=find_packages(exclude=['docs', 'tests']),

But compiled artifacts (pyc files and __pycache__ dir) should be excluded automatically.