简体   繁体   中英

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 ie Main.pyd. I have tried the way of using Cpython ie 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'?

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 .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM