{"id":998108,"date":"2024-12-27T09:29:59","date_gmt":"2024-12-27T01:29:59","guid":{"rendered":"https:\/\/docs.pingcode.com\/ask\/ask-ask\/998108.html"},"modified":"2024-12-27T09:30:02","modified_gmt":"2024-12-27T01:30:02","slug":"%e5%a6%82%e4%bd%95%e5%af%b9python%e9%85%8d%e7%bd%ae%e8%b7%af%e5%be%84","status":"publish","type":"post","link":"https:\/\/docs.pingcode.com\/ask\/998108.html","title":{"rendered":"\u5982\u4f55\u5bf9python\u914d\u7f6e\u8def\u5f84"},"content":{"rendered":"<p style=\"text-align:center;\" ><img decoding=\"async\" src=\"https:\/\/cdn-kb.worktile.com\/kb\/wp-content\/uploads\/2024\/04\/25073640\/f4721021-62f8-4f7f-803b-e5524dba9c85.webp\" alt=\"\u5982\u4f55\u5bf9python\u914d\u7f6e\u8def\u5f84\" \/><\/p>\n<p><p> <strong>\u8981\u5bf9Python\u914d\u7f6e\u8def\u5f84\uff0c\u4f60\u53ef\u4ee5\u901a\u8fc7\u4fee\u6539\u73af\u5883\u53d8\u91cf\u3001\u4f7f\u7528virtualenv\u3001\u8c03\u6574sys.path\u7b49\u65b9\u6cd5\u5b9e\u73b0\u3002\u4fee\u6539\u73af\u5883\u53d8\u91cf\u53ef\u4ee5\u8ba9Python\u5168\u5c40\u53ef\u7528\u3001\u4f7f\u7528virtualenv\u80fd\u4e3a\u4e0d\u540c\u9879\u76ee\u521b\u5efa\u72ec\u7acb\u7684\u73af\u5883\u3001\u8c03\u6574sys.path\u53ef\u4ee5\u5728\u8fd0\u884c\u65f6\u52a8\u6001\u4fee\u6539\u8def\u5f84\u3002<\/strong> <\/p>\n<\/p>\n<p><p>\u4fee\u6539\u73af\u5883\u53d8\u91cf\u662f\u6700\u5e38\u89c1\u7684\u65b9\u6cd5\u4e4b\u4e00\u3002\u901a\u8fc7\u8bbe\u7f6e\u7cfb\u7edf\u7684PATH\u53d8\u91cf\uff0c\u4f60\u53ef\u4ee5\u8ba9Python\u53ef\u6267\u884c\u6587\u4ef6\u5728\u547d\u4ee4\u884c\u4e2d\u5168\u5c40\u53ef\u7528\u3002\u5177\u4f53\u64cd\u4f5c\u6b65\u9aa4\u56e0\u64cd\u4f5c\u7cfb\u7edf\u4e0d\u540c\u800c\u6709\u6240\u5dee\u5f02\u3002\u5728Windows\u4e0a\uff0c\u4f60\u53ef\u4ee5\u901a\u8fc7\u201c\u7cfb\u7edf\u5c5e\u6027\u201d\u4e2d\u7684\u201c\u73af\u5883\u53d8\u91cf\u201d\u9009\u9879\u6765\u4fee\u6539\uff1b\u5728macOS\u548cLinux\u4e0a\uff0c\u4f60\u9700\u8981\u7f16\u8f91<code>.bashrc<\/code>\u6216<code>.bash_profile<\/code>\u6587\u4ef6\u3002\u5728\u8fd9\u4e9b\u6587\u4ef6\u4e2d\u6dfb\u52a0Python\u7684\u5b89\u88c5\u8def\u5f84\uff0c\u53ef\u4ee5\u786e\u4fddPython\u5728\u7ec8\u7aef\u4e2d\u968f\u65f6\u53ef\u7528\u3002<\/p>\n<\/p>\n<p><p>\u4e00\u3001\u4fee\u6539\u73af\u5883\u53d8\u91cf<\/p>\n<\/p>\n<p><p>\u4fee\u6539\u73af\u5883\u53d8\u91cf\u662f\u8ba9Python\u5728\u547d\u4ee4\u884c\u4e2d\u53ef\u7528\u7684\u6700\u76f4\u63a5\u65b9\u6cd5\u3002\u65e0\u8bba\u4f60\u4f7f\u7528\u7684\u662fWindows\u3001macOS\u8fd8\u662fLinux\uff0c\u73af\u5883\u53d8\u91cf\u7684\u8bbe\u7f6e\u65b9\u5f0f\u7565\u6709\u4e0d\u540c\uff0c\u4f46\u539f\u7406\u76f8\u540c\u3002<\/p>\n<\/p>\n<ol>\n<li><strong>Windows\u7cfb\u7edf\u4e0b\u7684\u914d\u7f6e<\/strong><\/li>\n<\/ol>\n<p><p>\u5728Windows\u7cfb\u7edf\u4e2d\uff0c\u4f60\u9700\u8981\u901a\u8fc7\u7cfb\u7edf\u5c5e\u6027\u6765\u4fee\u6539\u73af\u5883\u53d8\u91cf\u3002\u5177\u4f53\u6b65\u9aa4\u5982\u4e0b\uff1a<\/p>\n<\/p>\n<ul>\n<li>\u53f3\u952e\u70b9\u51fb\u201c\u6b64\u7535\u8111\u201d\u6216\u201c\u6211\u7684\u7535\u8111\u201d\uff0c\u9009\u62e9\u201c\u5c5e\u6027\u201d\u3002<\/li>\n<li>\u70b9\u51fb\u201c\u9ad8\u7ea7\u7cfb\u7edf\u8bbe\u7f6e\u201d\u3002<\/li>\n<li>\u5728\u201c\u7cfb\u7edf\u5c5e\u6027\u201d\u7a97\u53e3\u4e2d\uff0c\u70b9\u51fb\u201c\u73af\u5883\u53d8\u91cf\u201d\u3002<\/li>\n<li>\u5728\u201c\u7cfb\u7edf\u53d8\u91cf\u201d\u90e8\u5206\uff0c\u627e\u5230\u5e76\u9009\u62e9\u201cPath\u201d\u53d8\u91cf\uff0c\u7136\u540e\u70b9\u51fb\u201c\u7f16\u8f91\u201d\u3002<\/li>\n<li>\u5728\u201c\u7f16\u8f91\u73af\u5883\u53d8\u91cf\u201d\u7a97\u53e3\u4e2d\uff0c\u70b9\u51fb\u201c\u65b0\u5efa\u201d\uff0c\u5e76\u8f93\u5165Python\u7684\u5b89\u88c5\u8def\u5f84\u3002\u4f8b\u5982\uff1a<code>C:\\Python39<\/code>\u3002<\/li>\n<li>\u70b9\u51fb\u201c\u786e\u5b9a\u201d\u4fdd\u5b58\u66f4\u6539\u3002<\/li>\n<\/ul>\n<p><p>\u901a\u8fc7\u8fd9\u79cd\u65b9\u5f0f\uff0c\u4f60\u53ef\u4ee5\u5728\u547d\u4ee4\u884c\u4e2d\u968f\u65f6\u8fd0\u884cPython\u547d\u4ee4\u3002<\/p>\n<\/p>\n<ol start=\"2\">\n<li><strong>macOS\u548cLinux\u7cfb\u7edf\u4e0b\u7684\u914d\u7f6e<\/strong><\/li>\n<\/ol>\n<p><p>\u5728macOS\u548cLinux\u7cfb\u7edf\u4e2d\uff0c\u4f60\u9700\u8981\u901a\u8fc7\u7f16\u8f91\u7ec8\u7aef\u914d\u7f6e\u6587\u4ef6\u6765\u8bbe\u7f6e\u73af\u5883\u53d8\u91cf\u3002\u5e38\u89c1\u7684\u914d\u7f6e\u6587\u4ef6\u5305\u62ec<code>.bashrc<\/code>\u3001<code>.bash_profile<\/code>\u3001<code>.zshrc<\/code>\u7b49\u3002\u5177\u4f53\u6b65\u9aa4\u5982\u4e0b\uff1a<\/p>\n<\/p>\n<ul>\n<li>\u6253\u5f00\u7ec8\u7aef\u5e94\u7528\u7a0b\u5e8f\u3002<\/li>\n<li>\u4f7f\u7528\u6587\u672c\u7f16\u8f91\u5668\u6253\u5f00\u4f60\u7684\u914d\u7f6e\u6587\u4ef6\u3002\u4f8b\u5982\uff1a<code>nano ~\/.bash_profile<\/code>\u3002<\/li>\n<li>\u5728\u6587\u4ef6\u672b\u5c3e\u6dfb\u52a0\u4ee5\u4e0b\u884c\uff1a<code>export PATH=&quot;\/usr\/local\/bin\/python3:$PATH&quot;<\/code>\u3002\u786e\u4fdd\u66ff\u6362<code>\/usr\/local\/bin\/python3<\/code>\u4e3a\u4f60\u7684Python\u5b89\u88c5\u8def\u5f84\u3002<\/li>\n<li>\u4fdd\u5b58\u6587\u4ef6\u5e76\u9000\u51fa\u7f16\u8f91\u5668\u3002<\/li>\n<li>\u8fd0\u884c<code>source ~\/.bash_profile<\/code>\u547d\u4ee4\uff0c\u4f7f\u66f4\u6539\u751f\u6548\u3002<\/li>\n<\/ul>\n<p><p>\u901a\u8fc7\u8fd9\u79cd\u65b9\u5f0f\uff0cPython\u547d\u4ee4\u5c06\u5728\u7ec8\u7aef\u4e2d\u968f\u65f6\u53ef\u7528\u3002<\/p>\n<\/p>\n<p><p>\u4e8c\u3001\u4f7f\u7528Virtualenv<\/p>\n<\/p>\n<p><p><strong>Virtualenv<\/strong>\u662fPython\u7684\u4e00\u4e2a\u5de5\u5177\uff0c\u7528\u4e8e\u521b\u5efa\u72ec\u7acb\u7684Python\u73af\u5883\u3002\u5b83\u5141\u8bb8\u4f60\u4e3a\u6bcf\u4e2a\u9879\u76ee\u521b\u5efa\u9694\u79bb\u7684\u73af\u5883\uff0c\u907f\u514d\u4e0d\u540c\u9879\u76ee\u4e4b\u95f4\u7684\u4f9d\u8d56\u51b2\u7a81\u3002<\/p>\n<\/p>\n<ol>\n<li><strong>\u5b89\u88c5Virtualenv<\/strong><\/li>\n<\/ol>\n<p><p>\u9996\u5148\uff0c\u4f60\u9700\u8981\u786e\u4fdd\u5df2\u7ecf\u5b89\u88c5\u4e86Virtualenv\u3002\u4f60\u53ef\u4ee5\u901a\u8fc7\u4ee5\u4e0b\u547d\u4ee4\u5b89\u88c5\u5b83\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">pip install virtualenv<\/p>\n<p><\/code><\/pre>\n<\/p>\n<ol start=\"2\">\n<li><strong>\u521b\u5efaVirtualenv\u73af\u5883<\/strong><\/li>\n<\/ol>\n<p><p>\u5728\u9879\u76ee\u76ee\u5f55\u4e0b\uff0c\u8fd0\u884c\u4ee5\u4e0b\u547d\u4ee4\u521b\u5efa\u4e00\u4e2a\u65b0\u7684\u865a\u62df\u73af\u5883\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">virtualenv venv<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u8fd9\u5c06\u5728\u9879\u76ee\u76ee\u5f55\u4e2d\u521b\u5efa\u4e00\u4e2a\u540d\u4e3a<code>venv<\/code>\u7684\u6587\u4ef6\u5939\uff0c\u5176\u4e2d\u5305\u542b\u72ec\u7acb\u7684Python\u73af\u5883\u3002<\/p>\n<\/p>\n<ol start=\"3\">\n<li><strong>\u6fc0\u6d3bVirtualenv\u73af\u5883<\/strong><\/li>\n<\/ol>\n<p><p>\u5728\u521b\u5efa\u865a\u62df\u73af\u5883\u4e4b\u540e\uff0c\u4f60\u9700\u8981\u6fc0\u6d3b\u5b83\u3002\u6fc0\u6d3b\u540e\uff0c\u6240\u6709\u7684Python\u547d\u4ee4\u548c\u5305\u5b89\u88c5\u90fd\u5c06\u5728\u8fd9\u4e2a\u73af\u5883\u4e2d\u8fd0\u884c\u3002<\/p>\n<\/p>\n<ul>\n<li>\u5728Windows\u4e0a\uff1a<\/li>\n<\/ul>\n<p><pre><code class=\"language-bash\">venv\\Scripts\\activate<\/p>\n<p><\/code><\/pre>\n<\/p>\n<ul>\n<li>\u5728macOS\u548cLinux\u4e0a\uff1a<\/li>\n<\/ul>\n<p><pre><code class=\"language-bash\">source venv\/bin\/activate<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u6fc0\u6d3b\u6210\u529f\u540e\uff0c\u4f60\u7684\u547d\u4ee4\u63d0\u793a\u7b26\u4f1a\u663e\u793a\u865a\u62df\u73af\u5883\u7684\u540d\u79f0\u3002<\/p>\n<\/p>\n<ol start=\"4\">\n<li><strong>\u4f7f\u7528\u548c\u9000\u51faVirtualenv\u73af\u5883<\/strong><\/li>\n<\/ol>\n<p><p>\u5728\u6fc0\u6d3b\u7684\u73af\u5883\u4e2d\uff0c\u4f60\u53ef\u4ee5\u6b63\u5e38\u5b89\u88c5\u548c\u4f7f\u7528Python\u5305\uff0c\u6240\u6709\u7684\u5305\u90fd\u4f1a\u5b89\u88c5\u5728<code>venv<\/code>\u76ee\u5f55\u4e0b\u3002\u8981\u9000\u51fa\u865a\u62df\u73af\u5883\uff0c\u53ea\u9700\u8fd0\u884c\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">deactivate<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u4e09\u3001\u8c03\u6574sys.path<\/p>\n<\/p>\n<p><p><strong>sys.path<\/strong>\u662f\u4e00\u4e2aPython\u5217\u8868\uff0c\u5305\u542b\u4e86Python\u89e3\u91ca\u5668\u4f1a\u641c\u7d22\u6a21\u5757\u7684\u8def\u5f84\u3002\u901a\u8fc7\u4fee\u6539sys.path\uff0c\u4f60\u53ef\u4ee5\u5728\u8fd0\u884c\u65f6\u52a8\u6001\u8c03\u6574\u6a21\u5757\u641c\u7d22\u8def\u5f84\u3002<\/p>\n<\/p>\n<ol>\n<li><strong>\u5728\u4ee3\u7801\u4e2d\u4fee\u6539sys.path<\/strong><\/li>\n<\/ol>\n<p><p>\u4f60\u53ef\u4ee5\u5728Python\u4ee3\u7801\u4e2d\u76f4\u63a5\u4fee\u6539sys.path\uff0c\u4ee5\u6dfb\u52a0\u65b0\u7684\u6a21\u5757\u641c\u7d22\u8def\u5f84\u3002\u4f8b\u5982\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import sys<\/p>\n<p>sys.path.append(&#39;\/path\/to\/your\/module&#39;)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u901a\u8fc7\u8fd9\u79cd\u65b9\u5f0f\uff0c\u4f60\u53ef\u4ee5\u5728\u4ee3\u7801\u8fd0\u884c\u65f6\u52a8\u6001\u6307\u5b9a\u6a21\u5757\u8def\u5f84\uff0c\u800c\u4e0d\u9700\u8981\u4fee\u6539\u73af\u5883\u53d8\u91cf\u6216\u4f7f\u7528\u865a\u62df\u73af\u5883\u3002<\/p>\n<\/p>\n<ol start=\"2\">\n<li><strong>\u6c38\u4e45\u4fee\u6539sys.path<\/strong><\/li>\n<\/ol>\n<p><p>\u5982\u679c\u4f60\u5e0c\u671b\u6c38\u4e45\u6027\u5730\u4fee\u6539sys.path\uff0c\u53ef\u4ee5\u5728Python\u7684<code>site-packages<\/code>\u76ee\u5f55\u4e0b\u521b\u5efa\u4e00\u4e2a.pth\u6587\u4ef6\u3002\u5728\u8fd9\u4e2a\u6587\u4ef6\u4e2d\uff0c\u6dfb\u52a0\u4f60\u5e0c\u671b\u5305\u542b\u7684\u8def\u5f84\u3002\u6bcf\u884c\u4e00\u4e2a\u8def\u5f84\u3002\u4f8b\u5982\uff1a<\/p>\n<\/p>\n<p><p>\u521b\u5efa\u4e00\u4e2a\u540d\u4e3a<code>my_module.pth<\/code>\u7684\u6587\u4ef6\uff0c\u5e76\u6dfb\u52a0\u4ee5\u4e0b\u5185\u5bb9\uff1a<\/p>\n<\/p>\n<p><pre><code>\/path\/to\/your\/module<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u8fd9\u6837\uff0cPython\u89e3\u91ca\u5668\u5728\u542f\u52a8\u65f6\u4f1a\u81ea\u52a8\u8bfb\u53d6.pth\u6587\u4ef6\uff0c\u5e76\u5c06\u5176\u4e2d\u7684\u8def\u5f84\u6dfb\u52a0\u5230sys.path\u4e2d\u3002<\/p>\n<\/p>\n<p><p>\u56db\u3001\u4f7f\u7528Python\u542f\u52a8\u53c2\u6570<\/p>\n<\/p>\n<p><p>Python\u89e3\u91ca\u5668\u652f\u6301\u901a\u8fc7\u542f\u52a8\u53c2\u6570\u6765\u4e34\u65f6\u8c03\u6574\u6a21\u5757\u8def\u5f84\u3002\u4f60\u53ef\u4ee5\u4f7f\u7528<code>-m<\/code>\u53c2\u6570\u6307\u5b9a\u6a21\u5757\u8def\u5f84\u3002<\/p>\n<\/p>\n<ol>\n<li><strong>\u4f7f\u7528-m\u53c2\u6570<\/strong><\/li>\n<\/ol>\n<p><p>\u5728\u547d\u4ee4\u884c\u4e2d\u8fd0\u884cPython\u811a\u672c\u65f6\uff0c\u4f60\u53ef\u4ee5\u4f7f\u7528<code>-m<\/code>\u53c2\u6570\u6307\u5b9a\u6a21\u5757\u8def\u5f84\u3002\u4f8b\u5982\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">python -m \/path\/to\/your\/module your_script.py<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u8fd9\u79cd\u65b9\u6cd5\u9002\u7528\u4e8e\u4e34\u65f6\u8c03\u6574\u6a21\u5757\u8def\u5f84\uff0c\u9002\u5408\u5728\u4e0d\u65b9\u4fbf\u4fee\u6539\u73af\u5883\u53d8\u91cf\u6216sys.path\u7684\u60c5\u51b5\u4e0b\u4f7f\u7528\u3002<\/p>\n<\/p>\n<p><p>\u4e94\u3001\u603b\u7ed3<\/p>\n<\/p>\n<p><p>\u5728Python\u4e2d\u914d\u7f6e\u8def\u5f84\u662f\u4e00\u4e2a\u5e38\u89c1\u4e14\u91cd\u8981\u7684\u4efb\u52a1\u3002\u901a\u8fc7\u4fee\u6539\u73af\u5883\u53d8\u91cf\u3001\u4f7f\u7528Virtualenv\u3001\u8c03\u6574sys.path\u3001\u4ee5\u53ca\u4f7f\u7528Python\u542f\u52a8\u53c2\u6570\uff0c\u4f60\u53ef\u4ee5\u7075\u6d3b\u5730\u7ba1\u7406Python\u7684\u6a21\u5757\u641c\u7d22\u8def\u5f84\u3002\u6bcf\u79cd\u65b9\u6cd5\u90fd\u6709\u5176\u9002\u7528\u7684\u573a\u666f\u548c\u4f18\u7f3a\u70b9\uff0c\u6839\u636e\u4f60\u7684\u5177\u4f53\u9700\u6c42\u9009\u62e9\u5408\u9002\u7684\u65b9\u6cd5\uff0c\u53ef\u4ee5\u6709\u6548\u63d0\u9ad8\u5f00\u53d1\u6548\u7387\u548c\u9879\u76ee\u7684\u53ef\u7ef4\u62a4\u6027\u3002\u65e0\u8bba\u662f\u5168\u5c40\u7684\u8def\u5f84\u8bbe\u7f6e\u8fd8\u662f\u9879\u76ee\u7ea7\u7684\u73af\u5883\u7ba1\u7406\uff0c\u638c\u63e1\u8fd9\u4e9b\u6280\u5de7\u5c06\u4f7f\u4f60\u5728Python\u5f00\u53d1\u8fc7\u7a0b\u4e2d\u66f4\u52a0\u5f97\u5fc3\u5e94\u624b\u3002<\/p>\n<\/p>\n<h2><strong>\u76f8\u5173\u95ee\u7b54FAQs\uff1a<\/strong><\/h2>\n<p> <strong>\u5982\u4f55\u5728Python\u4e2d\u8bbe\u7f6e\u73af\u5883\u53d8\u91cf\u4ee5\u914d\u7f6e\u8def\u5f84\uff1f<\/strong><br \/>\u5728Python\u4e2d\uff0c\u53ef\u4ee5\u901a\u8fc7\u8bbe\u7f6e\u73af\u5883\u53d8\u91cf\u6765\u914d\u7f6e\u6a21\u5757\u641c\u7d22\u8def\u5f84\u3002\u4f7f\u7528<code>os<\/code>\u6a21\u5757\u4e2d\u7684<code>environ<\/code>\u5b57\u5178\uff0c\u53ef\u4ee5\u6dfb\u52a0\u6216\u4fee\u6539<code>PYTHONPATH<\/code>\u73af\u5883\u53d8\u91cf\u3002\u8fd9\u4f7f\u5f97Python\u80fd\u591f\u627e\u5230\u81ea\u5b9a\u4e49\u6a21\u5757\u548c\u5305\u3002\u60a8\u53ef\u4ee5\u5728\u811a\u672c\u5f00\u59cb\u5904\u6dfb\u52a0\u5982\u4e0b\u4ee3\u7801\uff1a  <\/p>\n<pre><code class=\"language-python\">import os\nimport sys\nos.environ[&#39;PYTHONPATH&#39;] = &#39;\/your\/custom\/path&#39;\nsys.path.append(&#39;\/your\/custom\/path&#39;)\n<\/code><\/pre>\n<p>\u8fd9\u6837\uff0cPython\u4f1a\u5728\u6307\u5b9a\u8def\u5f84\u4e2d\u67e5\u627e\u6a21\u5757\u3002<\/p>\n<p><strong>\u5982\u4f55\u5728Windows\u548cLinux\u4e2d\u8bbe\u7f6ePython\u8def\u5f84\uff1f<\/strong><br \/>\u5728Windows\u7cfb\u7edf\u4e2d\uff0c\u53ef\u4ee5\u901a\u8fc7\u201c\u7cfb\u7edf\u5c5e\u6027\u201d\u4e2d\u7684\u201c\u73af\u5883\u53d8\u91cf\u201d\u8bbe\u7f6e<code>PYTHONPATH<\/code>\u3002\u5728Linux\u7cfb\u7edf\u4e2d\uff0c\u53ef\u4ee5\u5728\u7528\u6237\u7684<code>.bashrc<\/code>\u6216<code>.bash_profile<\/code>\u6587\u4ef6\u4e2d\u6dfb\u52a0<code>export PYTHONPATH=\/your\/custom\/path<\/code>\u3002\u914d\u7f6e\u5b8c\u6210\u540e\uff0c\u91cd\u65b0\u542f\u52a8\u7ec8\u7aef\u6216\u4f7f\u7528<code>source ~\/.bashrc<\/code>\u547d\u4ee4\u4f7f\u66f4\u6539\u751f\u6548\u3002<\/p>\n<p><strong>\u5982\u4f55\u9a8c\u8bc1Python\u8def\u5f84\u7684\u914d\u7f6e\u662f\u5426\u6210\u529f\uff1f<\/strong><br \/>\u53ef\u4ee5\u901a\u8fc7Python\u7684\u5185\u7f6e<code>sys<\/code>\u6a21\u5757\u6765\u9a8c\u8bc1\u8def\u5f84\u914d\u7f6e\u662f\u5426\u6210\u529f\u3002\u5728Python\u4ea4\u4e92\u5f0f\u73af\u5883\u6216\u811a\u672c\u4e2d\u8fd0\u884c\u4ee5\u4e0b\u4ee3\u7801\uff1a  <\/p>\n<pre><code class=\"language-python\">import sys\nprint(sys.path)\n<\/code><\/pre>\n<p>\u8fd9\u5c06\u8f93\u51fa\u5f53\u524d\u7684\u6a21\u5757\u641c\u7d22\u8def\u5f84\u5217\u8868\u3002\u68c0\u67e5\u8f93\u51fa\u4e2d\u662f\u5426\u5305\u542b\u60a8\u6240\u6dfb\u52a0\u7684\u8def\u5f84\u3002\u5982\u679c\u8def\u5f84\u5728\u5217\u8868\u4e2d\uff0c\u8bf4\u660e\u914d\u7f6e\u6210\u529f\uff0c\u53ef\u4ee5\u5f00\u59cb\u4f7f\u7528\u81ea\u5b9a\u4e49\u6a21\u5757\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"\u8981\u5bf9Python\u914d\u7f6e\u8def\u5f84\uff0c\u4f60\u53ef\u4ee5\u901a\u8fc7\u4fee\u6539\u73af\u5883\u53d8\u91cf\u3001\u4f7f\u7528virtualenv\u3001\u8c03\u6574sys.path\u7b49\u65b9\u6cd5\u5b9e\u73b0\u3002\u4fee [&hellip;]","protected":false},"author":3,"featured_media":998120,"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\/998108"}],"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=998108"}],"version-history":[{"count":"1","href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/998108\/revisions"}],"predecessor-version":[{"id":998124,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/998108\/revisions\/998124"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media\/998120"}],"wp:attachment":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media?parent=998108"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/categories?post=998108"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/tags?post=998108"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}