Automatic translation of Python source modules with Python ByteCoat
After extracting the archive you'll get a directory such as bytecoat-python25-x86-glibc27. Inside this directory executing the command
./BCconvert modul.pyc -o
leads to file
./BCconvert /project/test.pyc -o /project
Command line arguments:
-h, --help show help message and exit
-t DIR, --template-dir=DIR Template directory (in case you BCconvert
is called from a different directory, this
must point to zu
<some-path>/bytecoat/templates
-o DIR, --output-dir=DIR write files to DIR
-n, --line-numbers enable line numbers in traceback
-r, --tracing enable tracing support
The generated C file can be compiled into a shared library using
pyhton25 BCcompile.py /project/test.c
The next python import of test.py will use test.so instead of test.pyc. Command line arguments:
-o DIR, --output-dir=DIR write files to DIR
Simple compilation guide for your C source modules translated with Python ByteCoat
from distutils.core import setup, Extension
setup(name='foo',
version='1.0',
ext_modules=[Extension('foo', ['foo.c'])],
)
"foo" is the name of the module to be translated and should be adapted for your file. In case you want to compile multiple files into extension modules you can append them to the list that is given to the "ext_modules" parameter like this
ext_modules=[Extension('foo', ['foo.c']),
Extension('bar',['bar.c']),]
After that, you need to start the compilation by running
python setup.py build_ext
to build all extension modules. The ready to use ".so" or ".pyd" extension modules can now be found in the "build" subdirectory. Just move or copy them to the location where you need them. Running
python setup.py install
will install the compiled extension modules to your "site-packages" directory. Make sure this command is called with the same Python version that has been used to generate the byte code files from the Python source code. We generate our C code for the same version that we detect in the header of the ".pyc" file and the setup.py script for those files needs to be started with the same Python executable in order to guarantee the inclusion of the correct Python header files and compile options.
Furthermore, setup.py needs to find a working C compiler such as "gcc" or Microsoft's "cl.exe". Find answer to frequently asked questions. More information on how to use Python's "distutils" module can be found at http://docs.python.org/distutils/index.html