{"id":986117,"date":"2024-12-27T07:42:10","date_gmt":"2024-12-26T23:42:10","guid":{"rendered":"https:\/\/docs.pingcode.com\/ask\/ask-ask\/986117.html"},"modified":"2024-12-27T07:42:12","modified_gmt":"2024-12-26T23:42:12","slug":"%e5%a6%82%e4%bd%95%e5%b5%8c%e5%85%a5python-%e5%88%b0-c","status":"publish","type":"post","link":"https:\/\/docs.pingcode.com\/ask\/ask-ask\/986117.html","title":{"rendered":"\u5982\u4f55\u5d4c\u5165python \u5230 c"},"content":{"rendered":"<p style=\"text-align:center;\" ><img decoding=\"async\" src=\"https:\/\/cdn-kb.worktile.com\/kb\/wp-content\/uploads\/2024\/04\/25062833\/b20d0773-cc28-4af9-a54c-c0c40b472cc5.webp\" alt=\"\u5982\u4f55\u5d4c\u5165python \u5230 c\" \/><\/p>\n<p><p> \u5d4c\u5165Python\u5230C\u4e2d\u53ef\u4ee5\u901a\u8fc7<strong>\u4f7f\u7528Python C API\u3001\u521b\u5efaPython\u6a21\u5757\u3001\u5229\u7528\u5d4c\u5165\u5f0fPython\u89e3\u91ca\u5668<\/strong>\u7b49\u65b9\u6cd5\u3002<strong>\u4f7f\u7528Python C API<\/strong>\u662f\u4e00\u79cd\u76f4\u63a5\u3001\u7075\u6d3b\u7684\u65b9\u5f0f\uff0c\u53ef\u4ee5\u5728C\u7a0b\u5e8f\u4e2d\u8c03\u7528Python\u4ee3\u7801\u3002\u5177\u4f53\u5b9e\u73b0\u9700\u8981\u4e86\u89e3Python\u5bf9\u8c61\u7684\u57fa\u672c\u64cd\u4f5c\u3002<strong>\u521b\u5efaPython\u6a21\u5757<\/strong>\u5219\u901a\u8fc7\u5c06Python\u4ee3\u7801\u6253\u5305\u4e3a\u53ef\u8c03\u7528\u7684C\u6269\u5c55\u6a21\u5757\uff0c\u4f7f\u5f97C\u7a0b\u5e8f\u53ef\u4ee5\u50cf\u8c03\u7528\u666e\u901a\u5e93\u4e00\u6837\u8c03\u7528Python\u4ee3\u7801\u3002<strong>\u5229\u7528\u5d4c\u5165\u5f0fPython\u89e3\u91ca\u5668<\/strong>\u5219\u662f\u5728C\u7a0b\u5e8f\u4e2d\u5d4c\u5165\u6574\u4e2aPython\u89e3\u91ca\u5668\uff0c\u4ee5\u4fbf\u8fd0\u884cPython\u4ee3\u7801\u7247\u6bb5\u3002\u5728\u8fd9\u4e09\u79cd\u65b9\u6cd5\u4e2d\uff0cPython C API\u63d0\u4f9b\u4e86\u6700\u7ec6\u7c92\u5ea6\u7684\u63a7\u5236\uff0c\u9002\u5408\u9700\u8981\u6df1\u5ea6\u96c6\u6210\u7684\u573a\u666f\u3002<\/p>\n<\/p>\n<p><h3>\u4e00\u3001\u4f7f\u7528Python C API<\/h3>\n<\/p>\n<p><p>Python C API\u662f\u7528\u4e8e\u5728C\/C++\u5e94\u7528\u7a0b\u5e8f\u4e2d\u5d4c\u5165Python\u7684\u5b98\u65b9\u63a5\u53e3\u3002\u5b83\u63d0\u4f9b\u4e86\u4e00\u7ec4\u51fd\u6570\u548c\u5b8f\u6765\u64cd\u4f5cPython\u5bf9\u8c61\uff0c\u6267\u884cPython\u4ee3\u7801\uff0c\u4ee5\u53ca\u7ba1\u7406Python\u73af\u5883\u3002<\/p>\n<\/p>\n<p><h4>1\u3001\u521d\u59cb\u5316Python\u73af\u5883<\/h4>\n<\/p>\n<p><p>\u5728\u4f7f\u7528Python C API\u4e4b\u524d\uff0c\u5fc5\u987b\u521d\u59cb\u5316Python\u73af\u5883\u3002\u8fd9\u53ef\u4ee5\u901a\u8fc7\u8c03\u7528<code>Py_Initialize()<\/code>\u51fd\u6570\u6765\u5b8c\u6210\u3002\u8fd9\u4e2a\u51fd\u6570\u4f1a\u8bbe\u7f6ePython\u89e3\u91ca\u5668\u7684\u5185\u90e8\u72b6\u6001\u5e76\u51c6\u5907\u6267\u884cPython\u4ee3\u7801\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-c\">#include &lt;Python.h&gt;<\/p>\n<p>int m<a href=\"https:\/\/docs.pingcode.com\/blog\/59162.html\" target=\"_blank\">AI<\/a>n() {<\/p>\n<p>    Py_Initialize();<\/p>\n<p>    \/\/ Your Python code execution here<\/p>\n<p>    Py_Finalize();<\/p>\n<p>    return 0;<\/p>\n<p>}<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h4>2\u3001\u6267\u884cPython\u4ee3\u7801<\/h4>\n<\/p>\n<p><p>\u5728\u521d\u59cb\u5316Python\u73af\u5883\u540e\uff0c\u53ef\u4ee5\u4f7f\u7528<code>PyRun_SimpleString()<\/code>\u6765\u6267\u884c\u7b80\u5355\u7684Python\u4ee3\u7801\u3002\u8fd9\u5bf9\u4e8e\u6267\u884c\u5355\u884cPython\u4ee3\u7801\u6216\u811a\u672c\u7247\u6bb5\u975e\u5e38\u6709\u7528\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-c\">PyRun_SimpleString(&quot;print(&#39;Hello from embedded Python!&#39;)&quot;);<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h4>3\u3001\u8c03\u7528Python\u51fd\u6570<\/h4>\n<\/p>\n<p><p>\u4e3a\u4e86\u8c03\u7528Python\u51fd\u6570\uff0c\u9700\u8981\u9996\u5148\u5bfc\u5165Python\u6a21\u5757\uff0c\u7136\u540e\u83b7\u53d6\u51fd\u6570\u5bf9\u8c61\u5e76\u8fdb\u884c\u8c03\u7528\u3002\u4ee5\u4e0b\u662f\u4e00\u4e2a\u7b80\u5355\u7684\u4f8b\u5b50\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-c\">PyObject *pName, *<a href=\"https:\/\/docs.pingcode.com\/blog\/project-management\/52627.html\" target=\"_blank\">PMO<\/a>dule, *pFunc;<\/p>\n<p>PyObject *pArgs, *pValue;<\/p>\n<p>pName = PyUnicode_DecodeFSDefault(&quot;mymodule&quot;);<\/p>\n<p>pModule = PyImport_Import(pName);<\/p>\n<p>Py_DECREF(pName);<\/p>\n<p>if (pModule != NULL) {<\/p>\n<p>    pFunc = PyObject_GetAttrString(pModule, &quot;myfunction&quot;);<\/p>\n<p>    if (pFunc &amp;&amp; PyCallable_Check(pFunc)) {<\/p>\n<p>        pArgs = PyTuple_Pack(1, PyLong_FromLong(42));<\/p>\n<p>        pValue = PyObject_CallObject(pFunc, pArgs);<\/p>\n<p>        Py_DECREF(pArgs);<\/p>\n<p>        if (pValue != NULL) {<\/p>\n<p>            printf(&quot;Result of call: %ld\\n&quot;, PyLong_AsLong(pValue));<\/p>\n<p>            Py_DECREF(pValue);<\/p>\n<p>        }<\/p>\n<p>    }<\/p>\n<p>    Py_XDECREF(pFunc);<\/p>\n<p>    Py_DECREF(pModule);<\/p>\n<p>}<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>\u4e8c\u3001\u521b\u5efaPython\u6a21\u5757<\/h3>\n<\/p>\n<p><p>\u53e6\u4e00\u79cd\u5d4c\u5165Python\u5230C\u4e2d\u7684\u65b9\u6cd5\u662f\u521b\u5efaPython\u6a21\u5757\uff0c\u8fd9\u6837Python\u51fd\u6570\u53ef\u4ee5\u88ab\u7f16\u8bd1\u6210\u5171\u4eab\u5e93\uff0c\u7136\u540e\u4eceC\u7a0b\u5e8f\u4e2d\u8c03\u7528\u3002<\/p>\n<\/p>\n<p><h4>1\u3001\u5b9a\u4e49Python\u6a21\u5757<\/h4>\n<\/p>\n<p><p>\u9996\u5148\uff0c\u9700\u8981\u521b\u5efa\u4e00\u4e2aC\u6587\u4ef6\uff0c\u5b9a\u4e49Python\u6a21\u5757\u548c\u51fd\u6570\u3002\u4ee5\u4e0b\u662f\u4e00\u4e2a\u7b80\u5355\u7684\u4f8b\u5b50\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-c\">#include &lt;Python.h&gt;<\/p>\n<p>static PyObject* mymodule_myfunction(PyObject *self, PyObject *args) {<\/p>\n<p>    int input;<\/p>\n<p>    if (!PyArg_ParseTuple(args, &quot;i&quot;, &amp;input)) {<\/p>\n<p>        return NULL;<\/p>\n<p>    }<\/p>\n<p>    return PyLong_FromLong(input * 2);<\/p>\n<p>}<\/p>\n<p>static PyMethodDef MyModuleMethods[] = {<\/p>\n<p>    {&quot;myfunction&quot;, mymodule_myfunction, METH_VARARGS, &quot;Multiply input by 2&quot;},<\/p>\n<p>    {NULL, NULL, 0, NULL}<\/p>\n<p>};<\/p>\n<p>static struct PyModuleDef mymodule = {<\/p>\n<p>    PyModuleDef_HEAD_INIT, &quot;mymodule&quot;, NULL, -1, MyModuleMethods<\/p>\n<p>};<\/p>\n<p>PyMODINIT_FUNC PyInit_mymodule(void) {<\/p>\n<p>    return PyModule_Create(&amp;mymodule);<\/p>\n<p>}<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h4>2\u3001\u7f16\u8bd1\u6a21\u5757<\/h4>\n<\/p>\n<p><p>\u4f7f\u7528Python\u7684<code>setup.py<\/code>\u811a\u672c\u6765\u7f16\u8bd1\u751f\u6210\u5171\u4eab\u5e93\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">from distutils.core import setup, Extension<\/p>\n<p>module = Extension(&#39;mymodule&#39;, sources = [&#39;mymodule.c&#39;])<\/p>\n<p>setup(name = &#39;MyModule&#39;,<\/p>\n<p>      version = &#39;1.0&#39;,<\/p>\n<p>      description = &#39;This is a demo package&#39;,<\/p>\n<p>      ext_modules = [module])<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u8fd0\u884c\u4ee5\u4e0b\u547d\u4ee4\u7f16\u8bd1\u6a21\u5757\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">python setup.py build<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h4>3\u3001\u5728C\u7a0b\u5e8f\u4e2d\u8c03\u7528\u6a21\u5757<\/h4>\n<\/p>\n<p><p>\u7f16\u8bd1\u5b8c\u6210\u540e\uff0c\u53ef\u4ee5\u5728C\u7a0b\u5e8f\u4e2d\u4f7f\u7528Python C API\u6765\u52a0\u8f7d\u548c\u8c03\u7528\u6a21\u5757\u4e2d\u7684\u51fd\u6570\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-c\">Py_Initialize();<\/p>\n<p>PyObject *pName, *pModule, *pFunc, *pValue;<\/p>\n<p>PyObject *pArgs;<\/p>\n<p>pName = PyUnicode_DecodeFSDefault(&quot;mymodule&quot;);<\/p>\n<p>pModule = PyImport_Import(pName);<\/p>\n<p>Py_DECREF(pName);<\/p>\n<p>if (pModule != NULL) {<\/p>\n<p>    pFunc = PyObject_GetAttrString(pModule, &quot;myfunction&quot;);<\/p>\n<p>    if (pFunc &amp;&amp; PyCallable_Check(pFunc)) {<\/p>\n<p>        pArgs = PyTuple_Pack(1, PyLong_FromLong(21));<\/p>\n<p>        pValue = PyObject_CallObject(pFunc, pArgs);<\/p>\n<p>        Py_DECREF(pArgs);<\/p>\n<p>        if (pValue != NULL) {<\/p>\n<p>            printf(&quot;Result of call: %ld\\n&quot;, PyLong_AsLong(pValue));<\/p>\n<p>            Py_DECREF(pValue);<\/p>\n<p>        }<\/p>\n<p>    }<\/p>\n<p>    Py_XDECREF(pFunc);<\/p>\n<p>    Py_DECREF(pModule);<\/p>\n<p>}<\/p>\n<p>Py_Finalize();<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>\u4e09\u3001\u5229\u7528\u5d4c\u5165\u5f0fPython\u89e3\u91ca\u5668<\/h3>\n<\/p>\n<p><p>\u5d4c\u5165\u5f0fPython\u89e3\u91ca\u5668\u5141\u8bb8C\u7a0b\u5e8f\u8fd0\u884c\u5b8c\u6574\u7684Python\u811a\u672c\u548c\u7ba1\u7406Python\u5bf9\u8c61\u3002\u8fd9\u79cd\u65b9\u6cd5\u9002\u5408\u9700\u8981\u9891\u7e41\u3001\u590d\u6742\u7684Python\u4e0eC\u4ea4\u4e92\u7684\u573a\u666f\u3002<\/p>\n<\/p>\n<p><h4>1\u3001\u521d\u59cb\u5316\u548c\u7ec8\u6b62Python\u89e3\u91ca\u5668<\/h4>\n<\/p>\n<p><p>\u4e0ePython C API\u7c7b\u4f3c\uff0c\u5d4c\u5165Python\u89e3\u91ca\u5668\u4e5f\u9700\u8981\u521d\u59cb\u5316\u548c\u7ec8\u6b62\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-c\">Py_Initialize();<\/p>\n<p>\/\/ Your Python script execution<\/p>\n<p>Py_Finalize();<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h4>2\u3001\u6267\u884c\u5b8c\u6574Python\u811a\u672c<\/h4>\n<\/p>\n<p><p>\u53ef\u4ee5\u4f7f\u7528<code>PyRun_SimpleFile()<\/code>\u6765\u6267\u884cPython\u811a\u672c\u6587\u4ef6\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-c\">FILE* fp = fopen(&quot;script.py&quot;, &quot;r&quot;);<\/p>\n<p>PyRun_SimpleFile(fp, &quot;script.py&quot;);<\/p>\n<p>fclose(fp);<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h4>3\u3001\u4e0ePython\u5bf9\u8c61\u4ea4\u4e92<\/h4>\n<\/p>\n<p><p>\u5d4c\u5165\u5f0f\u89e3\u91ca\u5668\u5141\u8bb8\u4e0ePython\u5bf9\u8c61\u8fdb\u884c\u590d\u6742\u7684\u4ea4\u4e92\u3002\u53ef\u4ee5\u521b\u5efa\u3001\u4fee\u6539\u3001\u5220\u9664Python\u5bf9\u8c61\uff0c\u4ee5\u53ca\u8c03\u7528Python\u51fd\u6570\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-c\">PyObject *pInt = PyLong_FromLong(123);<\/p>\n<p>printf(&quot;Value: %ld\\n&quot;, PyLong_AsLong(pInt));<\/p>\n<p>Py_DECREF(pInt);<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>\u56db\u3001\u6027\u80fd\u548c\u4f18\u5316<\/h3>\n<\/p>\n<p><p>\u5d4c\u5165Python\u5230C\u4e2d\u53ef\u80fd\u4f1a\u5e26\u6765\u6027\u80fd\u4e0a\u7684\u5f00\u9500\u3002\u4e3a\u4e86\u4f18\u5316\u6027\u80fd\uff0c\u53ef\u4ee5\u8003\u8651\u4ee5\u4e0b\u51e0\u79cd\u65b9\u6cd5\uff1a<\/p>\n<\/p>\n<p><h4>1\u3001\u51cf\u5c11Python\u8c03\u7528\u6b21\u6570<\/h4>\n<\/p>\n<p><p>\u5c3d\u91cf\u51cf\u5c11Python\u51fd\u6570\u8c03\u7528\u7684\u6b21\u6570\u3002\u5c06\u591a\u4e2a\u64cd\u4f5c\u5408\u5e76\u4e3a\u4e00\u4e2aPython\u8c03\u7528\uff0c\u53ef\u4ee5\u51cf\u5c11C\u4e0ePython\u4e4b\u95f4\u7684\u5207\u6362\u5f00\u9500\u3002<\/p>\n<\/p>\n<p><h4>2\u3001\u4f7f\u7528\u5408\u9002\u7684\u6570\u636e\u7ed3\u6784<\/h4>\n<\/p>\n<p><p>\u5728C\u4e0ePython\u4e4b\u95f4\u4f20\u9012\u6570\u636e\u65f6\uff0c\u9009\u62e9\u5408\u9002\u7684\u6570\u636e\u7ed3\u6784\u4ee5\u6700\u5c0f\u5316\u6570\u636e\u8f6c\u6362\u7684\u5f00\u9500\u3002\u4f8b\u5982\uff0c\u4f7f\u7528<code>PyList<\/code>\u800c\u4e0d\u662f<code>PyTuple<\/code>\u5728\u9700\u8981\u53ef\u53d8\u957f\u5ea6\u6570\u636e\u65f6\u3002<\/p>\n<\/p>\n<p><h4>3\u3001\u6279\u91cf\u5904\u7406\u6570\u636e<\/h4>\n<\/p>\n<p><p>\u5982\u679c\u9700\u8981\u5904\u7406\u5927\u91cf\u6570\u636e\uff0c\u53ef\u4ee5\u8003\u8651\u6279\u91cf\u4f20\u9012\u6570\u636e\uff0c\u800c\u4e0d\u662f\u9010\u4e2a\u4f20\u9012\u3002\u8fd9\u53ef\u4ee5\u663e\u8457\u63d0\u9ad8\u6027\u80fd\u3002<\/p>\n<\/p>\n<p><h3>\u4e94\u3001\u5e94\u7528\u573a\u666f\u4e0e\u5b9e\u8df5<\/h3>\n<\/p>\n<p><p>\u5d4c\u5165Python\u5230C\u4e2d\u7684\u6280\u672f\u53ef\u4ee5\u5e94\u7528\u4e8e\u591a\u79cd\u573a\u666f\uff0c\u5305\u62ec\u4f46\u4e0d\u9650\u4e8e\uff1a<\/p>\n<\/p>\n<p><h4>1\u3001\u6e38\u620f\u5f00\u53d1<\/h4>\n<\/p>\n<p><p>\u5728\u6e38\u620f\u5f15\u64ce\u4e2d\u5d4c\u5165Python\u53ef\u4ee5\u63d0\u4f9b\u7075\u6d3b\u7684\u811a\u672c\u652f\u6301\uff0c\u4f7f\u5f97\u6e38\u620f\u903b\u8f91\u66f4\u6613\u4e8e\u7f16\u5199\u548c\u4fee\u6539\u3002<\/p>\n<\/p>\n<p><h4>2\u3001\u79d1\u5b66\u8ba1\u7b97<\/h4>\n<\/p>\n<p><p>\u5728\u9ad8\u6027\u80fd\u8ba1\u7b97\u4e2d\uff0c\u901a\u8fc7C\u5b9e\u73b0\u6027\u80fd\u5173\u952e\u90e8\u5206\uff0c\u800c\u4f7f\u7528Python\u5b9e\u73b0\u7b97\u6cd5\u903b\u8f91\uff0c\u53ef\u4ee5\u517c\u987e\u6027\u80fd\u548c\u5f00\u53d1\u6548\u7387\u3002<\/p>\n<\/p>\n<p><h4>3\u3001\u81ea\u52a8\u5316\u6d4b\u8bd5<\/h4>\n<\/p>\n<p><p>\u5d4c\u5165Python\u5230C\u5e94\u7528\u4e2d\u53ef\u4ee5\u7b80\u5316\u6d4b\u8bd5\u811a\u672c\u7684\u7f16\u5199\u548c\u6267\u884c\uff0c\u4f7f\u5f97\u81ea\u52a8\u5316\u6d4b\u8bd5\u66f4\u4e3a\u4fbf\u6377\u3002<\/p>\n<\/p>\n<p><p>\u603b\u7684\u6765\u8bf4\uff0c\u5d4c\u5165Python\u5230C\u4e2d\u63d0\u4f9b\u4e86\u4e00\u79cd\u5f3a\u5927\u7684\u65b9\u5f0f\u6765\u7ed3\u5408\u4e24\u79cd\u8bed\u8a00\u7684\u4f18\u52bf\uff0c\u4f7f\u5f97\u5e94\u7528\u7a0b\u5e8f\u65e2\u80fd\u9ad8\u6548\u8fd0\u884c\uff0c\u53c8\u80fd\u7075\u6d3b\u6269\u5c55\u3002\u901a\u8fc7\u638c\u63e1Python C API\u3001\u521b\u5efaPython\u6a21\u5757\u548c\u5229\u7528\u5d4c\u5165\u5f0f\u89e3\u91ca\u5668\uff0c\u5f00\u53d1\u8005\u53ef\u4ee5\u6839\u636e\u5177\u4f53\u9700\u6c42\u9009\u62e9\u5408\u9002\u7684\u65b9\u6cd5\u8fdb\u884c\u96c6\u6210\u3002<\/p>\n<\/p>\n<h2><strong>\u76f8\u5173\u95ee\u7b54FAQs\uff1a<\/strong><\/h2>\n<p> <strong>\u5982\u4f55\u5728C\u7a0b\u5e8f\u4e2d\u8c03\u7528Python\u51fd\u6570\uff1f<\/strong><br \/>\u5728C\u7a0b\u5e8f\u4e2d\u8c03\u7528Python\u51fd\u6570\u53ef\u4ee5\u901a\u8fc7Python\/C API\u5b9e\u73b0\u3002\u60a8\u9700\u8981\u5305\u542bPython.h\u5934\u6587\u4ef6\uff0c\u5e76\u4f7f\u7528Py_Initialize()\u521d\u59cb\u5316Python\u89e3\u91ca\u5668\u3002\u63a5\u7740\uff0c\u53ef\u4ee5\u4f7f\u7528PyImport_ImportModule()\u52a0\u8f7dPython\u6a21\u5757\uff0c\u5e76\u901a\u8fc7PyObject_GetAttrString()\u83b7\u53d6\u51fd\u6570\u5bf9\u8c61\uff0c\u6700\u540e\u4f7f\u7528PyObject_CallObject()\u8c03\u7528\u8be5\u51fd\u6570\u3002\u8bb0\u5f97\u5728\u5b8c\u6210\u540e\u8c03\u7528Py_Finalize()\u6765\u6e05\u7406\u8d44\u6e90\u3002<\/p>\n<p><strong>\u662f\u5426\u9700\u8981\u5b89\u88c5\u7279\u5b9a\u7248\u672c\u7684Python\u624d\u80fd\u5d4c\u5165\uff1f<\/strong><br \/>\u662f\u7684\uff0c\u60a8\u9700\u8981\u786e\u4fdd\u5b89\u88c5\u7684Python\u7248\u672c\u4e0e\u60a8\u7684C\u7f16\u8bd1\u5668\u517c\u5bb9\u3002\u901a\u5e38\u5efa\u8bae\u4f7f\u7528Python\u7684\u6700\u65b0\u7a33\u5b9a\u7248\u672c\u3002\u6b64\u5916\uff0c\u8fd8\u9700\u786e\u4fdd\u7f16\u8bd1\u65f6\u94fe\u63a5\u5230\u6b63\u786e\u7684Python\u5e93\u6587\u4ef6\uff08\u5982libpython.a\u6216libpython.so\uff09\uff0c\u4ee5\u907f\u514d\u7248\u672c\u4e0d\u5339\u914d\u7684\u95ee\u9898\u3002<\/p>\n<p><strong>\u5d4c\u5165Python\u5230C\u7a0b\u5e8f\u6709\u4ec0\u4e48\u6027\u80fd\u5f71\u54cd\uff1f<\/strong><br \/>\u5d4c\u5165Python\u5230C\u7a0b\u5e8f\u53ef\u80fd\u4f1a\u5e26\u6765\u4e00\u5b9a\u7684\u6027\u80fd\u5f00\u9500\uff0c\u4e3b\u8981\u4f53\u73b0\u5728Python\u89e3\u91ca\u5668\u7684\u521d\u59cb\u5316\u548c\u51fd\u6570\u8c03\u7528\u7684\u4e0a\u4e0b\u6587\u5207\u6362\u4e0a\u3002\u5982\u679c\u5bf9\u6027\u80fd\u8981\u6c42\u8f83\u9ad8\uff0c\u53ef\u4ee5\u8003\u8651\u5c06\u9891\u7e41\u8c03\u7528\u7684Python\u4ee3\u7801\u4f18\u5316\u4e3aC\u6269\u5c55\u6a21\u5757\uff0c\u6216\u901a\u8fc7\u5176\u4ed6\u4f18\u5316\u624b\u6bb5\u51cf\u5c11\u5d4c\u5165\u5e26\u6765\u7684\u5f71\u54cd\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"\u5d4c\u5165Python\u5230C\u4e2d\u53ef\u4ee5\u901a\u8fc7\u4f7f\u7528Python C API\u3001\u521b\u5efaPython\u6a21\u5757\u3001\u5229\u7528\u5d4c\u5165\u5f0fPython\u89e3\u91ca\u5668 [&hellip;]","protected":false},"author":3,"featured_media":986122,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[37],"tags":[],"acf":[],"_links":{"self":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/986117"}],"collection":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/comments?post=986117"}],"version-history":[{"count":"1","href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/986117\/revisions"}],"predecessor-version":[{"id":986123,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/986117\/revisions\/986123"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media\/986122"}],"wp:attachment":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media?parent=986117"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/categories?post=986117"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/tags?post=986117"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}