{"id":1065225,"date":"2024-12-31T16:15:48","date_gmt":"2024-12-31T08:15:48","guid":{"rendered":"https:\/\/docs.pingcode.com\/ask\/ask-ask\/1065225.html"},"modified":"2024-12-31T16:15:50","modified_gmt":"2024-12-31T08:15:50","slug":"%e5%a6%82%e4%bd%95%e5%9c%a8%e5%91%bd%e4%bb%a4%e8%a1%8c%e4%b8%8b%e8%bf%90%e8%a1%8cpython","status":"publish","type":"post","link":"https:\/\/docs.pingcode.com\/ask\/ask-ask\/1065225.html","title":{"rendered":"\u5982\u4f55\u5728\u547d\u4ee4\u884c\u4e0b\u8fd0\u884cpython"},"content":{"rendered":"<p style=\"text-align:center;\" ><img decoding=\"async\" src=\"https:\/\/cdn-docs.pingcode.com\/wp-content\/uploads\/2024\/12\/168cb6ea-e1e7-4b64-88ce-361dc61092c8.webp?x-oss-process=image\/auto-orient,1\/format,webp\" alt=\"\u5982\u4f55\u5728\u547d\u4ee4\u884c\u4e0b\u8fd0\u884cpython\" \/><\/p>\n<p><p> \u5728\u547d\u4ee4\u884c\u4e0b\u8fd0\u884c Python \u7684\u65b9\u6cd5\u5305\u62ec\u5b89\u88c5 Python \u73af\u5883\u3001\u4f7f\u7528\u547d\u4ee4\u884c\u754c\u9762\u3001\u7f16\u5199\u548c\u6267\u884c Python \u811a\u672c\u7b49\u3002<strong>\u5b89\u88c5 Python \u73af\u5883\u3001\u4f7f\u7528\u547d\u4ee4\u884c\u754c\u9762\u3001\u7f16\u5199\u548c\u6267\u884c Python \u811a\u672c\u3001\u8c03\u8bd5\u548c\u4f18\u5316\u4ee3\u7801<\/strong>\u3002\u63a5\u4e0b\u6765\uff0c\u6211\u5c06\u8be6\u7ec6\u5c55\u5f00\u5176\u4e2d\u7684<strong>\u5b89\u88c5 Python \u73af\u5883<\/strong>\u8fd9\u4e00\u70b9\u3002<\/p>\n<\/p>\n<p><p><strong>\u5b89\u88c5 Python \u73af\u5883<\/strong>\u662f\u4f60\u5728\u547d\u4ee4\u884c\u4e0b\u8fd0\u884c Python \u7684\u7b2c\u4e00\u6b65\u3002\u65e0\u8bba\u4f60\u4f7f\u7528\u7684\u662f Windows\u3001macOS \u8fd8\u662f Linux \u7cfb\u7edf\uff0c\u90fd\u9700\u8981\u5728\u4f60\u7684\u8ba1\u7b97\u673a\u4e0a\u5b89\u88c5 Python \u89e3\u91ca\u5668\u3002Python \u89e3\u91ca\u5668\u53ef\u4ee5\u4ece Python \u5b98\u65b9\u7f51\u7ad9\u4e0b\u8f7d\uff0c\u4e0b\u8f7d\u5b8c\u6210\u540e\uff0c\u6839\u636e\u64cd\u4f5c\u7cfb\u7edf\u7684\u4e0d\u540c\uff0c\u6309\u6b65\u9aa4\u5b89\u88c5\u5373\u53ef\u3002\u5b89\u88c5\u5b8c\u6210\u540e\uff0c\u53ef\u4ee5\u901a\u8fc7\u547d\u4ee4 <code>python --version<\/code> \u6216 <code>python3 --version<\/code> \u6765\u9a8c\u8bc1\u662f\u5426\u6b63\u786e\u5b89\u88c5\u4e86 Python\u3002<\/p>\n<\/p>\n<p><p>\u4e00\u3001\u5b89\u88c5 Python \u73af\u5883<\/p>\n<\/p>\n<p><p>\u5728\u547d\u4ee4\u884c\u4e0b\u8fd0\u884c Python \u7684\u7b2c\u4e00\u6b65\u662f\u786e\u4fdd\u5df2\u7ecf\u5728\u7cfb\u7edf\u4e2d\u5b89\u88c5\u4e86 Python \u73af\u5883\u3002\u5982\u679c\u4f60\u8fd8\u6ca1\u6709\u5b89\u88c5 Python\uff0c\u53ef\u4ee5\u4ece Python \u5b98\u65b9\u7f51\u7ad9\u4e0b\u8f7d\u5e76\u5b89\u88c5\u9002\u5408\u4f60\u64cd\u4f5c\u7cfb\u7edf\u7684\u7248\u672c\u3002Windows\u3001macOS \u548c\u5927\u591a\u6570 Linux \u53d1\u884c\u7248\u90fd\u63d0\u4f9b\u4e86\u5bf9\u5e94\u7684\u5b89\u88c5\u5305\u3002\u5b89\u88c5\u5b8c\u6210\u540e\uff0c\u4f7f\u7528\u547d\u4ee4 <code>python --version<\/code> \u6216 <code>python3 --version<\/code> \u6765\u9a8c\u8bc1\u5b89\u88c5\u662f\u5426\u6210\u529f\u3002<\/p>\n<\/p>\n<ol>\n<li><strong>Windows \u7cfb\u7edf\uff1a<\/strong><\/li>\n<\/ol>\n<p><p>\u5728 Windows \u7cfb\u7edf\u4e2d\uff0c\u5b89\u88c5 Python \u7684\u8fc7\u7a0b\u76f8\u5bf9\u7b80\u5355\u3002\u9996\u5148\uff0c\u4ece Python \u5b98\u65b9\u7f51\u7ad9\u4e0b\u8f7d Windows \u5b89\u88c5\u5305\u3002\u8fd0\u884c\u5b89\u88c5\u5305\u65f6\uff0c\u786e\u4fdd\u52fe\u9009\u201cAdd Python to PATH\u201d\u9009\u9879\uff0c\u8fd9\u5c06\u81ea\u52a8\u5c06 Python \u6dfb\u52a0\u5230\u7cfb\u7edf\u7684\u73af\u5883\u53d8\u91cf\u4e2d\u3002\u5b89\u88c5\u5b8c\u6210\u540e\uff0c\u4f60\u53ef\u4ee5\u901a\u8fc7\u6253\u5f00\u547d\u4ee4\u63d0\u793a\u7b26\uff08cmd\uff09\u5e76\u8f93\u5165 <code>python --version<\/code> \u6765\u9a8c\u8bc1\u5b89\u88c5\u662f\u5426\u6210\u529f\u3002<\/p>\n<\/p>\n<ol start=\"2\">\n<li><strong>macOS \u7cfb\u7edf\uff1a<\/strong><\/li>\n<\/ol>\n<p><p>macOS \u7cfb\u7edf\u901a\u5e38\u9884\u88c5\u4e86 Python 2.x \u7248\u672c\uff0c\u4f46\u4e3a\u4e86\u4f7f\u7528\u6700\u65b0\u7684 Python \u7279\u6027\uff0c\u5efa\u8bae\u5b89\u88c5 Python 3.x \u7248\u672c\u3002\u53ef\u4ee5\u4ece Python \u5b98\u65b9\u7f51\u7ad9\u4e0b\u8f7d macOS \u5b89\u88c5\u5305\uff0c\u8fd0\u884c\u5b89\u88c5\u5305\u5e76\u6309\u7167\u63d0\u793a\u5b8c\u6210\u5b89\u88c5\u3002\u5b89\u88c5\u5b8c\u6210\u540e\uff0c\u53ef\u4ee5\u901a\u8fc7\u7ec8\u7aef\u8f93\u5165 <code>python3 --version<\/code> \u6765\u9a8c\u8bc1\u5b89\u88c5\u662f\u5426\u6210\u529f\u3002<\/p>\n<\/p>\n<ol start=\"3\">\n<li><strong>Linux \u7cfb\u7edf\uff1a<\/strong><\/li>\n<\/ol>\n<p><p>\u5927\u591a\u6570 Linux \u53d1\u884c\u7248\u90fd\u9884\u88c5\u4e86 Python\uff0c\u4f46\u5982\u679c\u9700\u8981\u5b89\u88c5\u6216\u5347\u7ea7\u5230\u6700\u65b0\u7248\u672c\uff0c\u53ef\u4ee5\u4f7f\u7528\u5305\u7ba1\u7406\u5668\u3002\u4f8b\u5982\uff0c\u5728 Ubuntu \u7cfb\u7edf\u4e2d\uff0c\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u5b89\u88c5 Python 3\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">sudo apt update<\/p>\n<p>sudo apt install python3<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5b89\u88c5\u5b8c\u6210\u540e\uff0c\u53ef\u4ee5\u901a\u8fc7\u7ec8\u7aef\u8f93\u5165 <code>python3 --version<\/code> \u6765\u9a8c\u8bc1\u5b89\u88c5\u662f\u5426\u6210\u529f\u3002<\/p>\n<\/p>\n<p><p>\u4e8c\u3001\u4f7f\u7528\u547d\u4ee4\u884c\u754c\u9762<\/p>\n<\/p>\n<p><p>\u5b89\u88c5\u5b8c\u6210 Python \u73af\u5883\u540e\uff0c\u4f60\u53ef\u4ee5\u4f7f\u7528\u547d\u4ee4\u884c\u754c\u9762\u8fd0\u884c Python\u3002\u547d\u4ee4\u884c\u754c\u9762\u662f\u4e00\u4e2a\u6587\u672c\u754c\u9762\uff0c\u5141\u8bb8\u4f60\u76f4\u63a5\u8f93\u5165\u547d\u4ee4\u5e76\u8fd0\u884c\u3002\u6253\u5f00\u547d\u4ee4\u884c\u754c\u9762\u7684\u65b9\u6cd5\u6839\u636e\u64cd\u4f5c\u7cfb\u7edf\u7684\u4e0d\u540c\u800c\u6709\u6240\u4e0d\u540c\uff1a<\/p>\n<\/p>\n<ol>\n<li><strong>Windows \u7cfb\u7edf\uff1a<\/strong><\/li>\n<\/ol>\n<p><p>\u5728 Windows \u7cfb\u7edf\u4e2d\uff0c\u4f60\u53ef\u4ee5\u901a\u8fc7\u6309 <code>Win + R<\/code> \u6253\u5f00\u8fd0\u884c\u7a97\u53e3\uff0c\u8f93\u5165 <code>cmd<\/code> \u5e76\u6309\u56de\u8f66\u952e\u6253\u5f00\u547d\u4ee4\u63d0\u793a\u7b26\u3002\u6216\u8005\uff0c\u4f60\u4e5f\u53ef\u4ee5\u901a\u8fc7\u5f00\u59cb\u83dc\u5355\u641c\u7d22\u201c\u547d\u4ee4\u63d0\u793a\u7b26\u201d\u6765\u6253\u5f00\u3002<\/p>\n<\/p>\n<ol start=\"2\">\n<li><strong>macOS \u7cfb\u7edf\uff1a<\/strong><\/li>\n<\/ol>\n<p><p>\u5728 macOS \u7cfb\u7edf\u4e2d\uff0c\u4f60\u53ef\u4ee5\u901a\u8fc7\u6309 <code>Cmd + \u7a7a\u683c<\/code> \u6253\u5f00 Spotlight \u641c\u7d22\uff0c\u8f93\u5165\u201c\u7ec8\u7aef\u201d\u5e76\u6309\u56de\u8f66\u952e\u6253\u5f00\u7ec8\u7aef\u3002\u6216\u8005\uff0c\u4f60\u4e5f\u53ef\u4ee5\u901a\u8fc7\u5e94\u7528\u7a0b\u5e8f\u6587\u4ef6\u5939\u4e2d\u7684\u201c\u5b9e\u7528\u5de5\u5177\u201d\u627e\u5230\u5e76\u6253\u5f00\u7ec8\u7aef\u3002<\/p>\n<\/p>\n<ol start=\"3\">\n<li><strong>Linux \u7cfb\u7edf\uff1a<\/strong><\/li>\n<\/ol>\n<p><p>\u5728\u5927\u591a\u6570 Linux \u53d1\u884c\u7248\u4e2d\uff0c\u4f60\u53ef\u4ee5\u901a\u8fc7\u6309 <code>Ctrl + Alt + T<\/code> \u5feb\u6377\u952e\u6253\u5f00\u7ec8\u7aef\u3002\u6216\u8005\uff0c\u4f60\u4e5f\u53ef\u4ee5\u901a\u8fc7\u5e94\u7528\u7a0b\u5e8f\u83dc\u5355\u4e2d\u7684\u201c\u7ec8\u7aef\u201d\u6765\u6253\u5f00\u3002<\/p>\n<\/p>\n<p><p>\u4e09\u3001\u7f16\u5199\u548c\u6267\u884c Python \u811a\u672c<\/p>\n<\/p>\n<p><p>\u5728\u547d\u4ee4\u884c\u754c\u9762\u4e2d\uff0c\u4f60\u53ef\u4ee5\u76f4\u63a5\u8f93\u5165 Python \u547d\u4ee4\u5e76\u7acb\u5373\u6267\u884c\uff0c\u4f46\u66f4\u5e38\u89c1\u7684\u662f\u7f16\u5199 Python \u811a\u672c\u5e76\u901a\u8fc7\u547d\u4ee4\u884c\u6267\u884c\u3002Python \u811a\u672c\u662f\u5305\u542b Python \u4ee3\u7801\u7684\u6587\u672c\u6587\u4ef6\uff0c\u6587\u4ef6\u6269\u5c55\u540d\u901a\u5e38\u4e3a <code>.py<\/code>\u3002<\/p>\n<\/p>\n<ol>\n<li><strong>\u7f16\u5199 Python \u811a\u672c\uff1a<\/strong><\/li>\n<\/ol>\n<p><p>\u4f60\u53ef\u4ee5\u4f7f\u7528\u4efb\u4f55\u6587\u672c\u7f16\u8f91\u5668\uff08\u5982 Notepad++\u3001Sublime Text\u3001Visual Studio Code \u7b49\uff09\u7f16\u5199 Python \u811a\u672c\u3002\u5c06\u811a\u672c\u4fdd\u5b58\u4e3a <code>.py<\/code> \u6587\u4ef6\u3002\u4f8b\u5982\uff0c\u7f16\u5199\u4e00\u4e2a\u7b80\u5355\u7684\u811a\u672c <code>hello.py<\/code>\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">print(&quot;Hello, World!&quot;)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<ol start=\"2\">\n<li><strong>\u6267\u884c Python \u811a\u672c\uff1a<\/strong><\/li>\n<\/ol>\n<p><p>\u5728\u547d\u4ee4\u884c\u754c\u9762\u4e2d\uff0c\u5bfc\u822a\u5230\u811a\u672c\u6240\u5728\u7684\u76ee\u5f55\uff0c\u7136\u540e\u4f7f\u7528 <code>python<\/code> \u6216 <code>python3<\/code> \u547d\u4ee4\u6267\u884c\u811a\u672c\u3002\u4f8b\u5982\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">cd path\/to\/your\/script<\/p>\n<p>python hello.py<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5982\u679c\u4e00\u5207\u6b63\u5e38\uff0c\u4f60\u5c06\u770b\u5230\u8f93\u51fa\u201cHello, World!\u201d\u3002<\/p>\n<\/p>\n<p><p>\u56db\u3001\u8c03\u8bd5\u548c\u4f18\u5316\u4ee3\u7801<\/p>\n<\/p>\n<p><p>\u5728\u547d\u4ee4\u884c\u4e0b\u8fd0\u884c Python \u811a\u672c\u65f6\uff0c\u96be\u514d\u4f1a\u9047\u5230\u9519\u8bef\u6216\u6027\u80fd\u95ee\u9898\u3002\u4e3a\u4e86\u8c03\u8bd5\u548c\u4f18\u5316\u4ee3\u7801\uff0c\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u65b9\u6cd5\uff1a<\/p>\n<\/p>\n<ol>\n<li><strong>\u4f7f\u7528\u6253\u5370\u8bed\u53e5\u8c03\u8bd5\uff1a<\/strong><\/li>\n<\/ol>\n<p><p>\u5728\u4ee3\u7801\u4e2d\u6dfb\u52a0 <code>print<\/code> \u8bed\u53e5\u53ef\u4ee5\u5e2e\u52a9\u4f60\u4e86\u89e3\u7a0b\u5e8f\u6267\u884c\u7684\u6d41\u7a0b\u548c\u53d8\u91cf\u7684\u503c\u3002\u8fd9\u662f\u6700\u7b80\u5355\u7684\u8c03\u8bd5\u65b9\u6cd5\u3002\u4f8b\u5982\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">def add(a, b):<\/p>\n<p>    print(f&quot;Adding {a} and {b}&quot;)<\/p>\n<p>    return a + b<\/p>\n<p>result = add(5, 3)<\/p>\n<p>print(f&quot;Result: {result}&quot;)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<ol start=\"2\">\n<li><strong>\u4f7f\u7528\u8c03\u8bd5\u5668\uff1a<\/strong><\/li>\n<\/ol>\n<p><p>Python \u63d0\u4f9b\u4e86\u5185\u7f6e\u7684\u8c03\u8bd5\u5668 <code>pdb<\/code>\uff0c\u53ef\u4ee5\u9010\u884c\u6267\u884c\u4ee3\u7801\u5e76\u68c0\u67e5\u53d8\u91cf\u7684\u503c\u3002\u8981\u4f7f\u7528 <code>pdb<\/code>\uff0c\u5728\u811a\u672c\u4e2d\u6dfb\u52a0\u4ee5\u4e0b\u4ee3\u7801\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import pdb; pdb.set_trace()<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u8fd0\u884c\u811a\u672c\u65f6\uff0c\u7a0b\u5e8f\u5c06\u6682\u505c\u5728 <code>set_trace<\/code> \u884c\uff0c\u4f60\u53ef\u4ee5\u8f93\u5165\u8c03\u8bd5\u547d\u4ee4\uff08\u5982 <code>n<\/code> \u9010\u884c\u6267\u884c\u3001<code>c<\/code> \u7ee7\u7eed\u6267\u884c\u3001<code>q<\/code> \u9000\u51fa\u8c03\u8bd5\u7b49\uff09\u6765\u8c03\u8bd5\u4ee3\u7801\u3002<\/p>\n<\/p>\n<ol start=\"3\">\n<li><strong>\u6027\u80fd\u5206\u6790\uff1a<\/strong><\/li>\n<\/ol>\n<p><p>\u5982\u679c\u4f60\u9700\u8981\u4f18\u5316\u4ee3\u7801\u7684\u6027\u80fd\uff0c\u53ef\u4ee5\u4f7f\u7528 <code>timeit<\/code> \u6a21\u5757\u8fdb\u884c\u6027\u80fd\u5206\u6790\u3002<code>timeit<\/code> \u6a21\u5757\u53ef\u4ee5\u51c6\u786e\u6d4b\u91cf\u4ee3\u7801\u7684\u6267\u884c\u65f6\u95f4\u3002\u4f8b\u5982\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import timeit<\/p>\n<p>def test():<\/p>\n<p>    return [i for i in range(1000)]<\/p>\n<p>execution_time = timeit.timeit(test, number=1000)<\/p>\n<p>print(f&quot;Execution time: {execution_time} seconds&quot;)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u901a\u8fc7\u8fd9\u4e9b\u65b9\u6cd5\uff0c\u4f60\u53ef\u4ee5\u5728\u547d\u4ee4\u884c\u4e0b\u9ad8\u6548\u5730\u8fd0\u884c\u548c\u8c03\u8bd5 Python \u4ee3\u7801\u3002<\/p>\n<\/p>\n<p><p>\u4e94\u3001\u4f7f\u7528\u865a\u62df\u73af\u5883<\/p>\n<\/p>\n<p><p>\u5728\u5f00\u53d1 Python \u9879\u76ee\u65f6\uff0c\u4f7f\u7528\u865a\u62df\u73af\u5883\u53ef\u4ee5\u5e2e\u52a9\u4f60\u9694\u79bb\u9879\u76ee\u7684\u4f9d\u8d56\u5e93\uff0c\u907f\u514d\u4e0e\u7cfb\u7edf\u5168\u5c40\u5b89\u88c5\u7684\u5e93\u53d1\u751f\u51b2\u7a81\u3002Python \u63d0\u4f9b\u4e86 <code>venv<\/code> \u6a21\u5757\u6765\u521b\u5efa\u865a\u62df\u73af\u5883\u3002<\/p>\n<\/p>\n<ol>\n<li><strong>\u521b\u5efa\u865a\u62df\u73af\u5883\uff1a<\/strong><\/li>\n<\/ol>\n<p><p>\u5728\u9879\u76ee\u76ee\u5f55\u4e0b\uff0c\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u521b\u5efa\u865a\u62df\u73af\u5883\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">python -m venv myenv<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u8fd9\u5c06\u521b\u5efa\u4e00\u4e2a\u540d\u4e3a <code>myenv<\/code> \u7684\u865a\u62df\u73af\u5883\u76ee\u5f55\u3002<\/p>\n<\/p>\n<ol start=\"2\">\n<li><strong>\u6fc0\u6d3b\u865a\u62df\u73af\u5883\uff1a<\/strong><\/li>\n<\/ol>\n<p><p>\u6839\u636e\u64cd\u4f5c\u7cfb\u7edf\u7684\u4e0d\u540c\uff0c\u6fc0\u6d3b\u865a\u62df\u73af\u5883\u7684\u65b9\u6cd5\u7565\u6709\u4e0d\u540c\uff1a<\/p>\n<\/p>\n<ul>\n<li><strong>Windows \u7cfb\u7edf\uff1a<\/strong><\/li>\n<\/ul>\n<p><pre><code class=\"language-bash\">myenv\\Scripts\\activate<\/p>\n<p><\/code><\/pre>\n<\/p>\n<ul>\n<li><strong>macOS \u548c Linux \u7cfb\u7edf\uff1a<\/strong><\/li>\n<\/ul>\n<p><pre><code class=\"language-bash\">source myenv\/bin\/activate<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u6fc0\u6d3b\u865a\u62df\u73af\u5883\u540e\uff0c\u547d\u4ee4\u884c\u63d0\u793a\u7b26\u4f1a\u663e\u793a\u865a\u62df\u73af\u5883\u7684\u540d\u79f0\u3002<\/p>\n<\/p>\n<ol start=\"3\">\n<li><strong>\u5b89\u88c5\u4f9d\u8d56\u5e93\uff1a<\/strong><\/li>\n<\/ol>\n<p><p>\u5728\u865a\u62df\u73af\u5883\u4e2d\uff0c\u4f60\u53ef\u4ee5\u4f7f\u7528 <code>pip<\/code> \u5b89\u88c5\u9879\u76ee\u7684\u4f9d\u8d56\u5e93\u3002\u4f8b\u5982\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">pip install requests<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u6240\u6709\u5b89\u88c5\u7684\u5e93\u90fd\u5c06\u4fdd\u5b58\u5728\u865a\u62df\u73af\u5883\u4e2d\uff0c\u800c\u4e0d\u4f1a\u5f71\u54cd\u7cfb\u7edf\u7684\u5168\u5c40\u5e93\u3002<\/p>\n<\/p>\n<ol start=\"4\">\n<li><strong>\u9000\u51fa\u865a\u62df\u73af\u5883\uff1a<\/strong><\/li>\n<\/ol>\n<p><p>\u5b8c\u6210\u5de5\u4f5c\u540e\uff0c\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u9000\u51fa\u865a\u62df\u73af\u5883\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">deactivate<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u901a\u8fc7\u4f7f\u7528\u865a\u62df\u73af\u5883\uff0c\u4f60\u53ef\u4ee5\u66f4\u597d\u5730\u7ba1\u7406\u9879\u76ee\u7684\u4f9d\u8d56\u5e93\uff0c\u786e\u4fdd\u9879\u76ee\u7684\u53ef\u79fb\u690d\u6027\u548c\u7a33\u5b9a\u6027\u3002<\/p>\n<\/p>\n<p><p>\u516d\u3001\u4f7f\u7528\u5305\u7ba1\u7406\u5de5\u5177<\/p>\n<\/p>\n<p><p>\u5728\u5f00\u53d1 Python \u9879\u76ee\u65f6\uff0c\u7ba1\u7406\u9879\u76ee\u7684\u4f9d\u8d56\u5e93\u662f\u975e\u5e38\u91cd\u8981\u7684\u3002\u4f7f\u7528\u5305\u7ba1\u7406\u5de5\u5177\u53ef\u4ee5\u5e2e\u52a9\u4f60\u65b9\u4fbf\u5730\u7ba1\u7406\u548c\u5b89\u88c5\u4f9d\u8d56\u5e93\u3002Python \u63d0\u4f9b\u4e86\u591a\u4e2a\u5305\u7ba1\u7406\u5de5\u5177\uff0c\u5176\u4e2d\u6700\u5e38\u7528\u7684\u662f <code>pip<\/code> \u548c <code>pipenv<\/code>\u3002<\/p>\n<\/p>\n<ol>\n<li><strong>\u4f7f\u7528 pip\uff1a<\/strong><\/li>\n<\/ol>\n<p><p><code>pip<\/code> \u662f Python \u7684\u5b98\u65b9\u5305\u7ba1\u7406\u5de5\u5177\uff0c\u51e0\u4e4e\u6240\u6709 Python \u9879\u76ee\u90fd\u4f7f\u7528 <code>pip<\/code> \u6765\u7ba1\u7406\u4f9d\u8d56\u5e93\u3002\u4f60\u53ef\u4ee5\u4f7f\u7528 <code>pip<\/code> \u5b89\u88c5\u3001\u5347\u7ea7\u548c\u5378\u8f7d\u5e93\u3002\u4f8b\u5982\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">pip install requests<\/p>\n<p>pip install --upgrade requests<\/p>\n<p>pip uninstall requests<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u4f60\u8fd8\u53ef\u4ee5\u4f7f\u7528 <code>requirements.txt<\/code> \u6587\u4ef6\u5217\u51fa\u9879\u76ee\u7684\u6240\u6709\u4f9d\u8d56\u5e93\uff0c\u5e76\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u5b89\u88c5\u6240\u6709\u4f9d\u8d56\u5e93\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">pip install -r requirements.txt<\/p>\n<p><\/code><\/pre>\n<\/p>\n<ol start=\"2\">\n<li><strong>\u4f7f\u7528 pipenv\uff1a<\/strong><\/li>\n<\/ol>\n<p><p><code>pipenv<\/code> \u662f\u4e00\u4e2a\u9ad8\u7ea7\u5305\u7ba1\u7406\u5de5\u5177\uff0c\u7ed3\u5408\u4e86 <code>pip<\/code> \u548c <code>virtualenv<\/code> \u7684\u529f\u80fd\uff0c\u4f7f\u4f9d\u8d56\u5e93\u7ba1\u7406\u66f4\u52a0\u65b9\u4fbf\u3002\u4f7f\u7528 <code>pipenv<\/code>\uff0c\u4f60\u53ef\u4ee5\u521b\u5efa\u548c\u7ba1\u7406\u865a\u62df\u73af\u5883\uff0c\u5e76\u81ea\u52a8\u5b89\u88c5\u548c\u66f4\u65b0\u4f9d\u8d56\u5e93\u3002\u4f8b\u5982\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">pip install pipenv<\/p>\n<p>pipenv install requests<\/p>\n<p>pipenv install --dev pytest<\/p>\n<p>pipenv shell<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u4f7f\u7528 <code>pipenv<\/code> \u521b\u5efa\u7684\u865a\u62df\u73af\u5883\u4f1a\u81ea\u52a8\u5305\u542b\u9879\u76ee\u7684\u6240\u6709\u4f9d\u8d56\u5e93\uff0c\u5e76\u751f\u6210 <code>Pipfile<\/code> \u548c <code>Pipfile.lock<\/code> \u6587\u4ef6\u6765\u8bb0\u5f55\u4f9d\u8d56\u5e93\u7684\u4fe1\u606f\u3002<\/p>\n<\/p>\n<p><p>\u901a\u8fc7\u4f7f\u7528\u5305\u7ba1\u7406\u5de5\u5177\uff0c\u4f60\u53ef\u4ee5\u66f4\u597d\u5730\u7ba1\u7406\u9879\u76ee\u7684\u4f9d\u8d56\u5e93\uff0c\u786e\u4fdd\u9879\u76ee\u7684\u53ef\u79fb\u690d\u6027\u548c\u7a33\u5b9a\u6027\u3002<\/p>\n<\/p>\n<p><p>\u4e03\u3001\u4f7f\u7528\u96c6\u6210\u5f00\u53d1\u73af\u5883\uff08IDE\uff09<\/p>\n<\/p>\n<p><p>\u867d\u7136\u547d\u4ee4\u884c\u754c\u9762\u975e\u5e38\u5f3a\u5927\uff0c\u4f46\u5728\u7f16\u5199\u590d\u6742\u7684 Python \u9879\u76ee\u65f6\uff0c\u4f7f\u7528\u96c6\u6210\u5f00\u53d1\u73af\u5883\uff08IDE\uff09\u53ef\u4ee5\u63d0\u9ad8\u5f00\u53d1\u6548\u7387\u3002IDE \u63d0\u4f9b\u4e86\u4ee3\u7801\u7f16\u8f91\u3001\u8c03\u8bd5\u3001\u7248\u672c\u63a7\u5236\u7b49\u4e00\u4f53\u5316\u529f\u80fd\uff0c\u4f7f\u5f00\u53d1\u8fc7\u7a0b\u66f4\u52a0\u987a\u7545\u3002\u4ee5\u4e0b\u662f\u4e00\u4e9b\u5e38\u7528\u7684 Python IDE\uff1a<\/p>\n<\/p>\n<ol>\n<li><strong>PyCharm\uff1a<\/strong><\/li>\n<\/ol>\n<p><p>PyCharm \u662f JetBr<a href=\"https:\/\/docs.pingcode.com\/blog\/59162.html\" target=\"_blank\">AI<\/a>ns \u516c\u53f8\u5f00\u53d1\u7684\u4e00\u6b3e\u529f\u80fd\u5f3a\u5927\u7684 Python IDE\uff0c\u652f\u6301\u4ee3\u7801\u8865\u5168\u3001\u8c03\u8bd5\u3001\u6d4b\u8bd5\u3001\u7248\u672c\u63a7\u5236\u7b49\u529f\u80fd\u3002PyCharm \u63d0\u4f9b\u4e86\u793e\u533a\u7248\u548c\u4e13\u4e1a\u7248\u4e24\u79cd\u7248\u672c\uff0c\u793e\u533a\u7248\u514d\u8d39\u5f00\u6e90\uff0c\u9002\u5408\u4e2a\u4eba\u548c\u5c0f\u578b\u9879\u76ee\u5f00\u53d1\u3002<\/p>\n<\/p>\n<ol start=\"2\">\n<li><strong>Visual Studio Code\uff1a<\/strong><\/li>\n<\/ol>\n<p><p>Visual Studio Code\uff08VS Code\uff09\u662f\u5fae\u8f6f\u63a8\u51fa\u7684\u4e00\u6b3e\u8f7b\u91cf\u7ea7\u3001\u8de8\u5e73\u53f0\u7684\u4ee3\u7801\u7f16\u8f91\u5668\uff0c\u652f\u6301\u591a\u79cd\u7f16\u7a0b\u8bed\u8a00\u3002\u901a\u8fc7\u5b89\u88c5 Python \u6269\u5c55\uff0cVS Code \u53ef\u4ee5\u53d8\u6210\u4e00\u4e2a\u529f\u80fd\u5f3a\u5927\u7684 Python IDE\uff0c\u652f\u6301\u4ee3\u7801\u8865\u5168\u3001\u8c03\u8bd5\u3001\u6d4b\u8bd5\u7b49\u529f\u80fd\u3002<\/p>\n<\/p>\n<ol start=\"3\">\n<li><strong>Jupyter Notebook\uff1a<\/strong><\/li>\n<\/ol>\n<p><p>Jupyter Notebook \u662f\u4e00\u4e2a\u4ea4\u4e92\u5f0f\u7684\u8ba1\u7b97\u73af\u5883\uff0c\u9002\u5408\u6570\u636e\u79d1\u5b66\u3001<a href=\"https:\/\/docs.pingcode.com\/ask\/59192.html\" target=\"_blank\">\u673a\u5668\u5b66\u4e60<\/a>\u7b49\u9886\u57df\u7684\u5f00\u53d1\u3002Jupyter Notebook \u5141\u8bb8\u4f60\u5728\u6d4f\u89c8\u5668\u4e2d\u7f16\u5199\u548c\u6267\u884c\u4ee3\u7801\uff0c\u652f\u6301\u53ef\u89c6\u5316\u548c\u6587\u6863\u7f16\u5199\uff0c\u975e\u5e38\u9002\u5408\u6570\u636e\u5206\u6790\u548c\u79d1\u5b66\u8ba1\u7b97\u3002<\/p>\n<\/p>\n<ol start=\"4\">\n<li><strong>Atom\uff1a<\/strong><\/li>\n<\/ol>\n<p><p>Atom \u662f GitHub \u5f00\u53d1\u7684\u4e00\u6b3e\u5f00\u6e90\u4ee3\u7801\u7f16\u8f91\u5668\uff0c\u652f\u6301\u591a\u79cd\u7f16\u7a0b\u8bed\u8a00\u3002\u901a\u8fc7\u5b89\u88c5\u76f8\u5173\u63d2\u4ef6\uff0cAtom \u53ef\u4ee5\u53d8\u6210\u4e00\u4e2a\u529f\u80fd\u5f3a\u5927\u7684 Python IDE\uff0c\u652f\u6301\u4ee3\u7801\u8865\u5168\u3001\u8c03\u8bd5\u3001\u6d4b\u8bd5\u7b49\u529f\u80fd\u3002<\/p>\n<\/p>\n<p><p>\u901a\u8fc7\u4f7f\u7528 IDE\uff0c\u4f60\u53ef\u4ee5\u63d0\u9ad8\u5f00\u53d1\u6548\u7387\uff0c\u51cf\u5c11\u9519\u8bef\uff0c\u4e13\u6ce8\u4e8e\u4ee3\u7801\u7684\u7f16\u5199\u548c\u8c03\u8bd5\u3002<\/p>\n<\/p>\n<p><p>\u516b\u3001\u7248\u672c\u63a7\u5236\u548c\u534f\u4f5c\u5f00\u53d1<\/p>\n<\/p>\n<p><p>\u5728\u5f00\u53d1 Python \u9879\u76ee\u65f6\uff0c\u4f7f\u7528\u7248\u672c\u63a7\u5236\u7cfb\u7edf\uff08\u5982 Git\uff09\u53ef\u4ee5\u5e2e\u52a9\u4f60\u7ba1\u7406\u4ee3\u7801\u7248\u672c\uff0c\u8ddf\u8e2a\u4ee3\u7801\u53d8\u5316\uff0c\u5e76\u65b9\u4fbf\u4e0e\u56e2\u961f\u6210\u5458\u534f\u4f5c\u5f00\u53d1\u3002\u4ee5\u4e0b\u662f\u4e00\u4e9b\u5e38\u7528\u7684\u7248\u672c\u63a7\u5236\u5de5\u5177\u548c\u5e73\u53f0\uff1a<\/p>\n<\/p>\n<ol>\n<li><strong>Git\uff1a<\/strong><\/li>\n<\/ol>\n<p><p>Git \u662f\u76ee\u524d\u6700\u6d41\u884c\u7684\u5206\u5e03\u5f0f\u7248\u672c\u63a7\u5236\u7cfb\u7edf\uff0c\u9002\u7528\u4e8e\u5404\u79cd\u89c4\u6a21\u7684\u9879\u76ee\u3002\u4f7f\u7528 Git\uff0c\u4f60\u53ef\u4ee5\u8f7b\u677e\u5730\u7ba1\u7406\u4ee3\u7801\u7248\u672c\u3001\u5408\u5e76\u4ee3\u7801\u3001\u66f4\u6539\u5386\u53f2\u8bb0\u5f55\u7b49\u3002\u4ee5\u4e0b\u662f\u4e00\u4e9b\u5e38\u7528\u7684 Git \u547d\u4ee4\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">git init<\/p>\n<p>git add .<\/p>\n<p>git commit -m &quot;Initial commit&quot;<\/p>\n<p>git remote add origin https:\/\/github.com\/username\/repo.git<\/p>\n<p>git push -u origin master<\/p>\n<p><\/code><\/pre>\n<\/p>\n<ol start=\"2\">\n<li><strong>GitHub\uff1a<\/strong><\/li>\n<\/ol>\n<p><p>GitHub \u662f\u4e00\u4e2a\u57fa\u4e8e Git \u7684\u4ee3\u7801\u6258\u7ba1\u5e73\u53f0\uff0c\u63d0\u4f9b\u4e86\u7248\u672c\u63a7\u5236\u3001<a href=\"https:\/\/docs.pingcode.com\/blog\/project-management\/23316.html\" target=\"_blank\">\u9879\u76ee\u7ba1\u7406<\/a>\u3001\u534f\u4f5c\u5f00\u53d1\u7b49\u529f\u80fd\u3002\u4f60\u53ef\u4ee5\u5728 GitHub \u4e0a\u521b\u5efa\u4ed3\u5e93\u3001\u63d0\u4ea4\u4ee3\u7801\u3001\u53d1\u8d77 Pull Request\u3001\u8fdb\u884c<a href=\"https:\/\/docs.pingcode.com\/code-review\" target=\"_blank\">\u4ee3\u7801\u5ba1\u67e5<\/a>\u7b49\u3002<\/p>\n<\/p>\n<ol start=\"3\">\n<li><strong>GitLab\uff1a<\/strong><\/li>\n<\/ol>\n<p><p>GitLab \u662f\u53e6\u4e00\u4e2a\u6d41\u884c\u7684\u4ee3\u7801\u6258\u7ba1\u5e73\u53f0\uff0c\u529f\u80fd\u7c7b\u4f3c\u4e8e GitHub\u3002GitLab \u63d0\u4f9b\u4e86\u66f4\u591a\u7684\u4f01\u4e1a\u7ea7\u529f\u80fd\uff0c\u5982\u6301\u7eed\u96c6\u6210\/\u6301\u7eed\u90e8\u7f72\uff08<a href=\"https:\/\/docs.pingcode.com\/blog\/devops\/52691.html\" target=\"_blank\">CI\/CD<\/a>\uff09\u3001\u4ee3\u7801\u5ba1\u67e5\u3001\u95ee\u9898\u8ffd\u8e2a\u7b49\u3002<\/p>\n<\/p>\n<ol start=\"4\">\n<li><strong>Bitbucket\uff1a<\/strong><\/li>\n<\/ol>\n<p><p>Bitbucket \u662f Atlassian \u516c\u53f8\u63a8\u51fa\u7684\u4ee3\u7801\u6258\u7ba1\u5e73\u53f0\uff0c\u652f\u6301 Git \u548c Mercurial \u4e24\u79cd\u7248\u672c\u63a7\u5236\u7cfb\u7edf\u3002Bitbucket \u63d0\u4f9b\u4e86\u4e30\u5bcc\u7684\u534f\u4f5c\u5f00\u53d1\u529f\u80fd\uff0c\u5982\u4ee3\u7801\u5ba1\u67e5\u3001\u5206\u652f\u7ba1\u7406\u3001\u6301\u7eed\u96c6\u6210\u7b49\u3002<\/p>\n<\/p>\n<p><p>\u901a\u8fc7\u4f7f\u7528\u7248\u672c\u63a7\u5236\u7cfb\u7edf\u548c\u4ee3\u7801\u6258\u7ba1\u5e73\u53f0\uff0c\u4f60\u53ef\u4ee5\u66f4\u597d\u5730\u7ba1\u7406\u4ee3\u7801\u7248\u672c\u3001\u8ddf\u8e2a\u4ee3\u7801\u53d8\u5316\u3001\u534f\u4f5c\u5f00\u53d1\uff0c\u63d0\u9ad8\u9879\u76ee\u7684\u8d28\u91cf\u548c\u6548\u7387\u3002<\/p>\n<\/p>\n<h2><strong>\u76f8\u5173\u95ee\u7b54FAQs\uff1a<\/strong><\/h2>\n<p> <strong>\u5982\u4f55\u5728\u547d\u4ee4\u884c\u4e0b\u68c0\u67e5Python\u662f\u5426\u5df2\u5b89\u88c5\uff1f<\/strong><br \/>\u8981\u786e\u8ba4\u60a8\u7684\u7cfb\u7edf\u4e2d\u662f\u5426\u5df2\u5b89\u88c5Python\uff0c\u53ef\u4ee5\u5728\u547d\u4ee4\u884c\u4e2d\u8f93\u5165<code>python --version<\/code>\u6216<code>python3 --version<\/code>\u3002\u5982\u679cPython\u5df2\u6210\u529f\u5b89\u88c5\uff0c\u60a8\u5c06\u770b\u5230Python\u7684\u7248\u672c\u53f7\u3002\u5982\u679c\u7cfb\u7edf\u63d0\u793a\u201c\u672a\u627e\u5230\u547d\u4ee4\u201d\uff0c\u60a8\u53ef\u80fd\u9700\u8981\u5b89\u88c5Python\u3002<\/p>\n<p><strong>\u5728\u547d\u4ee4\u884c\u4e2d\u8fd0\u884cPython\u811a\u672c\u7684\u6b65\u9aa4\u662f\u4ec0\u4e48\uff1f<\/strong><br \/>\u8fd0\u884cPython\u811a\u672c\u975e\u5e38\u7b80\u5355\u3002\u9996\u5148\uff0c\u6253\u5f00\u547d\u4ee4\u884c\u754c\u9762\u5e76\u5bfc\u822a\u5230\u5305\u542b\u60a8\u7684Python\u811a\u672c\u7684\u6587\u4ef6\u5939\u3002\u4f7f\u7528<code>cd<\/code>\u547d\u4ee4\u66f4\u6539\u76ee\u5f55\u3002\u63a5\u7740\uff0c\u8f93\u5165<code>python your_script.py<\/code>\u6216<code>python3 your_script.py<\/code>\uff08\u6839\u636e\u60a8\u5b89\u88c5\u7684Python\u7248\u672c\uff09\u6765\u8fd0\u884c\u60a8\u7684\u811a\u672c\u3002<\/p>\n<p><strong>\u5982\u4f55\u5728\u547d\u4ee4\u884c\u4e0b\u4f7f\u7528Python\u4ea4\u4e92\u5f0f\u89e3\u91ca\u5668\uff1f<\/strong><br \/>\u60a8\u53ef\u4ee5\u901a\u8fc7\u5728\u547d\u4ee4\u884c\u4e2d\u8f93\u5165<code>python<\/code>\u6216<code>python3<\/code>\u6765\u542f\u52a8Python\u7684\u4ea4\u4e92\u5f0f\u89e3\u91ca\u5668\u3002\u5728\u6b64\u6a21\u5f0f\u4e0b\uff0c\u60a8\u53ef\u4ee5\u76f4\u63a5\u8f93\u5165Python\u4ee3\u7801\u5e76\u7acb\u5373\u67e5\u770b\u8f93\u51fa\u3002\u8fd9\u5bf9\u4e8e\u6d4b\u8bd5\u5c0f\u6bb5\u4ee3\u7801\u6216\u8fdb\u884c\u5feb\u901f\u8ba1\u7b97\u975e\u5e38\u6709\u7528\u3002\u8981\u9000\u51fa\u89e3\u91ca\u5668\uff0c\u53ef\u4ee5\u8f93\u5165<code>exit()<\/code>\u6216\u4f7f\u7528\u5feb\u6377\u952e<code>Ctrl + Z<\/code>\uff08Windows\uff09\u6216<code>Ctrl + D<\/code>\uff08Mac\/Linux\uff09\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"\u5728\u547d\u4ee4\u884c\u4e0b\u8fd0\u884c Python \u7684\u65b9\u6cd5\u5305\u62ec\u5b89\u88c5 Python \u73af\u5883\u3001\u4f7f\u7528\u547d\u4ee4\u884c\u754c\u9762\u3001\u7f16\u5199\u548c\u6267\u884c Python \u811a [&hellip;]","protected":false},"author":3,"featured_media":1065232,"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\/1065225"}],"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=1065225"}],"version-history":[{"count":"1","href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1065225\/revisions"}],"predecessor-version":[{"id":1065235,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1065225\/revisions\/1065235"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media\/1065232"}],"wp:attachment":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media?parent=1065225"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/categories?post=1065225"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/tags?post=1065225"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}