{"id":8652,"date":"2024-02-23T14:16:04","date_gmt":"2024-02-23T05:16:04","guid":{"rendered":"https:\/\/www.skyer9.pe.kr\/wordpress\/?p=8652"},"modified":"2024-02-23T14:53:07","modified_gmt":"2024-02-23T05:53:07","slug":"cython-python-to-c","status":"publish","type":"post","link":"https:\/\/www.skyer9.pe.kr\/wordpress\/?p=8652","title":{"rendered":"Cython &#8211; python to C"},"content":{"rendered":"<h1>Cython &#8211; python to C<\/h1>\n<h2>OS \uac00 \uc708\ub3c4\uc6b0\uc778 \uacbd\uc6b0<\/h2>\n<p>Visual Studio 2022 Community \ub97c \uc124\uce58\ud574 \uc90d\ub2c8\ub2e4.<br \/>\n\ucee4\ubba4\ub2c8\ud2f0 \ubc84\uc804\uc758 \uacbd\uc6b0 \uac1c\uc778, 5\uba85 \uc774\ud558\uc758 \uc0ac\uc6a9\uc790\uc778 \uae30\uc5c5, \uc624\ud508 \uc18c\uc2a4, \ud559\uc220 \uc5f0\uad6c \ubc0f \uac15\uc758\uc2e4 \ud559\uc2b5 \ud658\uacbd\uc77c \uacbd\uc6b0 \ubb34\ub8cc\ub85c \uc0ac\uc6a9\ud560 \uc218 \uc788\ub294 IDE\uc785\ub2c8\ub2e4.<\/p>\n<p>\ub77c\uc774\uc13c\uc2a4\uac00 \ubb38\uc81c\uac00 \ub418\ub294 \uacbd\uc6b0 MinGW \ub97c \uc124\uce58\ud574\uc57c \ud558\ub294\ub370 \ubcf5\uc7a1\ud574\uc9d1\ub2c8\ub2e4.<\/p>\n<h2>\uc124\uce58<\/h2>\n<pre><code class=\"language-bash\">pip install cython<\/code><\/pre>\n<h2>my_pow.pyx \uc0dd\uc131<\/h2>\n<pre><code class=\"language-python\"># my_pow.pyx\nimport math\n\ndef my_pow(x, y):\n    return math.pow(x, y)<\/code><\/pre>\n<h2>setup.py \uc0dd\uc131<\/h2>\n<pre><code class=\"language-python\"># setup.py\n#\u00a0-*-\u00a0coding:\u00a0utf-8\u00a0-*-\nfrom distutils.core import setup\nfrom Cython.Build import cythonize\n\nsetup(ext_modules=cythonize(&quot;my_pow.pyx&quot;))<\/code><\/pre>\n<h2>\ube4c\ub4dc<\/h2>\n<pre><code class=\"language-bash\">python3 setup.py build_ext --inplace<\/code><\/pre>\n<p>\ucef4\ud30c\uc77c\ub41c \ubaa8\ub4c8\uc744 \ud655\uc778\ud560 \uc218 \uc788\ub2e4.<\/p>\n<pre><code class=\"language-bash\">ls -al\n......\nbuild\nmy_pow.c\nmy_pow.cpython-310-x86_64-linux-gnu.so\nmy_pow.pyx\nsetup.py<\/code><\/pre>\n<p>\uc708\ub3c4\uc6b0 MSVC \uc758 \uacbd\uc6b0 my_pow.cp39-win_amd64.pyd \uacfc \uac19\uc774 pyd (python dll) \ud30c\uc77c\uc774 \uc0dd\uc131\ub429\ub2c8\ub2e4.<\/p>\n<h2>my_pow.pyx \uc218\uc815<\/h2>\n<p>my_pow.cpython-310-x86_64-linux-gnu.so \uc5d0\uc11c \ud568\uc218\ub97c \ud638\ucd9c\ud558\ub294 \uac83\uc744 \ud655\uc778\ud558\uae30 \uc704\ud574 \uc544\ub798 \ub0b4\uc6a9\ub300\ub85c \uc218\uc815\ud569\ub2c8\ub2e4.<\/p>\n<pre><code class=\"language-python\"># my_pow.pyx\nimport math\n\n#def my_pow(x, y):\n#    return math.pow(x, y)<\/code><\/pre>\n<h2>cython \uc2e4\ud589<\/h2>\n<pre><code class=\"language-python\"># test.py\nfrom my_pow import my_pow\n\nprint(my_pow(2, 3))<\/code><\/pre>\n<pre><code class=\"language-bash\">python3 test.py\n8.0<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Cython &#8211; python to C OS \uac00 \uc708\ub3c4\uc6b0\uc778 \uacbd\uc6b0 Visual Studio 2022 Community \ub97c \uc124\uce58\ud574 \uc90d\ub2c8\ub2e4. \ucee4\ubba4\ub2c8\ud2f0 \ubc84\uc804\uc758 \uacbd\uc6b0 \uac1c\uc778, 5\uba85 \uc774\ud558\uc758 \uc0ac\uc6a9\uc790\uc778 \uae30\uc5c5, \uc624\ud508 \uc18c\uc2a4, \ud559\uc220 \uc5f0\uad6c \ubc0f \uac15\uc758\uc2e4 \ud559\uc2b5 \ud658\uacbd\uc77c \uacbd\uc6b0 \ubb34\ub8cc\ub85c \uc0ac\uc6a9\ud560 \uc218 \uc788\ub294 IDE\uc785\ub2c8\ub2e4. \ub77c\uc774\uc13c\uc2a4\uac00 \ubb38\uc81c\uac00 \ub418\ub294 \uacbd\uc6b0 MinGW \ub97c \uc124\uce58\ud574\uc57c \ud558\ub294\ub370 \ubcf5\uc7a1\ud574\uc9d1\ub2c8\ub2e4. \uc124\uce58 pip install cython my_pow.pyx \uc0dd\uc131 # my_pow.pyx\u2026 <span class=\"read-more\"><a href=\"https:\/\/www.skyer9.pe.kr\/wordpress\/?p=8652\">Read More &raquo;<\/a><\/span><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[40],"tags":[],"class_list":["post-8652","post","type-post","status-publish","format-standard","hentry","category-language"],"_links":{"self":[{"href":"https:\/\/www.skyer9.pe.kr\/wordpress\/index.php?rest_route=\/wp\/v2\/posts\/8652","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.skyer9.pe.kr\/wordpress\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.skyer9.pe.kr\/wordpress\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.skyer9.pe.kr\/wordpress\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.skyer9.pe.kr\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=8652"}],"version-history":[{"count":3,"href":"https:\/\/www.skyer9.pe.kr\/wordpress\/index.php?rest_route=\/wp\/v2\/posts\/8652\/revisions"}],"predecessor-version":[{"id":8655,"href":"https:\/\/www.skyer9.pe.kr\/wordpress\/index.php?rest_route=\/wp\/v2\/posts\/8652\/revisions\/8655"}],"wp:attachment":[{"href":"https:\/\/www.skyer9.pe.kr\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=8652"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.skyer9.pe.kr\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=8652"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.skyer9.pe.kr\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=8652"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}