python-3.xdllcpythonpyd

Convert .py file into .pyd file


Well after a lot of search unable to find a proper solution, I have my python file 'Main.py'.I want to have its .pyd file i.e Main.pyd. I have tried the way of using Cpython i.e first I have converted 'Main.py' file into 'Main.c'but then unable to convert the 'Main.c' into 'Main.pyd' and its quite tough way.Can I have a simple way to convert 'Main.py' into 'Main.pyd'?


Solution

  • I think you just need to create a library from your script. Create a new setup.py besides your sample_code.py:

    from distutils.core import setup
    from distutils.extension import Extension
    from Cython.Distutils import build_ext
    ext_modules = [
        Extension("sample_code",  ["sample_code.py"]),
    ]
    
    setup(
        name = 'My Program',
        cmdclass = {'build_ext': build_ext},
        ext_modules = ext_modules
    )
    

    Then use python setup.py build_ext --inplace to generate your library. You can find more information here.