Convert .py file into .pyd file

大兔子大兔子 提交于 2021-01-05 16:10:44

问题


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


回答1:


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.



来源:https://stackoverflow.com/questions/51465837/convert-py-file-into-pyd-file

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!