1

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'?

Nabeel Ayub
  • 1,060
  • 3
  • 15
  • 35

1 Answers1

6

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.

Masoud Rahimi
  • 5,785
  • 15
  • 39
  • 67
  • 1
    it seems this code requires cython package preinstalled as a requirement. is there anyway to compile it without cython? and what if i don't have absolutely no C compiler in my device? – Ratul Hasan May 18 '21 at 18:39