Search code examples
python-3.xdeploymentpippypipython-wheel

Souce code getting packaged in python wheel


We are using the wheels to deploy our code to QA/Production. Recently we found/realized that wheel packages are actually storing our source code. And by simple command as below will open all the source code inside it.

unzip package.whl

command used for wheel creation is as below

cd /path/to/source/code/folder
python setup.py bdist bdist_wheel

So,

  1. Is there any way to create wheels which creates binary and stores in package rather than source code?

Solution

  • In the simplest sense, wheel is just:

    • a zip file
    • with a specific filename
    • and a specific directory layout
    • containing pure-Python source code
    • and any platform-specific binaries

    This means that a wheel (and any other distribution) is not a binary itself, but it may contain platform-specific binaries -- for example, if you are building/compiling some C code along with your Python package.

    Most wheels are pure-Python, which means that they only contain Python source code.

    It seems like you're asking how to "compile" Python code into an obfuscated binary. This is not the goal of a wheel. You might want to read more details on the wheel format here: https://www.python.org/dev/peps/pep-0427/

    Is there any way to create wheels which creates binary and stores in package rather than source code?

    Not with the wheel format. If this is actually your goal, you may want to look into pyinstaller, py2exe or cython, depending on the target platform.