{"id":1030977,"date":"2024-12-31T11:21:38","date_gmt":"2024-12-31T03:21:38","guid":{"rendered":"https:\/\/docs.pingcode.com\/ask\/ask-ask\/1030977.html"},"modified":"2024-12-31T11:21:41","modified_gmt":"2024-12-31T03:21:41","slug":"python%e5%a6%82%e4%bd%95%e5%af%bc%e5%85%a5%e8%87%aa%e5%b7%b1%e7%9a%84%e5%87%bd%e6%95%b0%e5%ba%93","status":"publish","type":"post","link":"https:\/\/docs.pingcode.com\/ask\/ask-ask\/1030977.html","title":{"rendered":"python\u5982\u4f55\u5bfc\u5165\u81ea\u5df1\u7684\u51fd\u6570\u5e93"},"content":{"rendered":"<p style=\"text-align:center;\" ><img decoding=\"async\" src=\"https:\/\/cdn-docs.pingcode.com\/wp-content\/uploads\/2024\/12\/84957aba-ccec-43ad-a653-300e3cd54ff9.webp?x-oss-process=image\/auto-orient,1\/format,webp\" alt=\"python\u5982\u4f55\u5bfc\u5165\u81ea\u5df1\u7684\u51fd\u6570\u5e93\" \/><\/p>\n<p><p> <strong>\u8981\u5bfc\u5165\u81ea\u5df1\u7684\u51fd\u6570\u5e93\uff0c\u4f60\u53ef\u4ee5\u521b\u5efa\u4e00\u4e2a\u5305\u542b\u51fd\u6570\u7684Python\u6587\u4ef6\uff0c\u5e76\u5c06\u5176\u4f5c\u4e3a\u6a21\u5757\u5bfc\u5165\u5230\u5176\u4ed6Python\u811a\u672c\u4e2d\u3002<\/strong> \u9996\u5148\uff0c\u521b\u5efa\u4e00\u4e2a\u5305\u542b\u51fd\u6570\u7684Python\u6587\u4ef6\uff0c\u4f8b\u5982 <code>mylib.py<\/code>\uff0c\u7136\u540e\u5728\u9700\u8981\u4f7f\u7528\u8fd9\u4e9b\u51fd\u6570\u7684\u811a\u672c\u4e2d\u4f7f\u7528 <code>import<\/code> \u8bed\u53e5\u5bfc\u5165\u8fd9\u4e2a\u6a21\u5757\u3002\u8fd9\u6837\uff0c\u4f60\u5c31\u53ef\u4ee5\u5728\u811a\u672c\u4e2d\u8c03\u7528\u8fd9\u4e9b\u51fd\u6570\u3002\u4e3a\u4e86\u66f4\u8be6\u7ec6\u5730\u4e86\u89e3\u8fd9\u4e00\u8fc7\u7a0b\uff0c\u4e0b\u9762\u5c06\u4ecb\u7ecd\u5982\u4f55\u521b\u5efa\u548c\u5bfc\u5165\u81ea\u5df1\u7684\u51fd\u6570\u5e93\uff0c\u5e76\u63d0\u4f9b\u4e00\u4e9b\u5b9e\u8df5\u5efa\u8bae\u3002<\/p>\n<\/p>\n<p><p>\u4e00\u3001\u521b\u5efa\u81ea\u5df1\u7684\u51fd\u6570\u5e93<\/p>\n<\/p>\n<p><p>\u8981\u521b\u5efa\u81ea\u5df1\u7684\u51fd\u6570\u5e93\uff0c\u9996\u5148\u9700\u8981\u7f16\u5199\u4e00\u4e2aPython\u6587\u4ef6\uff0c\u5e76\u5728\u5176\u4e2d\u5b9a\u4e49\u4f60\u60f3\u8981\u7684\u51fd\u6570\u3002\u4f8b\u5982\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\"># mylib.py<\/p>\n<p>def add(a, b):<\/p>\n<p>    return a + b<\/p>\n<p>def subtract(a, b):<\/p>\n<p>    return a - b<\/p>\n<p>def multiply(a, b):<\/p>\n<p>    return a * b<\/p>\n<p>def divide(a, b):<\/p>\n<p>    if b == 0:<\/p>\n<p>        r<a href=\"https:\/\/docs.pingcode.com\/blog\/59162.html\" target=\"_blank\">AI<\/a>se ValueError(&quot;Cannot divide by zero&quot;)<\/p>\n<p>    return a \/ b<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728\u8fd9\u4e2a\u793a\u4f8b\u4e2d\uff0c\u6211\u4eec\u521b\u5efa\u4e86\u4e00\u4e2a\u540d\u4e3a <code>mylib.py<\/code> \u7684\u6587\u4ef6\uff0c\u5176\u4e2d\u5305\u542b\u4e86\u56db\u4e2a\u7b80\u5355\u7684\u6570\u5b66\u51fd\u6570\uff1a\u52a0\u6cd5\u3001\u51cf\u6cd5\u3001\u4e58\u6cd5\u548c\u9664\u6cd5\u3002<\/p>\n<\/p>\n<p><p>\u4e8c\u3001\u5bfc\u5165\u81ea\u5df1\u7684\u51fd\u6570\u5e93<\/p>\n<\/p>\n<p><p>\u63a5\u4e0b\u6765\uff0c\u6211\u4eec\u5c06\u5728\u53e6\u4e00\u4e2aPython\u811a\u672c\u4e2d\u5bfc\u5165\u5e76\u4f7f\u7528\u8fd9\u4e9b\u51fd\u6570\u3002\u5047\u8bbe\u6211\u4eec\u6709\u4e00\u4e2a\u540d\u4e3a <code>main.py<\/code> \u7684\u6587\u4ef6\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\"># main.py<\/p>\n<p>import mylib<\/p>\n<p>result_add = mylib.add(5, 3)<\/p>\n<p>result_subtract = mylib.subtract(5, 3)<\/p>\n<p>result_multiply = mylib.multiply(5, 3)<\/p>\n<p>result_divide = mylib.divide(5, 3)<\/p>\n<p>print(&quot;Addition:&quot;, result_add)<\/p>\n<p>print(&quot;Subtraction:&quot;, result_subtract)<\/p>\n<p>print(&quot;Multiplication:&quot;, result_multiply)<\/p>\n<p>print(&quot;Division:&quot;, result_divide)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728\u8fd9\u4e2a\u793a\u4f8b\u4e2d\uff0c\u6211\u4eec\u4f7f\u7528 <code>import mylib<\/code> \u8bed\u53e5\u5bfc\u5165 <code>mylib.py<\/code> \u6587\u4ef6\u4e2d\u7684\u51fd\u6570\uff0c\u7136\u540e\u8c03\u7528\u8fd9\u4e9b\u51fd\u6570\u5e76\u6253\u5370\u7ed3\u679c\u3002<\/p>\n<\/p>\n<p><p>\u4e09\u3001\u4f7f\u7528\u76f8\u5bf9\u548c\u7edd\u5bf9\u5bfc\u5165<\/p>\n<\/p>\n<p><p>\u5728\u4e00\u4e9b\u9879\u76ee\u4e2d\uff0c\u4f60\u53ef\u80fd\u9700\u8981\u4f7f\u7528\u76f8\u5bf9\u5bfc\u5165\u6216\u7edd\u5bf9\u5bfc\u5165\u6765\u5bfc\u5165\u6a21\u5757\u3002\u76f8\u5bf9\u5bfc\u5165\u901a\u5e38\u5728\u5927\u578b\u9879\u76ee\u4e2d\u4f7f\u7528\uff0c\u7279\u522b\u662f\u5f53\u6a21\u5757\u4f4d\u4e8e\u4e0d\u540c\u7684\u76ee\u5f55\u4e2d\u65f6\u3002\u7edd\u5bf9\u5bfc\u5165\u5219\u662f\u4f7f\u7528\u6a21\u5757\u7684\u5b8c\u5168\u9650\u5b9a\u540d\u79f0\u8fdb\u884c\u5bfc\u5165\u3002<\/p>\n<\/p>\n<p><p>\u4f8b\u5982\uff0c\u5982\u679c\u4f60\u7684\u9879\u76ee\u7ed3\u6784\u5982\u4e0b\uff1a<\/p>\n<\/p>\n<p><pre><code>my_project\/<\/p>\n<p>    main.py<\/p>\n<p>    utils\/<\/p>\n<p>        __init__.py<\/p>\n<p>        mylib.py<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728 <code>main.py<\/code> \u4e2d\uff0c\u4f60\u53ef\u4ee5\u4f7f\u7528\u7edd\u5bf9\u5bfc\u5165\u6216\u76f8\u5bf9\u5bfc\u5165\u6765\u5bfc\u5165 <code>mylib<\/code> \u6a21\u5757\u3002<\/p>\n<\/p>\n<p><p>\u7edd\u5bf9\u5bfc\u5165\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\"># main.py<\/p>\n<p>from utils import mylib<\/p>\n<p>result_add = mylib.add(5, 3)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u76f8\u5bf9\u5bfc\u5165\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\"># main.py<\/p>\n<p>from .utils import mylib<\/p>\n<p>result_add = mylib.add(5, 3)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u56db\u3001\u4f7f\u7528\u5305\u6765\u7ec4\u7ec7\u51fd\u6570\u5e93<\/p>\n<\/p>\n<p><p>\u5f53\u4f60\u7684\u51fd\u6570\u5e93\u53d8\u5f97\u66f4\u52a0\u590d\u6742\u65f6\uff0c\u4f60\u53ef\u80fd\u9700\u8981\u4f7f\u7528\u5305\u6765\u7ec4\u7ec7\u4f60\u7684\u4ee3\u7801\u3002\u4e00\u4e2a\u5305\u662f\u4e00\u4e2a\u5305\u542b\u4e00\u4e2a\u6216\u591a\u4e2a\u6a21\u5757\u7684\u76ee\u5f55\u3002\u4e3a\u4e86\u5c06\u76ee\u5f55\u6807\u8bb0\u4e3a\u5305\uff0c\u4f60\u9700\u8981\u5728\u76ee\u5f55\u4e2d\u5305\u542b\u4e00\u4e2a <code>__init__.py<\/code> \u6587\u4ef6\u3002<\/p>\n<\/p>\n<p><p>\u4f8b\u5982\uff1a<\/p>\n<\/p>\n<p><pre><code>my_project\/<\/p>\n<p>    main.py<\/p>\n<p>    mylib\/<\/p>\n<p>        __init__.py<\/p>\n<p>        math_operations.py<\/p>\n<p>        string_operations.py<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728\u8fd9\u4e2a\u7ed3\u6784\u4e2d\uff0c<code>mylib<\/code> \u662f\u4e00\u4e2a\u5305\uff0c\u5305\u542b\u4e24\u4e2a\u6a21\u5757 <code>math_operations.py<\/code> \u548c <code>string_operations.py<\/code>\u3002\u4f60\u53ef\u4ee5\u5728 <code>__init__.py<\/code> \u4e2d\u5bfc\u5165\u8fd9\u4e9b\u6a21\u5757\uff0c\u4ee5\u4fbf\u5728\u5bfc\u5165\u5305\u65f6\u81ea\u52a8\u52a0\u8f7d\u5b83\u4eec\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\"># mylib\/__init__.py<\/p>\n<p>from .math_operations import add, subtract, multiply, divide<\/p>\n<p>from .string_operations import concatenate, split<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u73b0\u5728\uff0c\u4f60\u53ef\u4ee5\u5728 <code>main.py<\/code> \u4e2d\u5bfc\u5165\u5e76\u4f7f\u7528\u8fd9\u4e9b\u51fd\u6570\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\"># main.py<\/p>\n<p>import mylib<\/p>\n<p>result_add = mylib.add(5, 3)<\/p>\n<p>result_concat = mylib.concatenate(&quot;Hello&quot;, &quot;World&quot;)<\/p>\n<p>print(&quot;Addition:&quot;, result_add)<\/p>\n<p>print(&quot;Concatenation:&quot;, result_concat)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u4e94\u3001\u5904\u7406\u4f9d\u8d56\u5173\u7cfb\u548c\u73af\u5883<\/p>\n<\/p>\n<p><p>\u5728\u5f00\u53d1\u81ea\u5df1\u7684\u51fd\u6570\u5e93\u65f6\uff0c\u786e\u4fdd\u4f60\u5904\u7406\u597d\u4f9d\u8d56\u5173\u7cfb\u548c\u73af\u5883\u914d\u7f6e\u3002\u4f8b\u5982\uff0c\u5982\u679c\u4f60\u7684\u51fd\u6570\u5e93\u4f9d\u8d56\u4e8e\u5916\u90e8\u5e93\u6216\u6a21\u5757\uff0c\u786e\u4fdd\u5728\u6587\u6863\u4e2d\u660e\u786e\u8bf4\u660e\uff0c\u5e76\u5728\u9879\u76ee\u7684 <code>requirements.txt<\/code> \u6587\u4ef6\u4e2d\u5217\u51fa\u8fd9\u4e9b\u4f9d\u8d56\u9879\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-plaintext\"># requirements.txt<\/p>\n<p>numpy<\/p>\n<p>pandas<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u8fd9\u6837\uff0c\u7528\u6237\u53ef\u4ee5\u4f7f\u7528 <code>pip install -r requirements.txt<\/code> \u547d\u4ee4\u5b89\u88c5\u6240\u6709\u5fc5\u8981\u7684\u4f9d\u8d56\u9879\u3002<\/p>\n<\/p>\n<p><p>\u516d\u3001\u6a21\u5757\u91cd\u7528\u548c\u4ee3\u7801\u8d28\u91cf<\/p>\n<\/p>\n<p><p>\u4e3a\u4e86\u63d0\u9ad8\u4ee3\u7801\u7684\u91cd\u7528\u6027\u548c\u8d28\u91cf\uff0c\u8bf7\u9075\u5faa\u4e00\u4e9b\u6700\u4f73\u5b9e\u8df5\uff1a<\/p>\n<\/p>\n<ol>\n<li><strong>\u6a21\u5757\u5316\u8bbe\u8ba1<\/strong>\uff1a\u5c06\u529f\u80fd\u5212\u5206\u4e3a\u591a\u4e2a\u6a21\u5757\uff0c\u6bcf\u4e2a\u6a21\u5757\u4e13\u6ce8\u4e8e\u4e00\u4e2a\u7279\u5b9a\u7684\u4efb\u52a1\u3002<\/li>\n<li><strong>\u6587\u6863\u5316<\/strong>\uff1a\u4e3a\u4f60\u7684\u51fd\u6570\u548c\u6a21\u5757\u7f16\u5199\u6587\u6863\uff0c\u89e3\u91ca\u5b83\u4eec\u7684\u7528\u9014\u3001\u53c2\u6570\u548c\u8fd4\u56de\u503c\u3002<\/li>\n<li><strong>\u6d4b\u8bd5<\/strong>\uff1a\u7f16\u5199\u6d4b\u8bd5\u7528\u4f8b\uff0c\u786e\u4fdd\u4f60\u7684\u51fd\u6570\u5e93\u5728\u5404\u79cd\u60c5\u51b5\u4e0b\u90fd\u80fd\u6b63\u5e38\u5de5\u4f5c\u3002<\/li>\n<li><strong>\u7248\u672c\u63a7\u5236<\/strong>\uff1a\u4f7f\u7528\u7248\u672c\u63a7\u5236\u7cfb\u7edf\uff08\u5982Git\uff09\u6765\u7ba1\u7406\u4ee3\u7801\u7684\u66f4\u6539\u548c\u7248\u672c\u3002<\/li>\n<\/ol>\n<p><p>\u4e03\u3001\u53d1\u5e03\u81ea\u5df1\u7684\u51fd\u6570\u5e93<\/p>\n<\/p>\n<p><p>\u5982\u679c\u4f60\u60f3\u4e0e\u4ed6\u4eba\u5206\u4eab\u4f60\u7684\u51fd\u6570\u5e93\uff0c\u53ef\u4ee5\u5c06\u5176\u53d1\u5e03\u5230Python\u5305\u7d22\u5f15\uff08PyPI\uff09\u4e0a\u3002\u4ee5\u4e0b\u662f\u4e00\u4e2a\u7b80\u5355\u7684\u53d1\u5e03\u6d41\u7a0b\uff1a<\/p>\n<\/p>\n<ol>\n<li><strong>\u521b\u5efa <code>setup.py<\/code> \u6587\u4ef6<\/strong>\uff1a\u5728\u9879\u76ee\u6839\u76ee\u5f55\u4e2d\u521b\u5efa\u4e00\u4e2a <code>setup.py<\/code> \u6587\u4ef6\uff0c\u5305\u542b\u5305\u7684\u5143\u6570\u636e\u3002<\/li>\n<\/ol>\n<p><pre><code class=\"language-python\"># setup.py<\/p>\n<p>from setuptools import setup, find_packages<\/p>\n<p>setup(<\/p>\n<p>    name=&quot;mylib&quot;,<\/p>\n<p>    version=&quot;0.1.0&quot;,<\/p>\n<p>    packages=find_packages(),<\/p>\n<p>    install_requires=[<\/p>\n<p>        &quot;numpy&quot;,<\/p>\n<p>        &quot;pandas&quot;,<\/p>\n<p>    ],<\/p>\n<p>    author=&quot;Your Name&quot;,<\/p>\n<p>    author_email=&quot;your.email@example.com&quot;,<\/p>\n<p>    description=&quot;A simple Python function library&quot;,<\/p>\n<p>    url=&quot;https:\/\/github.com\/yourusername\/mylib&quot;,<\/p>\n<p>)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<ol start=\"2\">\n<li><strong>\u6784\u5efa\u548c\u4e0a\u4f20\u5305<\/strong>\uff1a\u4f7f\u7528 <code>twine<\/code> \u5de5\u5177\u6784\u5efa\u548c\u4e0a\u4f20\u5305\u3002<\/li>\n<\/ol>\n<p><pre><code class=\"language-sh\">$ python setup.py sdist<\/p>\n<p>$ twine upload dist\/*<\/p>\n<p><\/code><\/pre>\n<\/p>\n<ol start=\"3\">\n<li><strong>\u5b89\u88c5\u548c\u4f7f\u7528<\/strong>\uff1a\u5176\u4ed6\u7528\u6237\u53ef\u4ee5\u4f7f\u7528 <code>pip install mylib<\/code> \u547d\u4ee4\u5b89\u88c5\u4f60\u7684\u5305\u3002<\/li>\n<\/ol>\n<p><p>\u901a\u8fc7\u4ee5\u4e0a\u6b65\u9aa4\uff0c\u4f60\u53ef\u4ee5\u8f7b\u677e\u5730\u521b\u5efa\u3001\u5bfc\u5165\u548c\u53d1\u5e03\u81ea\u5df1\u7684Python\u51fd\u6570\u5e93\u3002\u65e0\u8bba\u662f\u7528\u4e8e\u4e2a\u4eba\u9879\u76ee\u8fd8\u662f\u4e0e\u4ed6\u4eba\u5206\u4eab\uff0c\u8fd9\u4e9b\u6280\u5de7\u548c\u6700\u4f73\u5b9e\u8df5\u5c06\u5e2e\u52a9\u4f60\u63d0\u9ad8\u4ee3\u7801\u7684\u7ec4\u7ec7\u6027\u548c\u53ef\u7ef4\u62a4\u6027\u3002<\/p>\n<\/p>\n<h2><strong>\u76f8\u5173\u95ee\u7b54FAQs\uff1a<\/strong><\/h2>\n<p> <strong>\u5982\u4f55\u5c06\u81ea\u5b9a\u4e49\u7684\u51fd\u6570\u5e93\u5bfc\u5165\u5230Python\u9879\u76ee\u4e2d\uff1f<\/strong><br \/>\u8981\u5c06\u81ea\u5b9a\u4e49\u7684\u51fd\u6570\u5e93\u5bfc\u5165\u5230Python\u9879\u76ee\u4e2d\uff0c\u60a8\u9700\u8981\u786e\u4fdd\u8be5\u5e93\u7684\u6587\u4ef6\uff08\u4f8b\u5982<code>mylibrary.py<\/code>\uff09\u4e0e\u60a8\u7684\u4e3b\u811a\u672c\u4f4d\u4e8e\u540c\u4e00\u76ee\u5f55\u4e0b\u3002\u7136\u540e\uff0c\u60a8\u53ef\u4ee5\u4f7f\u7528<code>import<\/code>\u8bed\u53e5\u5bfc\u5165\u5b83\u3002\u793a\u4f8b\u4ee3\u7801\u5982\u4e0b\uff1a  <\/p>\n<pre><code class=\"language-python\">import mylibrary\n<\/code><\/pre>\n<p>\u5982\u679c\u60a8\u53ea\u60f3\u5bfc\u5165\u7279\u5b9a\u7684\u51fd\u6570\uff0c\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u8bed\u6cd5\uff1a  <\/p>\n<pre><code class=\"language-python\">from mylibrary import my_function\n<\/code><\/pre>\n<p>\u786e\u4fdd\u60a8\u7684\u5e93\u6587\u4ef6\u547d\u540d\u9075\u5faaPython\u7684\u547d\u540d\u89c4\u5219\u3002<\/p>\n<p><strong>\u5982\u4f55\u5728Python\u4e2d\u521b\u5efa\u5e76\u5bfc\u5165\u591a\u4e2a\u6a21\u5757\uff1f<\/strong><br \/>\u60a8\u53ef\u4ee5\u901a\u8fc7\u5c06\u591a\u4e2a\u76f8\u5173\u51fd\u6570\u653e\u7f6e\u5728\u4e00\u4e2a\u6587\u4ef6\u4e2d\u6765\u521b\u5efa\u6a21\u5757\uff0c\u6216\u5c06\u5b83\u4eec\u5206\u6563\u5728\u591a\u4e2a\u6587\u4ef6\u4e2d\u3002\u5728\u591a\u4e2a\u6587\u4ef6\u7684\u60c5\u51b5\u4e0b\uff0c\u60a8\u53ef\u4ee5\u521b\u5efa\u4e00\u4e2a\u5305\u3002\u5728\u6bcf\u4e2a\u6a21\u5757\u7684\u76ee\u5f55\u4e2d\u521b\u5efa\u4e00\u4e2a\u540d\u4e3a<code>__init__.py<\/code>\u7684\u7a7a\u6587\u4ef6\uff0c\u7136\u540e\u901a\u8fc7\u5305\u540d\u5bfc\u5165\u6a21\u5757\u3002\u4f8b\u5982\uff1a  <\/p>\n<pre><code class=\"language-python\">import mypackage.mymodule\n<\/code><\/pre>\n<p>\u8fd9\u6837\u53ef\u4ee5\u66f4\u597d\u5730\u7ec4\u7ec7\u4ee3\u7801\uff0c\u7279\u522b\u662f\u5f53\u9879\u76ee\u53d8\u5f97\u590d\u6742\u65f6\u3002<\/p>\n<p><strong>\u5982\u4f55\u5904\u7406\u5bfc\u5165\u65f6\u9047\u5230\u7684\u9519\u8bef\uff1f<\/strong><br \/>\u5728\u5bfc\u5165\u81ea\u5b9a\u4e49\u51fd\u6570\u5e93\u65f6\uff0c\u60a8\u53ef\u80fd\u4f1a\u9047\u5230<code>ModuleNotFoundError<\/code>\u6216<code>ImportError<\/code>\u3002\u8fd9\u4e9b\u9519\u8bef\u901a\u5e38\u662f\u56e0\u4e3a\u5e93\u6587\u4ef6\u672a\u5728Python\u7684\u641c\u7d22\u8def\u5f84\u4e2d\u3002\u786e\u4fdd\u60a8\u7684\u6587\u4ef6\u8def\u5f84\u6b63\u786e\uff0c\u6216\u8005\u4f7f\u7528<code>sys.path.append(&#39;\/path\/to\/your\/library&#39;)<\/code>\u5c06\u5e93\u8def\u5f84\u6dfb\u52a0\u5230Python\u7684\u641c\u7d22\u8def\u5f84\u4e2d\u3002\u6b64\u5916\uff0c\u68c0\u67e5\u5e93\u6587\u4ef6\u662f\u5426\u5b58\u5728\u8bed\u6cd5\u9519\u8bef\uff0c\u6216\u786e\u4fdd\u6ca1\u6709\u547d\u540d\u51b2\u7a81\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"\u8981\u5bfc\u5165\u81ea\u5df1\u7684\u51fd\u6570\u5e93\uff0c\u4f60\u53ef\u4ee5\u521b\u5efa\u4e00\u4e2a\u5305\u542b\u51fd\u6570\u7684Python\u6587\u4ef6\uff0c\u5e76\u5c06\u5176\u4f5c\u4e3a\u6a21\u5757\u5bfc\u5165\u5230\u5176\u4ed6Python\u811a\u672c\u4e2d\u3002 \u9996 [&hellip;]","protected":false},"author":3,"featured_media":1030988,"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\/1030977"}],"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=1030977"}],"version-history":[{"count":"1","href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1030977\/revisions"}],"predecessor-version":[{"id":1030992,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1030977\/revisions\/1030992"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media\/1030988"}],"wp:attachment":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media?parent=1030977"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/categories?post=1030977"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/tags?post=1030977"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}