{"id":1180701,"date":"2025-01-15T18:41:38","date_gmt":"2025-01-15T10:41:38","guid":{"rendered":""},"modified":"2025-01-15T18:41:46","modified_gmt":"2025-01-15T10:41:46","slug":"%e5%a6%82%e4%bd%95%e6%a3%80%e9%aa%8cpython%e4%b8%8b%e8%bd%bd%e6%98%af%e5%90%a6%e6%88%90%e5%8a%9f","status":"publish","type":"post","link":"https:\/\/docs.pingcode.com\/ask\/1180701.html","title":{"rendered":"\u5982\u4f55\u68c0\u9a8cPython\u4e0b\u8f7d\u662f\u5426\u6210\u529f"},"content":{"rendered":"<p style=\"text-align:center;\" ><img decoding=\"async\" src=\"https:\/\/cdn-kb.worktile.com\/kb\/wp-content\/uploads\/2024\/04\/25125324\/6cd95523-2fbf-46f1-954d-4a258ff722b7.webp\" alt=\"\u5982\u4f55\u68c0\u9a8cPython\u4e0b\u8f7d\u662f\u5426\u6210\u529f\" \/><\/p>\n<p><p> \u8981\u68c0\u9a8cPython\u4e0b\u8f7d\u662f\u5426\u6210\u529f\uff0c\u53ef\u4ee5\u901a\u8fc7\u4ee5\u4e0b\u65b9\u6cd5\u8fdb\u884c\u9a8c\u8bc1\uff1a<strong>\u8fd0\u884cPython\u89e3\u91ca\u5668\u3001\u68c0\u67e5Python\u7248\u672c\u3001\u8fd0\u884cPython\u811a\u672c\u3001\u4f7f\u7528pip\u8fdb\u884c\u5305\u7ba1\u7406<\/strong>\u3002\u5176\u4e2d\uff0c\u901a\u8fc7\u8fd0\u884cPython\u89e3\u91ca\u5668\u662f\u6700\u76f4\u63a5\u548c\u6709\u6548\u7684\u65b9\u6cd5\u4e4b\u4e00\u3002\u6253\u5f00\u7ec8\u7aef\u6216\u547d\u4ee4\u63d0\u793a\u7b26\uff0c\u8f93\u5165<code>python<\/code>\u6216<code>python3<\/code>\uff0c\u5982\u679c\u770b\u5230Python\u89e3\u91ca\u5668\u542f\u52a8\u5e76\u663e\u793a\u7248\u672c\u4fe1\u606f\uff0c\u5219\u8bf4\u660ePython\u4e0b\u8f7d\u5e76\u5b89\u88c5\u6210\u529f\u3002<\/p>\n<\/p>\n<p><h3>\u4e00\u3001\u8fd0\u884cPython\u89e3\u91ca\u5668<\/h3>\n<\/p>\n<ol>\n<li>\n<p><strong>\u6253\u5f00\u7ec8\u7aef\u6216\u547d\u4ee4\u63d0\u793a\u7b26<\/strong><\/p>\n<\/p>\n<ul>\n<li>\u5728Windows\u7cfb\u7edf\u4e2d\uff0c\u6309\u4e0bWin + R\u952e\uff0c\u7136\u540e\u8f93\u5165<code>cmd<\/code>\u5e76\u6309\u4e0b\u56de\u8f66\u952e\u3002<\/li>\n<li>\u5728Mac\u6216Linux\u7cfb\u7edf\u4e2d\uff0c\u53ef\u4ee5\u76f4\u63a5\u6253\u5f00\u7ec8\u7aef\u5e94\u7528\u7a0b\u5e8f\u3002<\/li>\n<\/ul>\n<\/li>\n<li>\n<p><strong>\u8f93\u5165\u547d\u4ee4\u542f\u52a8Python\u89e3\u91ca\u5668<\/strong><\/p>\n<\/p>\n<ul>\n<li>\u5728\u7ec8\u7aef\u6216\u547d\u4ee4\u63d0\u793a\u7b26\u4e2d\u8f93\u5165<code>python<\/code>\u6216<code>python3<\/code>\uff0c\u7136\u540e\u6309\u4e0b\u56de\u8f66\u952e\u3002<\/li>\n<li>\u5982\u679cPython\u89e3\u91ca\u5668\u6210\u529f\u542f\u52a8\uff0c\u4f60\u5c06\u770b\u5230\u7c7b\u4f3c\u4ee5\u4e0b\u7684\u4fe1\u606f\uff1a\n<pre><code>Python 3.x.x (default, Dec  6 2023, 20:24:33) <\/p>\n<p>[GCC 4.8.5] on linux<\/p>\n<p>Type &quot;help&quot;, &quot;copyright&quot;, &quot;credits&quot; or &quot;license&quot; for more information.<\/p>\n<p>&gt;&gt;&gt;<\/p>\n<p><\/code><\/pre>\n<\/p>\n<\/li>\n<li>\u8fd9\u8868\u793aPython\u5df2\u7ecf\u6210\u529f\u5b89\u88c5\u5e76\u53ef\u4ee5\u6b63\u5e38\u4f7f\u7528\u3002<\/li>\n<\/ul>\n<\/li>\n<\/ol>\n<p><h3>\u4e8c\u3001\u68c0\u67e5Python\u7248\u672c<\/h3>\n<\/p>\n<ol>\n<li>\n<p><strong>\u5728\u7ec8\u7aef\u6216\u547d\u4ee4\u63d0\u793a\u7b26\u4e2d\u8f93\u5165\u547d\u4ee4<\/strong><\/p>\n<\/p>\n<ul>\n<li>\u8f93\u5165<code>python --version<\/code>\u6216<code>python3 --version<\/code>\uff0c\u7136\u540e\u6309\u4e0b\u56de\u8f66\u952e\u3002<\/li>\n<li>\u4f60\u5c06\u770b\u5230\u7c7b\u4f3c\u4ee5\u4e0b\u7684\u8f93\u51fa\uff1a\n<pre><code>Python 3.x.x<\/p>\n<p><\/code><\/pre>\n<\/p>\n<\/li>\n<li>\u8fd9\u8868\u793aPython\u5df2\u7ecf\u6210\u529f\u5b89\u88c5\uff0c\u5e76\u4e14\u663e\u793a\u4e86\u5f53\u524d\u5b89\u88c5\u7684Python\u7248\u672c\u3002<\/li>\n<\/ul>\n<\/li>\n<li>\n<p><strong>\u9a8c\u8bc1Python\u7248\u672c<\/strong><\/p>\n<\/p>\n<ul>\n<li>\u786e\u8ba4\u8f93\u51fa\u7684Python\u7248\u672c\u4e0e\u9884\u671f\u7684\u4e00\u81f4\u3002\u5982\u679c\u7248\u672c\u4fe1\u606f\u6b63\u786e\uff0c\u8bf4\u660ePython\u5b89\u88c5\u6ca1\u6709\u95ee\u9898\u3002<\/li>\n<\/ul>\n<\/li>\n<\/ol>\n<p><h3>\u4e09\u3001\u8fd0\u884cPython\u811a\u672c<\/h3>\n<\/p>\n<ol>\n<li>\n<p><strong>\u521b\u5efa\u4e00\u4e2a\u7b80\u5355\u7684Python\u811a\u672c<\/strong><\/p>\n<\/p>\n<ul>\n<li>\u4f7f\u7528\u6587\u672c\u7f16\u8f91\u5668\u521b\u5efa\u4e00\u4e2a\u65b0\u7684\u6587\u4ef6\uff0c\u5e76\u547d\u540d\u4e3a<code>test.py<\/code>\u3002<\/li>\n<li>\u5728\u6587\u4ef6\u4e2d\u8f93\u5165\u4ee5\u4e0b\u5185\u5bb9\uff1a\n<pre><code class=\"language-python\">print(&quot;Hello, Python!&quot;)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<\/li>\n<\/ul>\n<\/li>\n<li>\n<p><strong>\u8fd0\u884cPython\u811a\u672c<\/strong><\/p>\n<\/p>\n<ul>\n<li>\u5728\u7ec8\u7aef\u6216\u547d\u4ee4\u63d0\u793a\u7b26\u4e2d\uff0c\u5bfc\u822a\u5230\u5305\u542b<code>test.py<\/code>\u6587\u4ef6\u7684\u76ee\u5f55\u3002<\/li>\n<li>\u8f93\u5165<code>python test.py<\/code>\u6216<code>python3 test.py<\/code>\uff0c\u7136\u540e\u6309\u4e0b\u56de\u8f66\u952e\u3002<\/li>\n<li>\u5982\u679c\u770b\u5230\u8f93\u51fa<code>Hello, Python!<\/code>\uff0c\u8bf4\u660ePython\u5b89\u88c5\u6210\u529f\u5e76\u4e14\u53ef\u4ee5\u6b63\u5e38\u8fd0\u884c\u811a\u672c\u3002<\/li>\n<\/ul>\n<\/li>\n<\/ol>\n<p><h3>\u56db\u3001\u4f7f\u7528pip\u8fdb\u884c\u5305\u7ba1\u7406<\/h3>\n<\/p>\n<ol>\n<li>\n<p><strong>\u68c0\u67e5pip\u662f\u5426\u5b89\u88c5<\/strong><\/p>\n<\/p>\n<ul>\n<li>\u5728\u7ec8\u7aef\u6216\u547d\u4ee4\u63d0\u793a\u7b26\u4e2d\u8f93\u5165<code>pip --version<\/code>\u6216<code>pip3 --version<\/code>\uff0c\u7136\u540e\u6309\u4e0b\u56de\u8f66\u952e\u3002<\/li>\n<li>\u4f60\u5c06\u770b\u5230\u7c7b\u4f3c\u4ee5\u4e0b\u7684\u8f93\u51fa\uff1a\n<pre><code>pip 21.0.1 from \/usr\/local\/lib\/python3.9\/site-packages\/pip (python 3.9)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<\/li>\n<li>\u8fd9\u8868\u793apip\u5df2\u7ecf\u6210\u529f\u5b89\u88c5\uff0c\u5e76\u4e14\u663e\u793a\u4e86\u5f53\u524d\u5b89\u88c5\u7684pip\u7248\u672c\u3002<\/li>\n<\/ul>\n<\/li>\n<li>\n<p><strong>\u5b89\u88c5\u4e00\u4e2aPython\u5305<\/strong><\/p>\n<\/p>\n<ul>\n<li>\u4f7f\u7528pip\u5b89\u88c5\u4e00\u4e2a\u7b80\u5355\u7684Python\u5305\uff0c\u4f8b\u5982<code>requests<\/code>\u3002<\/li>\n<li>\u5728\u7ec8\u7aef\u6216\u547d\u4ee4\u63d0\u793a\u7b26\u4e2d\u8f93\u5165<code>pip install requests<\/code>\u6216<code>pip3 install requests<\/code>\uff0c\u7136\u540e\u6309\u4e0b\u56de\u8f66\u952e\u3002<\/li>\n<li>\u5982\u679c\u5b89\u88c5\u6210\u529f\uff0c\u4f60\u5c06\u770b\u5230\u7c7b\u4f3c\u4ee5\u4e0b\u7684\u8f93\u51fa\uff1a\n<pre><code>Successfully installed requests-2.25.1<\/p>\n<p><\/code><\/pre>\n<\/p>\n<\/li>\n<\/ul>\n<\/li>\n<li>\n<p><strong>\u9a8c\u8bc1\u5b89\u88c5\u7684\u5305<\/strong><\/p>\n<\/p>\n<ul>\n<li>\u521b\u5efa\u4e00\u4e2a\u65b0\u7684Python\u811a\u672c\u6587\u4ef6\uff0c\u5e76\u547d\u540d\u4e3a<code>test_requests.py<\/code>\u3002<\/li>\n<li>\u5728\u6587\u4ef6\u4e2d\u8f93\u5165\u4ee5\u4e0b\u5185\u5bb9\uff1a\n<pre><code class=\"language-python\">import requests<\/p>\n<p>response = requests.get(&#39;https:\/\/www.example.com&#39;)<\/p>\n<p>print(response.status_code)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<\/li>\n<li>\u8fd0\u884c\u811a\u672c\u5e76\u68c0\u67e5\u8f93\u51fa\u3002\u5982\u679c\u770b\u5230HTTP\u72b6\u6001\u7801\uff08\u4f8b\u5982<code>200<\/code>\uff09\uff0c\u8bf4\u660ePython\u548cpip\u90fd\u6b63\u5e38\u5de5\u4f5c\u3002<\/li>\n<\/ul>\n<\/li>\n<\/ol>\n<p><h3>\u4e94\u3001\u68c0\u67e5\u73af\u5883\u53d8\u91cf\u914d\u7f6e<\/h3>\n<\/p>\n<ol>\n<li>\n<p><strong>\u68c0\u67e5PATH\u73af\u5883\u53d8\u91cf<\/strong><\/p>\n<\/p>\n<ul>\n<li>\u786e\u4fddPython\u7684\u5b89\u88c5\u8def\u5f84\u5305\u542b\u5728\u7cfb\u7edf\u7684PATH\u73af\u5883\u53d8\u91cf\u4e2d\u3002<\/li>\n<li>\u5728\u7ec8\u7aef\u6216\u547d\u4ee4\u63d0\u793a\u7b26\u4e2d\u8f93\u5165<code>echo $PATH<\/code>\uff08Linux\/Mac\uff09\u6216<code>echo %PATH%<\/code>\uff08Windows\uff09\uff0c\u7136\u540e\u6309\u4e0b\u56de\u8f66\u952e\u3002<\/li>\n<li>\u68c0\u67e5\u8f93\u51fa\u4e2d\u662f\u5426\u5305\u542bPython\u7684\u5b89\u88c5\u8def\u5f84\u3002<\/li>\n<\/ul>\n<\/li>\n<li>\n<p><strong>\u914d\u7f6e\u73af\u5883\u53d8\u91cf<\/strong><\/p>\n<\/p>\n<ul>\n<li>\u5982\u679cPATH\u73af\u5883\u53d8\u91cf\u4e2d\u6ca1\u6709\u5305\u542bPython\u7684\u5b89\u88c5\u8def\u5f84\uff0c\u9700\u8981\u624b\u52a8\u6dfb\u52a0\u3002<\/li>\n<li>\u5728Windows\u7cfb\u7edf\u4e2d\uff0c\u53ef\u4ee5\u901a\u8fc7\u201c\u7cfb\u7edf\u5c5e\u6027\u201d\u4e2d\u7684\u201c\u73af\u5883\u53d8\u91cf\u201d\u8fdb\u884c\u914d\u7f6e\u3002<\/li>\n<li>\u5728Linux\/Mac\u7cfb\u7edf\u4e2d\uff0c\u53ef\u4ee5\u7f16\u8f91<code>~\/.bashrc<\/code>\u6216<code>~\/.zshrc<\/code>\u6587\u4ef6\uff0c\u6dfb\u52a0\u4ee5\u4e0b\u5185\u5bb9\uff1a\n<pre><code>export PATH=&quot;\/path\/to\/python:$PATH&quot;<\/p>\n<p><\/code><\/pre>\n<\/p>\n<\/li>\n<li>\u4fdd\u5b58\u6587\u4ef6\u5e76\u8fd0\u884c<code>source ~\/.bashrc<\/code>\u6216<code>source ~\/.zshrc<\/code>\u4ee5\u5e94\u7528\u66f4\u6539\u3002<\/li>\n<\/ul>\n<\/li>\n<\/ol>\n<p><h3>\u516d\u3001\u4f7f\u7528Python\u865a\u62df\u73af\u5883<\/h3>\n<\/p>\n<ol>\n<li>\n<p><strong>\u521b\u5efa\u865a\u62df\u73af\u5883<\/strong><\/p>\n<\/p>\n<ul>\n<li>\u5728\u7ec8\u7aef\u6216\u547d\u4ee4\u63d0\u793a\u7b26\u4e2d\uff0c\u5bfc\u822a\u5230\u4e00\u4e2a\u65b0\u7684\u6216\u73b0\u6709\u7684\u9879\u76ee\u76ee\u5f55\u3002<\/li>\n<li>\u8f93\u5165<code>python -m venv myenv<\/code>\u6216<code>python3 -m venv myenv<\/code>\uff0c\u7136\u540e\u6309\u4e0b\u56de\u8f66\u952e\u3002\u8fd9\u5c06\u521b\u5efa\u4e00\u4e2a\u540d\u4e3a<code>myenv<\/code>\u7684\u865a\u62df\u73af\u5883\u3002<\/li>\n<\/ul>\n<\/li>\n<li>\n<p><strong>\u6fc0\u6d3b\u865a\u62df\u73af\u5883<\/strong><\/p>\n<\/p>\n<ul>\n<li>\u5728Windows\u7cfb\u7edf\u4e2d\uff0c\u8f93\u5165<code>myenv\\Scripts\\activate<\/code>\uff0c\u7136\u540e\u6309\u4e0b\u56de\u8f66\u952e\u3002<\/li>\n<li>\u5728Linux\/Mac\u7cfb\u7edf\u4e2d\uff0c\u8f93\u5165<code>source myenv\/bin\/activate<\/code>\uff0c\u7136\u540e\u6309\u4e0b\u56de\u8f66\u952e\u3002<\/li>\n<li>\u4f60\u5c06\u770b\u5230\u7ec8\u7aef\u63d0\u793a\u7b26\u524d\u9762\u6dfb\u52a0\u4e86<code>(myenv)<\/code>\uff0c\u8868\u793a\u865a\u62df\u73af\u5883\u5df2\u6fc0\u6d3b\u3002<\/li>\n<\/ul>\n<\/li>\n<li>\n<p><strong>\u9a8c\u8bc1\u865a\u62df\u73af\u5883\u4e2d\u7684Python<\/strong><\/p>\n<\/p>\n<ul>\n<li>\u5728\u6fc0\u6d3b\u7684\u865a\u62df\u73af\u5883\u4e2d\uff0c\u8f93\u5165<code>python --version<\/code>\u6216<code>python3 --version<\/code>\uff0c\u7136\u540e\u6309\u4e0b\u56de\u8f66\u952e\u3002<\/li>\n<li>\u786e\u8ba4\u8f93\u51fa\u7684Python\u7248\u672c\u4e0e\u9884\u671f\u7684\u4e00\u81f4\u3002<\/li>\n<\/ul>\n<\/li>\n<\/ol>\n<p><h3>\u4e03\u3001\u4f7f\u7528\u96c6\u6210\u5f00\u53d1\u73af\u5883\uff08IDE\uff09<\/h3>\n<\/p>\n<ol>\n<li>\n<p><strong>\u9009\u62e9\u5e76\u5b89\u88c5IDE<\/strong><\/p>\n<\/p>\n<ul>\n<li>\u9009\u62e9\u4e00\u4e2a\u9002\u5408Python\u5f00\u53d1\u7684IDE\uff0c\u4f8b\u5982PyCharm\u3001VS Code\u3001Jupyter Notebook\u7b49\u3002<\/li>\n<li>\u4e0b\u8f7d\u5e76\u5b89\u88c5\u6240\u9009\u7684IDE\u3002<\/li>\n<\/ul>\n<\/li>\n<li>\n<p><strong>\u914d\u7f6ePython\u89e3\u91ca\u5668<\/strong><\/p>\n<\/p>\n<ul>\n<li>\u5728IDE\u4e2d\u914d\u7f6ePython\u89e3\u91ca\u5668\u3002\u901a\u5e38\u53ef\u4ee5\u5728IDE\u7684\u8bbe\u7f6e\u6216\u504f\u597d\u8bbe\u7f6e\u4e2d\u627e\u5230\u76f8\u5173\u9009\u9879\u3002<\/li>\n<li>\u9009\u62e9\u6b63\u786e\u7684Python\u89e3\u91ca\u5668\u8def\u5f84\uff0c\u786e\u4fdd\u4e0e\u7cfb\u7edf\u4e2d\u5b89\u88c5\u7684Python\u7248\u672c\u4e00\u81f4\u3002<\/li>\n<\/ul>\n<\/li>\n<li>\n<p><strong>\u8fd0\u884cPython\u4ee3\u7801<\/strong><\/p>\n<\/p>\n<ul>\n<li>\u5728IDE\u4e2d\u521b\u5efa\u4e00\u4e2a\u65b0\u7684Python\u9879\u76ee\u6216\u6587\u4ef6\uff0c\u5e76\u7f16\u5199\u7b80\u5355\u7684Python\u4ee3\u7801\u3002<\/li>\n<li>\u8fd0\u884c\u4ee3\u7801\u5e76\u68c0\u67e5\u8f93\u51fa\uff0c\u786e\u4fddPython\u73af\u5883\u914d\u7f6e\u6b63\u786e\u3002<\/li>\n<\/ul>\n<\/li>\n<\/ol>\n<p><h3>\u516b\u3001\u68c0\u67e5Python\u6a21\u5757\u548c\u4f9d\u8d56\u9879<\/h3>\n<\/p>\n<ol>\n<li>\n<p><strong>\u5217\u51fa\u5df2\u5b89\u88c5\u7684Python\u6a21\u5757<\/strong><\/p>\n<\/p>\n<ul>\n<li>\u5728\u7ec8\u7aef\u6216\u547d\u4ee4\u63d0\u793a\u7b26\u4e2d\u8f93\u5165<code>pip list<\/code>\u6216<code>pip3 list<\/code>\uff0c\u7136\u540e\u6309\u4e0b\u56de\u8f66\u952e\u3002<\/li>\n<li>\u4f60\u5c06\u770b\u5230\u7cfb\u7edf\u4e2d\u5df2\u5b89\u88c5\u7684\u6240\u6709Python\u6a21\u5757\u53ca\u5176\u7248\u672c\u53f7\u3002<\/li>\n<\/ul>\n<\/li>\n<li>\n<p><strong>\u68c0\u67e5\u7279\u5b9a\u6a21\u5757<\/strong><\/p>\n<\/p>\n<ul>\n<li>\u5982\u679c\u9700\u8981\u68c0\u67e5\u7279\u5b9a\u6a21\u5757\u662f\u5426\u5b89\u88c5\uff0c\u53ef\u4ee5\u8f93\u5165<code>pip show &lt;module_name&gt;<\/code>\u6216<code>pip3 show &lt;module_name&gt;<\/code>\uff0c\u7136\u540e\u6309\u4e0b\u56de\u8f66\u952e\u3002<\/li>\n<li>\u4f60\u5c06\u770b\u5230\u6a21\u5757\u7684\u8be6\u7ec6\u4fe1\u606f\uff0c\u5305\u62ec\u7248\u672c\u53f7\u3001\u5b89\u88c5\u8def\u5f84\u7b49\u3002<\/li>\n<\/ul>\n<\/li>\n<li>\n<p><strong>\u5b89\u88c5\u7f3a\u5931\u7684\u4f9d\u8d56\u9879<\/strong><\/p>\n<\/p>\n<ul>\n<li>\u5982\u679c\u67d0\u4e2a\u6a21\u5757\u6216\u4f9d\u8d56\u9879\u7f3a\u5931\uff0c\u53ef\u4ee5\u4f7f\u7528<code>pip install &lt;module_name&gt;<\/code>\u6216<code>pip3 install &lt;module_name&gt;<\/code>\u8fdb\u884c\u5b89\u88c5\u3002<\/li>\n<li>\u786e\u4fdd\u5b89\u88c5\u540e\u518d\u6b21\u8fd0\u884c\u4ee3\u7801\u4ee5\u9a8c\u8bc1\u4f9d\u8d56\u9879\u662f\u5426\u6b63\u786e\u5b89\u88c5\u3002<\/li>\n<\/ul>\n<\/li>\n<\/ol>\n<p><h3>\u4e5d\u3001\u68c0\u67e5\u7cfb\u7edf\u65e5\u5fd7\u548c\u9519\u8bef\u4fe1\u606f<\/h3>\n<\/p>\n<ol>\n<li>\n<p><strong>\u67e5\u770b\u5b89\u88c5\u65e5\u5fd7<\/strong><\/p>\n<\/p>\n<ul>\n<li>\u5728\u5b89\u88c5Python\u8fc7\u7a0b\u4e2d\uff0c\u68c0\u67e5\u7cfb\u7edf\u65e5\u5fd7\u6587\u4ef6\u4ee5\u83b7\u53d6\u8be6\u7ec6\u7684\u5b89\u88c5\u4fe1\u606f\u548c\u53ef\u80fd\u7684\u9519\u8bef\u63d0\u793a\u3002<\/li>\n<li>\u5728Windows\u7cfb\u7edf\u4e2d\uff0c\u53ef\u4ee5\u67e5\u770b<code>C:\\Users\\&lt;YourUsername&gt;\\AppData\\Local\\Temp<\/code>\u76ee\u5f55\u4e2d\u7684\u5b89\u88c5\u65e5\u5fd7\u6587\u4ef6\u3002<\/li>\n<li>\u5728Linux\/Mac\u7cfb\u7edf\u4e2d\uff0c\u53ef\u4ee5\u67e5\u770b\u7ec8\u7aef\u8f93\u51fa\u6216\u7cfb\u7edf\u65e5\u5fd7\u6587\u4ef6\u3002<\/li>\n<\/ul>\n<\/li>\n<li>\n<p><strong>\u89e3\u51b3\u5e38\u89c1\u9519\u8bef<\/strong><\/p>\n<\/p>\n<ul>\n<li>\u6839\u636e\u7cfb\u7edf\u65e5\u5fd7\u4e2d\u7684\u9519\u8bef\u63d0\u793a\uff0c\u67e5\u627e\u5e76\u89e3\u51b3\u5e38\u89c1\u7684\u5b89\u88c5\u95ee\u9898\u3002\u4f8b\u5982\uff0c\u7f3a\u5c11\u5fc5\u8981\u7684\u6743\u9650\u3001\u51b2\u7a81\u7684\u4f9d\u8d56\u9879\u7b49\u3002<\/li>\n<li>\u53c2\u8003Python\u5b98\u65b9\u6587\u6863\u6216\u793e\u533a\u8bba\u575b\u83b7\u53d6\u89e3\u51b3\u65b9\u6848\u3002<\/li>\n<\/ul>\n<\/li>\n<\/ol>\n<p><h3>\u5341\u3001\u6d4b\u8bd5Python\u7684\u529f\u80fd\u548c\u6027\u80fd<\/h3>\n<\/p>\n<ol>\n<li>\n<p><strong>\u7f16\u5199\u590d\u6742\u7684Python\u811a\u672c<\/strong><\/p>\n<\/p>\n<ul>\n<li>\u7f16\u5199\u5e76\u8fd0\u884c\u66f4\u590d\u6742\u7684Python\u811a\u672c\uff0c\u4ee5\u6d4b\u8bd5Python\u7684\u529f\u80fd\u548c\u6027\u80fd\u3002<\/li>\n<li>\u4f8b\u5982\uff0c\u4f7f\u7528Python\u8fdb\u884c\u6570\u636e\u5904\u7406\u3001\u6587\u4ef6\u64cd\u4f5c\u3001\u7f51\u7edc\u8bf7\u6c42\u7b49\u4efb\u52a1\u3002<\/li>\n<\/ul>\n<\/li>\n<li>\n<p><strong>\u4f7f\u7528Benchmark\u5de5\u5177<\/strong><\/p>\n<\/p>\n<ul>\n<li>\u4f7f\u7528Python\u7684\u6027\u80fd\u6d4b\u8bd5\u5de5\u5177\uff0c\u5982<code>timeit<\/code>\u6a21\u5757\u3001<code>cProfile<\/code>\u6a21\u5757\u7b49\uff0c\u5bf9Python\u4ee3\u7801\u8fdb\u884c\u6027\u80fd\u6d4b\u8bd5\u3002<\/li>\n<li>\u5206\u6790\u4ee3\u7801\u7684\u6267\u884c\u65f6\u95f4\u548c\u6027\u80fd\u74f6\u9888\uff0c\u4ee5\u786e\u4fddPython\u73af\u5883\u8fd0\u884c\u9ad8\u6548\u3002<\/li>\n<\/ul>\n<\/li>\n<\/ol>\n<p><h3>\u5341\u4e00\u3001\u68c0\u67e5Python\u7684\u5b89\u5168\u6027<\/h3>\n<\/p>\n<ol>\n<li>\n<p><strong>\u66f4\u65b0Python\u548c\u6a21\u5757<\/strong><\/p>\n<\/p>\n<ul>\n<li>\u5b9a\u671f\u66f4\u65b0Python\u548c\u5df2\u5b89\u88c5\u7684\u6a21\u5757\uff0c\u4ee5\u786e\u4fdd\u4f7f\u7528\u6700\u65b0\u7684\u5b89\u5168\u8865\u4e01\u548c\u529f\u80fd\u3002<\/li>\n<li>\u4f7f\u7528<code>pip install --upgrade &lt;module_name&gt;<\/code>\u6216<code>pip3 install --upgrade &lt;module_name&gt;<\/code>\u8fdb\u884c\u6a21\u5757\u66f4\u65b0\u3002<\/li>\n<\/ul>\n<\/li>\n<li>\n<p><strong>\u68c0\u67e5\u5df2\u77e5\u6f0f\u6d1e<\/strong><\/p>\n<\/p>\n<ul>\n<li>\u4f7f\u7528\u5de5\u5177\u5982<code><a href=\"https:\/\/docs.pingcode.com\/agile\/agile-at-scale\/what-is-safe\" target=\"_blank\">SAFe<\/a>ty<\/code>\u6216<code>Bandit<\/code>\u68c0\u67e5Python\u4ee3\u7801\u548c\u4f9d\u8d56\u9879\u4e2d\u7684\u5df2\u77e5\u6f0f\u6d1e\u3002<\/li>\n<li>\u5728\u7ec8\u7aef\u4e2d\u8f93\u5165<code>pip install safety<\/code>\u6216<code>pip3 install safety<\/code>\uff0c\u7136\u540e\u4f7f\u7528<code>safety check<\/code>\u547d\u4ee4\u8fdb\u884c\u5b89\u5168\u68c0\u67e5\u3002<\/li>\n<\/ul>\n<\/li>\n<\/ol>\n<p><h3>\u5341\u4e8c\u3001\u914d\u7f6e\u548c\u7ba1\u7406Python\u73af\u5883<\/h3>\n<\/p>\n<ol>\n<li>\n<p><strong>\u4f7f\u7528\u73af\u5883\u7ba1\u7406\u5de5\u5177<\/strong><\/p>\n<\/p>\n<ul>\n<li>\u4f7f\u7528\u5de5\u5177\u5982<code>pyenv<\/code>\u7ba1\u7406\u591a\u4e2aPython\u7248\u672c\u3002\u53ef\u4ee5\u8f7b\u677e\u5207\u6362\u548c\u7ba1\u7406\u4e0d\u540c\u9879\u76ee\u6240\u9700\u7684Python\u7248\u672c\u3002<\/li>\n<li>\u5728\u7ec8\u7aef\u4e2d\u8f93\u5165<code>pyenv install &lt;version&gt;<\/code>\u5b89\u88c5\u7279\u5b9a\u7248\u672c\u7684Python\uff0c\u5e76\u4f7f\u7528<code>pyenv global &lt;version&gt;<\/code>\u8bbe\u7f6e\u5168\u5c40Python\u7248\u672c\u3002<\/li>\n<\/ul>\n<\/li>\n<li>\n<p><strong>\u521b\u5efa\u5e76\u7ba1\u7406\u865a\u62df\u73af\u5883<\/strong><\/p>\n<\/p>\n<ul>\n<li>\u4f7f\u7528<code>virtualenv<\/code>\u5de5\u5177\u521b\u5efa\u548c\u7ba1\u7406\u865a\u62df\u73af\u5883\u3002\u53ef\u4ee5\u9694\u79bb\u9879\u76ee\u7684\u4f9d\u8d56\u9879\uff0c\u907f\u514d\u51b2\u7a81\u3002<\/li>\n<li>\u5728\u7ec8\u7aef\u4e2d\u8f93\u5165<code>virtualenv &lt;env_name&gt;<\/code>\u521b\u5efa\u865a\u62df\u73af\u5883\uff0c\u5e76\u4f7f\u7528<code>source &lt;env_name&gt;\/bin\/activate<\/code>\u6fc0\u6d3b\u865a\u62df\u73af\u5883\u3002<\/li>\n<\/ul>\n<\/li>\n<\/ol>\n<p><h3>\u5341\u4e09\u3001\u4f7f\u7528Python\u7684\u96c6\u6210\u5f00\u53d1\u5de5\u5177<\/h3>\n<\/p>\n<ol>\n<li>\n<p><strong>\u4f7f\u7528Jupyter Notebook<\/strong><\/p>\n<\/p>\n<ul>\n<li>\u5b89\u88c5\u5e76\u4f7f\u7528Jupyter Notebook\u8fdb\u884c\u4ea4\u4e92\u5f0f\u7f16\u7a0b\u548c\u6570\u636e\u5206\u6790\u3002<\/li>\n<li>\u5728\u7ec8\u7aef\u4e2d\u8f93\u5165<code>pip install jupyter<\/code>\u6216<code>pip3 install jupyter<\/code>\uff0c\u7136\u540e\u4f7f\u7528<code>jupyter notebook<\/code>\u547d\u4ee4\u542f\u52a8Jupyter Notebook\u3002<\/li>\n<\/ul>\n<\/li>\n<li>\n<p><strong>\u4f7f\u7528IDE\u8fdb\u884c\u8c03\u8bd5<\/strong><\/p>\n<\/p>\n<ul>\n<li>\u4f7f\u7528PyCharm\u3001VS Code\u7b49\u96c6\u6210\u5f00\u53d1\u73af\u5883\uff08IDE\uff09\u8fdb\u884cPython\u4ee3\u7801\u7684\u8c03\u8bd5\u3002<\/li>\n<li>\u914d\u7f6e\u65ad\u70b9\u3001\u53d8\u91cf\u76d1\u89c6\u7b49\u529f\u80fd\uff0c\u63d0\u9ad8\u5f00\u53d1\u6548\u7387\u548c\u4ee3\u7801\u8d28\u91cf\u3002<\/li>\n<\/ul>\n<\/li>\n<\/ol>\n<p><h3>\u5341\u56db\u3001\u5b66\u4e60\u548c\u63d0\u5347Python\u6280\u80fd<\/h3>\n<\/p>\n<ol>\n<li>\n<p><strong>\u5b66\u4e60Python\u57fa\u7840<\/strong><\/p>\n<\/p>\n<ul>\n<li>\u5b66\u4e60Python\u7684\u57fa\u7840\u8bed\u6cd5\u3001\u6570\u636e\u7c7b\u578b\u3001\u63a7\u5236\u7ed3\u6784\u7b49\u77e5\u8bc6\u3002<\/li>\n<li>\u53c2\u8003Python\u5b98\u65b9\u6587\u6863\u3001\u5728\u7ebf\u6559\u7a0b\u3001\u4e66\u7c4d\u7b49\u8d44\u6e90\u8fdb\u884c\u5b66\u4e60\u3002<\/li>\n<\/ul>\n<\/li>\n<li>\n<p><strong>\u63d0\u5347Python\u7f16\u7a0b\u80fd\u529b<\/strong><\/p>\n<\/p>\n<ul>\n<li>\u53c2\u4e0e\u5f00\u6e90\u9879\u76ee\u3001\u7f16\u5199\u5b9e\u9645\u9879\u76ee\u4ee3\u7801\uff0c\u63d0\u5347Python\u7f16\u7a0b\u80fd\u529b\u3002<\/li>\n<li>\u53c2\u52a0Python\u793e\u533a\u6d3b\u52a8\u3001\u6280\u672f\u4ea4\u6d41\u4f1a\uff0c\u4e0e\u5176\u4ed6\u5f00\u53d1\u8005\u4ea4\u6d41\u7ecf\u9a8c\u548c\u6280\u672f\u3002<\/li>\n<\/ul>\n<\/li>\n<\/ol>\n<p><p>\u901a\u8fc7\u4ee5\u4e0a\u65b9\u6cd5\uff0c\u53ef\u4ee5\u5168\u9762\u68c0\u9a8cPython\u4e0b\u8f7d\u662f\u5426\u6210\u529f\uff0c\u5e76\u786e\u4fddPython\u73af\u5883\u7684\u6b63\u5e38\u8fd0\u884c\u548c\u914d\u7f6e\u3002\u65e0\u8bba\u662f\u5728\u5f00\u53d1\u73af\u5883\u3001\u8fd0\u884c\u73af\u5883\u8fd8\u662f\u5b89\u5168\u6027\u65b9\u9762\uff0c\u90fd\u53ef\u4ee5\u8fdb\u884c\u6709\u6548\u7684\u9a8c\u8bc1\u548c\u7ba1\u7406\u3002<\/p>\n<\/p>\n<h2><strong>\u76f8\u5173\u95ee\u7b54FAQs\uff1a<\/strong><\/h2>\n<p> <strong>\u5982\u4f55\u786e\u8ba4\u6211\u4e0b\u8f7d\u7684Python\u7248\u672c\u662f\u5426\u6b63\u786e\uff1f<\/strong><br \/>\u5728\u4e0b\u8f7dPython\u540e\uff0c\u60a8\u53ef\u4ee5\u901a\u8fc7\u6253\u5f00\u547d\u4ee4\u884c\u754c\u9762\uff08Windows\u7528\u6237\u53ef\u4ee5\u4f7f\u7528CMD\uff0cMac\u548cLinux\u7528\u6237\u53ef\u4ee5\u4f7f\u7528\u7ec8\u7aef\uff09\u5e76\u8f93\u5165\u547d\u4ee4<code>python --version<\/code>\u6216<code>python3 --version<\/code>\u6765\u68c0\u67e5\u5df2\u5b89\u88c5\u7684Python\u7248\u672c\u3002\u5982\u679c\u547d\u4ee4\u884c\u8fd4\u56de\u7248\u672c\u53f7\uff0c\u8bf4\u660ePython\u5df2\u6b63\u786e\u5b89\u88c5\u5e76\u53ef\u4ee5\u6b63\u5e38\u4f7f\u7528\u3002<\/p>\n<p><strong>\u5982\u679cPython\u4e0b\u8f7d\u540e\u65e0\u6cd5\u8fd0\u884c\uff0c\u8be5\u5982\u4f55\u89e3\u51b3\uff1f<\/strong><br \/>\u5982\u679c\u60a8\u5728\u5c1d\u8bd5\u8fd0\u884cPython\u65f6\u9047\u5230\u95ee\u9898\uff0c\u53ef\u80fd\u662f\u56e0\u4e3a\u7cfb\u7edf\u73af\u5883\u53d8\u91cf\u672a\u6b63\u786e\u914d\u7f6e\u3002\u60a8\u53ef\u4ee5\u68c0\u67e5\u7cfb\u7edf\u8bbe\u7f6e\uff0c\u786e\u4fddPython\u7684\u5b89\u88c5\u8def\u5f84\u5df2\u6dfb\u52a0\u5230\u73af\u5883\u53d8\u91cf\u4e2d\u3002\u5728Windows\u4e0a\uff0c\u53ef\u4ee5\u901a\u8fc7\u201c\u7cfb\u7edf\u5c5e\u6027\u201d\u4e2d\u7684\u201c\u73af\u5883\u53d8\u91cf\u201d\u9009\u9879\u6765\u8fdb\u884c\u8bbe\u7f6e\uff1b\u5728Mac\u548cLinux\u4e0a\uff0c\u53ef\u4ee5\u901a\u8fc7\u4fee\u6539<code>.bash_profile<\/code>\u6216<code>.bashrc<\/code>\u6587\u4ef6\u6765\u6dfb\u52a0\u8def\u5f84\u3002<\/p>\n<p><strong>\u4e0b\u8f7d\u7684Python\u5305\u542b\u54ea\u4e9b\u5e38\u7528\u6a21\u5757\uff0c\u5982\u4f55\u9a8c\u8bc1\u5b83\u4eec\u662f\u5426\u6b63\u5e38\u5de5\u4f5c\uff1f<\/strong><br \/>\u4e0b\u8f7d\u7684Python\u901a\u5e38\u4f1a\u9884\u88c5\u4e00\u4e9b\u5e38\u7528\u6a21\u5757\uff0c\u4f8b\u5982<code>os<\/code>\u3001<code>sys<\/code>\u548c<code>math<\/code>\u7b49\u3002\u60a8\u53ef\u4ee5\u901a\u8fc7\u5728Python\u7684\u4ea4\u4e92\u5f0f\u547d\u4ee4\u884c\u4e2d\u8f93\u5165<code>import module_name<\/code>\uff08\u4f8b\u5982<code>import os<\/code>\uff09\u6765\u9a8c\u8bc1\u6a21\u5757\u662f\u5426\u6b63\u5e38\u5de5\u4f5c\u3002\u5982\u679c\u6ca1\u6709\u9519\u8bef\u63d0\u793a\uff0c\u8bf4\u660e\u8be5\u6a21\u5757\u5df2\u6210\u529f\u5b89\u88c5\u5e76\u53ef\u6b63\u5e38\u4f7f\u7528\u3002\u4e5f\u53ef\u4ee5\u901a\u8fc7\u7f16\u5199\u7b80\u5355\u7684\u4ee3\u7801\u6765\u6d4b\u8bd5\u6a21\u5757\u7684\u529f\u80fd\uff0c\u786e\u4fdd\u5b83\u4eec\u6309\u9884\u671f\u8fd0\u884c\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"\u8981\u68c0\u9a8cPython\u4e0b\u8f7d\u662f\u5426\u6210\u529f\uff0c\u53ef\u4ee5\u901a\u8fc7\u4ee5\u4e0b\u65b9\u6cd5\u8fdb\u884c\u9a8c\u8bc1\uff1a\u8fd0\u884cPython\u89e3\u91ca\u5668\u3001\u68c0\u67e5Python\u7248\u672c\u3001\u8fd0\u884cP [&hellip;]","protected":false},"author":3,"featured_media":1180714,"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\/1180701"}],"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=1180701"}],"version-history":[{"count":"1","href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1180701\/revisions"}],"predecessor-version":[{"id":1180719,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1180701\/revisions\/1180719"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media\/1180714"}],"wp:attachment":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media?parent=1180701"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/categories?post=1180701"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/tags?post=1180701"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}