Skip to content
Advertisement

sdist/bdist_wheel not including pyc in Linux but is included in Windows

I am trying to create a Python distribution where I have to include both the source and the compiled binary. (Yes, I read arguments against/for adding .pyc, but my use case requires the .pyc to be added). Running my steps in Windows, both the source and compiled binaries are added in the output file (I used both sdist and bdist_wheel).

Say I have the following structure:

root
+--folderA
   +--alpha
   +--beta
   +--__init__.py
+--folderB

folderA contains source codes while folderB contains other files within its subdirectories.

Steps done:

  1. Modules are compiled using compileall
  2. Sources in alpha are removed. Sources in beta are kept.
  3. Run python setup.py sdist|bdist_wheel

I used find_packages() in setup.py to detect the modules. Modules in alpha are not detected while those in beta are found.

In the results .tgz and .whl files in Windows, all the needed files are there. All is good.

However, when the same procedure is done in Linux (Ubuntu to be specific), only the modules in beta are added and some modules in folderB but not other files of different type and the module alpha. sdist will give only the source while bdist and bdist_wheel will give the .pycs only. I understand that sdist is for distributing source files while bdist is for binary files.

My question is why is the behavior different in Windows and is it possible to produce the same output in Linux (source and .pyc along with other files)?

I am using Python 2.7.

Advertisement

Answer

To include files in sdist add them to MANIFEST.in:

global-include *.py *.pyc

Including *.pyc into wheels works for me on Linux without any special configuration, I just do

python setup.py build
python -m compileall build
python setup.py sdist
python setup.py bdist_wheel

PS. If you’re trying to hide sources from people — you’re on the wrong track. *.pyc files can be decompiled. There is a disassembler in standard library and there are many decompilers and uncompilers out there.

User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement