{"id":116014,"date":"2026-10-20T15:40:50","date_gmt":"2026-10-20T07:40:50","guid":{"rendered":"https:\/\/www.wsisp.com\/helps\/116014.html"},"modified":"2026-10-20T15:40:50","modified_gmt":"2026-10-20T07:40:50","slug":"ubuntu-%e6%9c%8d%e5%8a%a1%e5%99%a8%e5%ae%89%e8%a3%85-python-%e6%95%99%e7%a8%8b","status":"publish","type":"post","link":"https:\/\/www.wsisp.com\/helps\/116014.html","title":{"rendered":"Ubuntu \u670d\u52a1\u5668\u5b89\u88c5 Python \u6559\u7a0b"},"content":{"rendered":"<p>        \/* MD \/ \u5bcc\u6587\u672c\u4e2d\u7684 .toc\uff08\u542b\u535a\u5ba2\u56ed\u642c\u5bb6\u7b49\u5d4c\u5957\u7ed3\u6784\uff09\uff1b.toc-box \u5728\u4fa7\u680f\uff0c\u4e0d\u53d7\u5f71\u54cd *\/<br \/>\n        #content_views .toc,<br \/>\n        \/* \u7f16\u8f91\u5668\u5e38\u5728\u76ee\u5f55\u524d\u540e\u63d2\u5165\u7a7a p\uff08:empty \u4ecd\u5360 20px\uff09\uff0c\u4e00\u5e76\u53bb\u6389\u907f\u514d\u9876\u7a7a\u9699 *\/<br \/>\n        #content_views.markdown_views &gt; p:empty:has(+ .toc),<br \/>\n        #content_views.markdown_views &gt; .toc + p:empty,<br \/>\n        \/* \u5bcc\u6587\u672c\u65e7\u7248\u76ee\u5f55\u6807\u8bb0 *\/<br \/>\n        #content_views.htmledit_views #main-toc,<br \/>\n        #content_views.htmledit_views #hr-toc,<br \/>\n        #content_views.htmledit_views p[id*=\\&#8221;-toc\\&#8221;] {<br \/>\n          display: none !important;<br \/>\n        }<br \/>\n        \/* \u76ee\u5f55\u53bb\u6389\u540e\uff0c\u7d27\u8ddf\u7684\u9996\u4e2a\u6807\u9898\u4e0d\u518d\u591a\u51fa\u4e00\u5757\u4e0a\u8fb9\u8ddd *\/<br \/>\n        #content_views.markdown_views &gt; .toc + h1,<br \/>\n        #content_views.markdown_views &gt; .toc + h2,<br \/>\n        #content_views.markdown_views &gt; .toc + h3,<br \/>\n        #content_views.markdown_views &gt; .toc + h4,<br \/>\n        #content_views.markdown_views &gt; .toc + p:empty + h1,<br \/>\n        #content_views.markdown_views &gt; .toc + p:empty + h2,<br \/>\n        #content_views.markdown_views &gt; .toc + p:empty + h3,<br \/>\n        #content_views.markdown_views &gt; .toc + p:empty + h4 {<br \/>\n          margin-top: 0 !important;<br \/>\n        }<\/p>\n<p>\u672c\u6559\u7a0b\u4ee5 Ubuntu 24.04 LTS \u4e3a\u4f8b\u3002<\/p>\n<p>\u9002\u5408\u7b2c\u4e00\u6b21\u5728 Linux \u670d\u52a1\u5668\u4e0a\u5b89\u88c5 Python \u7684\u7528\u6237\u3002<\/p>\n<p>\u6700\u7ec8\u76ee\u6807&#xff1a;<\/p>\n<ul>\n<li>\u5b89\u88c5 Python 3<\/li>\n<li>\u5b89\u88c5 pip<\/li>\n<li>\u914d\u7f6e python \u547d\u4ee4<\/li>\n<li>\u521b\u5efa Python \u865a\u62df\u73af\u5883<\/li>\n<li>\u5b89\u88c5\u7b2c\u4e09\u65b9\u4f9d\u8d56<\/li>\n<li>\u638c\u63e1\u57fa\u672c\u7684 Python \u9879\u76ee\u8fd0\u884c\u65b9\u5f0f<\/li>\n<\/ul>\n<hr \/>\n<h3>\u4e00\u3001\u5148\u7406\u89e3 Python\u3001pip \u548c\u865a\u62df\u73af\u5883<\/h3>\n<p>\u5728\u5f00\u59cb\u4e4b\u524d&#xff0c;\u5148\u641e\u6e05\u695a\u51e0\u4e2a\u6982\u5ff5\u3002<\/p>\n<h4>1. Python \u662f\u4ec0\u4e48&#xff1f;<\/h4>\n<p>Python \u662f\u7f16\u7a0b\u8bed\u8a00\u548c\u8fd0\u884c\u73af\u5883\u3002<\/p>\n<p>\u4f8b\u5982&#xff1a;<\/p>\n<p>python3 <span class=\"token parameter variable\">&#8211;version<\/span><\/p>\n<p>\u53ef\u4ee5\u67e5\u770b Python \u7248\u672c&#xff1a;<\/p>\n<p>Python 3.12.3<\/p>\n<hr \/>\n<h4>2. pip \u662f\u4ec0\u4e48&#xff1f;<\/h4>\n<p>pip \u662f Python \u7684\u7b2c\u4e09\u65b9\u8f6f\u4ef6\u5305\u7ba1\u7406\u5de5\u5177\u3002<\/p>\n<p>\u4f8b\u5982\u4f60\u7684\u9879\u76ee\u9700\u8981&#xff1a;<\/p>\n<p>FastAPI<br \/>\nRequests<br \/>\nDjango<br \/>\nPyMySQL<br \/>\nRedis<\/p>\n<p>\u5c31\u53ef\u4ee5\u901a\u8fc7 pip \u5b89\u88c5&#xff1a;<\/p>\n<p>pip <span class=\"token function\">install<\/span> requests<\/p>\n<p>\u53ef\u4ee5\u7b80\u5355\u7406\u89e3\u4e3a&#xff1a;<\/p>\n<p>Python<br \/>\n  \u2193<br \/>\n\u8fd0\u884c Python \u7a0b\u5e8f<\/p>\n<p>pip<br \/>\n  \u2193<br \/>\n\u5b89\u88c5 Python \u7b2c\u4e09\u65b9\u5e93<\/p>\n<hr \/>\n<h4>3. \u865a\u62df\u73af\u5883\u662f\u4ec0\u4e48&#xff1f;<\/h4>\n<p>\u5047\u8bbe\u670d\u52a1\u5668\u4e0a\u6709\u4e24\u4e2a\u9879\u76ee&#xff1a;<\/p>\n<p>\u9879\u76ee A \u2192 requests 2.x<br \/>\n\u9879\u76ee B \u2192 requests 3.x<\/p>\n<p>\u5982\u679c\u6240\u6709\u4f9d\u8d56\u90fd\u5b89\u88c5\u5230\u7cfb\u7edf Python \u4e2d&#xff0c;\u5c31\u5bb9\u6613\u53d1\u751f\u7248\u672c\u51b2\u7a81\u3002<\/p>\n<p>\u865a\u62df\u73af\u5883\u5c31\u662f\u7ed9\u6bcf\u4e2a\u9879\u76ee\u51c6\u5907\u4e00\u4e2a\u72ec\u7acb\u7684 Python \u73af\u5883&#xff1a;<\/p>\n<p>\u670d\u52a1\u5668<br \/>\n\u2502<br \/>\n\u251c\u2500\u2500 \u7cfb\u7edf Python<br \/>\n\u2502<br \/>\n\u251c\u2500\u2500 \u9879\u76ee A<br \/>\n\u2502   \u2514\u2500\u2500 .venv<br \/>\n\u2502       \u2514\u2500\u2500 Python &#043; \u9879\u76ee\u4f9d\u8d56<br \/>\n\u2502<br \/>\n\u2514\u2500\u2500 \u9879\u76ee B<br \/>\n    \u2514\u2500\u2500 .venv<br \/>\n        \u2514\u2500\u2500 Python &#043; \u9879\u76ee\u4f9d\u8d56<\/p>\n<p>\u56e0\u6b64&#xff1a;<\/p>\n<p>\u670d\u52a1\u5668\u5b89\u88c5 Python \u2260 \u7ed9\u6240\u6709\u9879\u76ee\u5171\u7528\u4e00\u4e2a Python \u73af\u5883\u3002<\/p>\n<p>\u63a8\u8350&#xff1a;<\/p>\n<p>\u7cfb\u7edf Python \u8d1f\u8d23\u7cfb\u7edf\u672c\u8eab&#xff0c;\u9879\u76ee\u4f7f\u7528\u81ea\u5df1\u7684\u865a\u62df\u73af\u5883\u3002<\/p>\n<hr \/>\n<h2>\u4e8c\u3001\u68c0\u67e5\u670d\u52a1\u5668\u662f\u5426\u5df2\u7ecf\u5b89\u88c5 Python<\/h2>\n<p>\u767b\u5f55\u670d\u52a1\u5668&#xff1a;<\/p>\n<p><span class=\"token function\">ssh<\/span> \u7528\u6237\u540d&#064;\u670d\u52a1\u5668IP<\/p>\n<p>\u4f8b\u5982&#xff1a;<\/p>\n<p><span class=\"token function\">ssh<\/span> ayy&#064;192.168.0.10<\/p>\n<p>\u767b\u5f55\u4ee5\u540e\u6267\u884c&#xff1a;<\/p>\n<p>python3 <span class=\"token parameter variable\">&#8211;version<\/span><\/p>\n<p>\u5982\u679c\u770b\u5230&#xff1a;<\/p>\n<p>Python 3.12.3<\/p>\n<p>\u8bf4\u660e Python \u5df2\u7ecf\u5b89\u88c5\u3002<\/p>\n<p>\u518d\u6267\u884c&#xff1a;<\/p>\n<p><span class=\"token function\">which<\/span> python3<\/p>\n<p>\u5982\u679c\u770b\u5230&#xff1a;<\/p>\n<p>\/usr\/bin\/python3<\/p>\n<p>\u8bf4\u660e\u5f53\u524d\u4f7f\u7528\u7684\u662f Ubuntu \u7cfb\u7edf\u81ea\u5e26\u7684 Python\u3002<\/p>\n<hr \/>\n<h2>\u4e09\u3001\u5982\u679c\u6ca1\u6709 Python&#xff0c;\u5b89\u88c5 Python<\/h2>\n<p>Ubuntu \u53ef\u4ee5\u76f4\u63a5\u901a\u8fc7 APT \u5b89\u88c5\u3002<\/p>\n<p>\u9996\u5148\u66f4\u65b0\u8f6f\u4ef6\u5305\u7d22\u5f15&#xff1a;<\/p>\n<p><span class=\"token function\">sudo<\/span> <span class=\"token function\">apt<\/span> update<\/p>\n<p>\u7136\u540e\u5b89\u88c5 Python&#xff1a;<\/p>\n<p><span class=\"token function\">sudo<\/span> <span class=\"token function\">apt<\/span> <span class=\"token function\">install<\/span> <span class=\"token parameter variable\">-y<\/span> python3<\/p>\n<p>\u5b89\u88c5\u5b8c\u6210\u4ee5\u540e&#xff1a;<\/p>\n<p>python3 <span class=\"token parameter variable\">&#8211;version<\/span><\/p>\n<p>\u4f8b\u5982&#xff1a;<\/p>\n<p>Python 3.12.3<\/p>\n<p>\u518d\u68c0\u67e5&#xff1a;<\/p>\n<p><span class=\"token function\">which<\/span> python3<\/p>\n<p>\u901a\u5e38\u4f1a\u5f97\u5230&#xff1a;<\/p>\n<p>\/usr\/bin\/python3<\/p>\n<hr \/>\n<h2>\u56db\u3001\u5b89\u88c5 pip<\/h2>\n<p>\u8fd9\u4e00\u6b65\u975e\u5e38\u91cd\u8981\u3002<\/p>\n<p>\u521a\u5b89\u88c5\u5b8c Python \u540e&#xff0c;\u53ef\u80fd\u51fa\u73b0&#xff1a;<\/p>\n<p>pip3 <span class=\"token parameter variable\">&#8211;version<\/span><\/p>\n<p>\u7136\u540e\u63d0\u793a&#xff1a;<\/p>\n<p>Command &#039;pip3&#039; not found<\/p>\n<p>\u8fd9\u5e76\u4e0d\u4ee3\u8868 Python \u5b89\u88c5\u5931\u8d25\u3002<\/p>\n<p>\u53ea\u662f\u8bf4\u660e&#xff1a;<\/p>\n<p>Python \u5df2\u7ecf\u5b89\u88c5&#xff0c;\u4f46 pip \u8fd8\u6ca1\u6709\u5b89\u88c5\u3002<\/p>\n<p>\u6267\u884c&#xff1a;<\/p>\n<p><span class=\"token function\">sudo<\/span> <span class=\"token function\">apt<\/span> <span class=\"token function\">install<\/span> <span class=\"token parameter variable\">-y<\/span> python3-pip<\/p>\n<p>\u5b89\u88c5\u5b8c\u6210\u4ee5\u540e&#xff1a;<\/p>\n<p>pip3 <span class=\"token parameter variable\">&#8211;version<\/span><\/p>\n<p>\u4e5f\u53ef\u4ee5\u4f7f\u7528\u66f4\u63a8\u8350\u7684\u65b9\u5f0f&#xff1a;<\/p>\n<p>python3 <span class=\"token parameter variable\">-m<\/span> pip <span class=\"token parameter variable\">&#8211;version<\/span><\/p>\n<p>\u5982\u679c\u6b63\u5e38&#xff0c;\u4f1a\u770b\u5230\u7c7b\u4f3c&#xff1a;<\/p>\n<p>pip 24.x from \/usr\/lib\/python3\/dist-packages\/pip<\/p>\n<hr \/>\n<h2>\u4e94\u3001\u5b89\u88c5\u865a\u62df\u73af\u5883\u529f\u80fd<\/h2>\n<p>Ubuntu \u4e2d\u8fd8\u9700\u8981\u5b89\u88c5 venv\u3002<\/p>\n<p>\u6267\u884c&#xff1a;<\/p>\n<p><span class=\"token function\">sudo<\/span> <span class=\"token function\">apt<\/span> <span class=\"token function\">install<\/span> <span class=\"token parameter variable\">-y<\/span> python3-venv<\/p>\n<p>\u4e3a\u4ec0\u4e48\u9700\u8981\u5b83&#xff1f;<\/p>\n<p>\u56e0\u4e3a\u540e\u9762\u521b\u5efa\u9879\u76ee\u865a\u62df\u73af\u5883\u65f6\u9700\u8981&#xff1a;<\/p>\n<p>python3 <span class=\"token parameter variable\">-m<\/span> venv .venv<\/p>\n<p>\u5982\u679c\u6ca1\u6709\u5b89\u88c5 python3-venv&#xff0c;\u53ef\u80fd\u4f1a\u51fa\u73b0\u7c7b\u4f3c&#xff1a;<\/p>\n<p>The virtual environment was not created successfully<\/p>\n<p>\u6240\u4ee5\u63a8\u8350\u4e00\u6b21\u5b89\u88c5&#xff1a;<\/p>\n<p><span class=\"token function\">sudo<\/span> <span class=\"token function\">apt<\/span> <span class=\"token function\">install<\/span> <span class=\"token parameter variable\">-y<\/span> python3-pip python3-venv<\/p>\n<hr \/>\n<h2>\u516d\u3001\u662f\u5426\u9700\u8981\u5b89\u88c5 python \u547d\u4ee4&#xff1f;<\/h2>\n<p>Ubuntu \u9ed8\u8ba4\u53ef\u80fd\u53ea\u6709&#xff1a;<\/p>\n<p>python3<\/p>\n<p>\u6267\u884c&#xff1a;<\/p>\n<p>python <span class=\"token parameter variable\">&#8211;version<\/span><\/p>\n<p>\u53ef\u80fd\u5f97\u5230&#xff1a;<\/p>\n<p>Command &#039;python&#039; not found<\/p>\n<p>\u8fd9\u4e5f\u662f\u6b63\u5e38\u7684\u3002<\/p>\n<p>Ubuntu \u660e\u786e\u533a\u5206&#xff1a;<\/p>\n<p>python3<\/p>\n<p>\u548c&#xff1a;<\/p>\n<p>python<\/p>\n<p>\u5982\u679c\u5e0c\u671b\u4ee5\u540e\u76f4\u63a5\u4f7f\u7528&#xff1a;<\/p>\n<p>python<\/p>\n<p>\u6765\u4ee3\u8868 Python 3&#xff0c;\u53ef\u4ee5\u5b89\u88c5&#xff1a;<\/p>\n<p><span class=\"token function\">sudo<\/span> <span class=\"token function\">apt<\/span> <span class=\"token function\">install<\/span> <span class=\"token parameter variable\">-y<\/span> python-is-python3<\/p>\n<p>\u7136\u540e&#xff1a;<\/p>\n<p>python <span class=\"token parameter variable\">&#8211;version<\/span><\/p>\n<p>\u5c31\u4f1a\u5f97\u5230&#xff1a;<\/p>\n<p>Python 3.12.3<\/p>\n<p>\u53ef\u4ee5\u7406\u89e3\u4e3a&#xff1a;<\/p>\n<p>python<br \/>\n  \u2193<br \/>\npython3<br \/>\n  \u2193<br \/>\nPython 3.12.3<\/p>\n<hr \/>\n<h2>\u4e03\u3001\u63a8\u8350\u4e00\u6b21\u6027\u5b89\u88c5\u57fa\u7840 Python \u73af\u5883<\/h2>\n<p>\u5982\u679c\u662f\u4e00\u53f0\u521a\u51c6\u5907\u597d\u7684 Ubuntu \u670d\u52a1\u5668&#xff0c;\u53ef\u4ee5\u76f4\u63a5\u6267\u884c&#xff1a;<\/p>\n<p><span class=\"token function\">sudo<\/span> <span class=\"token function\">apt<\/span> update<\/p>\n<p><span class=\"token function\">sudo<\/span> <span class=\"token function\">apt<\/span> <span class=\"token function\">install<\/span> <span class=\"token parameter variable\">-y<\/span> <span class=\"token punctuation\">\\\\<\/span><br \/>\n    python3 <span class=\"token punctuation\">\\\\<\/span><br \/>\n    python3-pip <span class=\"token punctuation\">\\\\<\/span><br \/>\n    python3-venv <span class=\"token punctuation\">\\\\<\/span><br \/>\n    python-is-python3<\/p>\n<p>\u5b89\u88c5\u5b8c\u6210\u4ee5\u540e\u68c0\u67e5&#xff1a;<\/p>\n<p>python3 <span class=\"token parameter variable\">&#8211;version<\/span><\/p>\n<p>python <span class=\"token parameter variable\">&#8211;version<\/span><\/p>\n<p>python3 <span class=\"token parameter variable\">-m<\/span> pip <span class=\"token parameter variable\">&#8211;version<\/span><\/p>\n<p>pip3 <span class=\"token parameter variable\">&#8211;version<\/span><\/p>\n<p><span class=\"token function\">which<\/span> python3<\/p>\n<p><span class=\"token function\">which<\/span> python<\/p>\n<p>\u6b63\u5e38\u60c5\u51b5\u4e0b\u7c7b\u4f3c&#xff1a;<\/p>\n<p>Python 3.12.3<br \/>\nPython 3.12.3<br \/>\npip 24.x<br \/>\npip 24.x<br \/>\n\/usr\/bin\/python3<br \/>\n\/usr\/bin\/python<\/p>\n<hr \/>\n<h2>\u516b\u3001\u521b\u5efa\u7b2c\u4e00\u4e2a Python \u9879\u76ee<\/h2>\n<p>\u4e0d\u8981\u76f4\u63a5\u5728 \/usr\/bin \u6216\u7cfb\u7edf\u76ee\u5f55\u91cc\u9762\u5f00\u53d1\u3002<\/p>\n<p>\u5efa\u8bae\u521b\u5efa\u81ea\u5df1\u7684\u9879\u76ee\u76ee\u5f55\u3002<\/p>\n<p>\u4f8b\u5982&#xff1a;<\/p>\n<p><span class=\"token function\">mkdir<\/span> <span class=\"token parameter variable\">-p<\/span> ~\/projects\/python-demo<\/p>\n<p>\u8fdb\u5165\u9879\u76ee&#xff1a;<\/p>\n<p><span class=\"token builtin class-name\">cd<\/span> ~\/projects\/python-demo<\/p>\n<p>\u67e5\u770b\u5f53\u524d\u4f4d\u7f6e&#xff1a;<\/p>\n<p><span class=\"token builtin class-name\">pwd<\/span><\/p>\n<p>\u4f8b\u5982&#xff1a;<\/p>\n<p>\/home\/ayy\/projects\/python-demo<\/p>\n<hr \/>\n<h2>\u4e5d\u3001\u521b\u5efa Python \u865a\u62df\u73af\u5883<\/h2>\n<p>\u5728\u9879\u76ee\u76ee\u5f55\u6267\u884c&#xff1a;<\/p>\n<p>python3 <span class=\"token parameter variable\">-m<\/span> venv .venv<\/p>\n<p>\u8fd9\u91cc&#xff1a;<\/p>\n<p>python3<\/p>\n<p>\u8868\u793a\u4f7f\u7528 Python 3\u3002<\/p>\n<p>-m venv<\/p>\n<p>\u8868\u793a\u4f7f\u7528 Python \u81ea\u5e26\u7684\u865a\u62df\u73af\u5883\u6a21\u5757\u3002<\/p>\n<p>.venv<\/p>\n<p>\u8868\u793a\u628a\u865a\u62df\u73af\u5883\u521b\u5efa\u5230 .venv \u76ee\u5f55\u3002<\/p>\n<p>\u6700\u7ec8&#xff1a;<\/p>\n<p>python-demo\/<br \/>\n\u2514\u2500\u2500 .venv\/<\/p>\n<hr \/>\n<h2>\u5341\u3001\u6fc0\u6d3b\u865a\u62df\u73af\u5883<\/h2>\n<p>\u6267\u884c&#xff1a;<\/p>\n<p><span class=\"token builtin class-name\">source<\/span> .venv\/bin\/activate<\/p>\n<p>\u6210\u529f\u4ee5\u540e&#xff0c;\u547d\u4ee4\u884c\u524d\u9762\u901a\u5e38\u4f1a\u51fa\u73b0&#xff1a;<\/p>\n<p>(.venv)<\/p>\n<p>\u4f8b\u5982&#xff1a;<\/p>\n<p>(.venv) ayy&#064;server:~\/projects\/python-demo$<\/p>\n<p>\u8fd9\u8868\u793a&#xff1a;<\/p>\n<p>\u5f53\u524d\u7ec8\u7aef\u5df2\u7ecf\u8fdb\u5165 Python \u865a\u62df\u73af\u5883\u3002<\/p>\n<hr \/>\n<h2>\u5341\u4e00\u3001\u68c0\u67e5\u865a\u62df\u73af\u5883\u662f\u5426\u751f\u6548<\/h2>\n<p>\u6267\u884c&#xff1a;<\/p>\n<p>python <span class=\"token parameter variable\">&#8211;version<\/span><\/p>\n<p>\u7136\u540e&#xff1a;<\/p>\n<p><span class=\"token function\">which<\/span> python<\/p>\n<p>\u6b63\u5e38\u5e94\u8be5\u770b\u5230\u7c7b\u4f3c&#xff1a;<\/p>\n<p>Python 3.12.3<\/p>\n<p>\u4ee5\u53ca&#xff1a;<\/p>\n<p>\/home\/ayy\/projects\/python-demo\/.venv\/bin\/python<\/p>\n<p>\u6ce8\u610f\u8fd9\u91cc\u5df2\u7ecf\u4e0d\u662f&#xff1a;<\/p>\n<p>\/usr\/bin\/python3<\/p>\n<p>\u800c\u662f&#xff1a;<\/p>\n<p>~\/projects\/python-demo\/.venv\/bin\/python<\/p>\n<p>\u8fd9\u8bf4\u660e\u865a\u62df\u73af\u5883\u5df2\u7ecf\u751f\u6548\u3002<\/p>\n<hr \/>\n<h2>\u5341\u4e8c\u3001\u5347\u7ea7 pip<\/h2>\n<p>\u8fdb\u5165\u865a\u62df\u73af\u5883\u4ee5\u540e&#xff0c;\u5efa\u8bae\u5347\u7ea7 pip&#xff1a;<\/p>\n<p>python <span class=\"token parameter variable\">-m<\/span> pip <span class=\"token function\">install<\/span> <span class=\"token parameter variable\">&#8211;upgrade<\/span> pip<\/p>\n<p>\u7136\u540e\u68c0\u67e5&#xff1a;<\/p>\n<p>python <span class=\"token parameter variable\">-m<\/span> pip <span class=\"token parameter variable\">&#8211;version<\/span><\/p>\n<p>\u63a8\u8350\u4ee5\u540e\u4f7f\u7528&#xff1a;<\/p>\n<p>python <span class=\"token parameter variable\">-m<\/span> pip<\/p>\n<p>\u4f8b\u5982&#xff1a;<\/p>\n<p>python <span class=\"token parameter variable\">-m<\/span> pip <span class=\"token function\">install<\/span> requests<\/p>\n<p>\u800c\u4e0d\u662f\u7b80\u5355\u4f7f\u7528&#xff1a;<\/p>\n<p>pip <span class=\"token function\">install<\/span> requests<\/p>\n<p>\u539f\u56e0\u662f&#xff1a;<\/p>\n<p>python -m pip<\/p>\n<p>\u53ef\u4ee5\u660e\u786e\u8868\u793a&#xff1a;<\/p>\n<p>\u4f7f\u7528\u5f53\u524d\u8fd9\u4e2a Python \u5bf9\u5e94\u7684 pip\u3002<\/p>\n<p>\u5bf9\u4e8e\u670d\u52a1\u5668\u5b58\u5728\u591a\u4e2a Python \u7248\u672c\u7684\u60c5\u51b5&#xff0c;\u8fd9\u79cd\u5199\u6cd5\u66f4\u52a0\u5b89\u5168\u3002<\/p>\n<hr \/>\n<h2>\u5341\u4e09\u3001\u5b89\u88c5\u7b2c\u4e00\u4e2a Python \u7b2c\u4e09\u65b9\u5e93<\/h2>\n<p>\u4f8b\u5982\u5b89\u88c5 requests&#xff1a;<\/p>\n<p>python <span class=\"token parameter variable\">-m<\/span> pip <span class=\"token function\">install<\/span> requests<\/p>\n<p>\u5b89\u88c5\u5b8c\u6210\u4ee5\u540e&#xff1a;<\/p>\n<p>python <span class=\"token parameter variable\">-m<\/span> pip list<\/p>\n<p>\u5e94\u8be5\u53ef\u4ee5\u770b\u5230&#xff1a;<\/p>\n<p>requests<\/p>\n<p>\u6d4b\u8bd5&#xff1a;<\/p>\n<p>python <span class=\"token parameter variable\">-c<\/span> <span class=\"token string\">&#034;import requests; print(requests.__version__)&#034;<\/span><\/p>\n<p>\u5982\u679c\u80fd\u591f\u6b63\u5e38\u8f93\u51fa\u7248\u672c\u53f7&#xff0c;\u8bf4\u660e\u5b89\u88c5\u6210\u529f\u3002<\/p>\n<hr \/>\n<h2>\u5341\u56db\u3001\u7f16\u5199\u7b2c\u4e00\u4e2a Python \u7a0b\u5e8f<\/h2>\n<p>\u521b\u5efa&#xff1a;<\/p>\n<p><span class=\"token function\">vim<\/span> hello.py<\/p>\n<p>\u8f93\u5165&#xff1a;<\/p>\n<p><span class=\"token keyword\">print<\/span><span class=\"token punctuation\">(<\/span><span class=\"token string\">&#034;Hello Python!&#034;<\/span><span class=\"token punctuation\">)<\/span><\/p>\n<p>\u4fdd\u5b58\u4ee5\u540e\u6267\u884c&#xff1a;<\/p>\n<p>python hello.py<\/p>\n<p>\u8f93\u51fa&#xff1a;<\/p>\n<p>Hello Python!<\/p>\n<p>\u606d\u559c&#xff0c;\u4f60\u5df2\u7ecf\u5b8c\u6210&#xff1a;<\/p>\n<p>\u670d\u52a1\u5668<br \/>\n  \u2193<br \/>\nPython<br \/>\n  \u2193<br \/>\npip<br \/>\n  \u2193<br \/>\n\u865a\u62df\u73af\u5883<br \/>\n  \u2193<br \/>\n\u7b2c\u4e09\u65b9\u5e93<br \/>\n  \u2193<br \/>\nPython \u7a0b\u5e8f<\/p>\n<hr \/>\n<h2>\u5341\u4e94\u3001\u9000\u51fa\u865a\u62df\u73af\u5883<\/h2>\n<p>\u4f7f\u7528\u5b8c\u4ee5\u540e&#xff1a;<\/p>\n<p>deactivate<\/p>\n<p>\u524d\u9762\u7684&#xff1a;<\/p>\n<p>(.venv)<\/p>\n<p>\u5c31\u4f1a\u6d88\u5931\u3002<\/p>\n<p>\u518d\u6b21\u8fdb\u5165\u9879\u76ee\u65f6&#xff1a;<\/p>\n<p><span class=\"token builtin class-name\">cd<\/span> ~\/projects\/python-demo<\/p>\n<p>\u7136\u540e&#xff1a;<\/p>\n<p><span class=\"token builtin class-name\">source<\/span> .venv\/bin\/activate<\/p>\n<p>\u5373\u53ef\u91cd\u65b0\u8fdb\u5165\u3002<\/p>\n<hr \/>\n<h2>\u5341\u516d\u3001Python \u9879\u76ee\u4e3a\u4ec0\u4e48\u9700\u8981 requirements.txt&#xff1f;<\/h2>\n<p>\u5b9e\u9645\u9879\u76ee\u901a\u5e38\u4f1a\u4f9d\u8d56\u5f88\u591a Python \u5e93\u3002<\/p>\n<p>\u4f8b\u5982&#xff1a;<\/p>\n<p>FastAPI<br \/>\nUvicorn<br \/>\nRequests<br \/>\nRedis<br \/>\nPyMySQL<\/p>\n<p>\u5982\u679c\u628a\u9879\u76ee\u90e8\u7f72\u5230\u53e6\u4e00\u53f0\u670d\u52a1\u5668&#xff0c;\u4e0d\u53ef\u80fd\u4e00\u4e2a\u4e00\u4e2a\u8bb0\u4f4f\u3002<\/p>\n<p>\u6240\u4ee5 Python \u9879\u76ee\u901a\u5e38\u4f7f\u7528&#xff1a;<\/p>\n<p>requirements.txt<\/p>\n<p>\u4f8b\u5982&#xff1a;<\/p>\n<p>fastapi&#061;&#061;0.116.1<br \/>\nuvicorn&#061;&#061;0.35.0<br \/>\nrequests&#061;&#061;2.32.5<\/p>\n<p>\u5b89\u88c5\u6240\u6709\u4f9d\u8d56&#xff1a;<\/p>\n<p>python <span class=\"token parameter variable\">-m<\/span> pip <span class=\"token function\">install<\/span> <span class=\"token parameter variable\">-r<\/span> requirements.txt<\/p>\n<p>\u8fd9\u6837\u90e8\u7f72\u9879\u76ee\u5c31\u7b80\u5355\u5f88\u591a\u3002<\/p>\n<hr \/>\n<h2>\u5341\u4e03\u3001\u751f\u6210 requirements.txt<\/h2>\n<p>\u5982\u679c\u5f53\u524d\u865a\u62df\u73af\u5883\u5df2\u7ecf\u5b89\u88c5\u597d\u4e86\u9879\u76ee\u4f9d\u8d56&#xff1a;<\/p>\n<p>python <span class=\"token parameter variable\">-m<\/span> pip freeze <span class=\"token operator\">&gt;<\/span> requirements.txt<\/p>\n<p>\u67e5\u770b&#xff1a;<\/p>\n<p><span class=\"token function\">cat<\/span> requirements.txt<\/p>\n<p>\u4f8b\u5982&#xff1a;<\/p>\n<p>fastapi&#061;&#061;0.116.1<br \/>\nrequests&#061;&#061;2.32.5<br \/>\nuvicorn&#061;&#061;0.35.0<\/p>\n<p>\u4ee5\u540e\u6362\u670d\u52a1\u5668&#xff1a;<\/p>\n<p>python3 <span class=\"token parameter variable\">-m<\/span> venv .venv<\/p>\n<p><span class=\"token builtin class-name\">source<\/span> .venv\/bin\/activate<\/p>\n<p>python <span class=\"token parameter variable\">-m<\/span> pip <span class=\"token function\">install<\/span> <span class=\"token parameter variable\">-r<\/span> requirements.txt<\/p>\n<p>\u5c31\u53ef\u4ee5\u5feb\u901f\u6062\u590d\u9879\u76ee\u73af\u5883\u3002<\/p>\n<hr \/>\n<h2>\u5341\u516b\u3001\u4e0d\u8981\u968f\u610f\u4fee\u6539\u7cfb\u7edf Python<\/h2>\n<p>\u8fd9\u662f\u670d\u52a1\u5668\u5b89\u88c5 Python \u65f6\u6700\u9700\u8981\u6ce8\u610f\u7684\u4e00\u70b9\u3002<\/p>\n<p>\u4e0d\u8981\u6267\u884c\u7c7b\u4f3c&#xff1a;<\/p>\n<p><span class=\"token function\">sudo<\/span> <span class=\"token function\">rm<\/span> \/usr\/bin\/python3<\/p>\n<p>\u4e5f\u4e0d\u8981\u968f\u610f\u6267\u884c&#xff1a;<\/p>\n<p><span class=\"token function\">sudo<\/span> <span class=\"token function\">ln<\/span> <span class=\"token parameter variable\">-sf<\/span> \/xxx\/python3 \/usr\/bin\/python3<\/p>\n<p>\u66f4\u4e0d\u8981\u4e3a\u4e86\u5347\u7ea7 Python&#xff0c;\u76f4\u63a5\u66ff\u6362 Ubuntu \u7684\u7cfb\u7edf Python\u3002<\/p>\n<p>\u56e0\u4e3a&#xff1a;<\/p>\n<p>Ubuntu<br \/>\n  \u2502<br \/>\n  \u251c\u2500\u2500 apt<br \/>\n  \u251c\u2500\u2500 \u7cfb\u7edf\u5de5\u5177<br \/>\n  \u251c\u2500\u2500 cloud-init<br \/>\n  \u2514\u2500\u2500 \u5176\u4ed6\u7cfb\u7edf\u7ec4\u4ef6<br \/>\n          \u2502<br \/>\n          \u2514\u2500\u2500 \u53ef\u80fd\u4f9d\u8d56\u7cfb\u7edf Python<\/p>\n<p>\u5982\u679c\u5f3a\u884c\u66ff\u6362&#xff1a;<\/p>\n<p>\/usr\/bin\/python3<\/p>\n<p>\u53ef\u80fd\u5bfc\u81f4&#xff1a;<\/p>\n<p>apt \u65e0\u6cd5\u6b63\u5e38\u8fd0\u884c<br \/>\n\u7cfb\u7edf\u5de5\u5177\u5f02\u5e38<br \/>\n\u7cfb\u7edf\u5347\u7ea7\u5931\u8d25<br \/>\n\u670d\u52a1\u5668\u7ba1\u7406\u529f\u80fd\u5f02\u5e38<\/p>\n<h4>\u6b63\u786e\u601d\u8def<\/h4>\n<p>\u7cfb\u7edf Python<br \/>\n    \u2502<br \/>\n    \u2514\u2500\u2500 Ubuntu \u81ea\u5df1\u7ba1\u7406<\/p>\n<p>\u9879\u76ee Python<br \/>\n    \u2502<br \/>\n    \u2514\u2500\u2500 .venv \u81ea\u5df1\u7ba1\u7406<\/p>\n<p>\u4e0d\u8981\u4e3a\u4e86\u9879\u76ee\u9700\u6c42\u4fee\u6539\u7cfb\u7edf Python\u3002<\/p>\n<hr \/>\n<h2>\u5341\u4e5d\u3001\u670d\u52a1\u5668\u591a\u4e2a Python \u7248\u672c\u600e\u4e48\u529e&#xff1f;<\/h2>\n<p>\u4f8b\u5982&#xff1a;<\/p>\n<p>\u9879\u76ee A \u2192 Python 3.12<br \/>\n\u9879\u76ee B \u2192 Python 3.13<br \/>\n\u9879\u76ee C \u2192 Python 3.14<\/p>\n<p>\u4e0d\u8981\u76f4\u63a5\u66ff\u6362&#xff1a;<\/p>\n<p>\/usr\/bin\/python3<\/p>\n<p>\u53ef\u4ee5\u8003\u8651&#xff1a;<\/p>\n<p>pyenv<br \/>\nuv<br \/>\nDocker<\/p>\n<p>\u5176\u4e2d\u670d\u52a1\u5668\u751f\u4ea7\u73af\u5883\u5c24\u5176\u63a8\u8350\u8003\u8651 Docker&#xff1a;<\/p>\n<p>\u670d\u52a1\u5668<br \/>\n\u2502<br \/>\n\u251c\u2500\u2500 Docker<br \/>\n\u2502<br \/>\n\u251c\u2500\u2500 Python 3.12 \u5bb9\u5668<br \/>\n\u2502   \u2514\u2500\u2500 \u9879\u76ee A<br \/>\n\u2502<br \/>\n\u251c\u2500\u2500 Python 3.13 \u5bb9\u5668<br \/>\n\u2502   \u2514\u2500\u2500 \u9879\u76ee B<br \/>\n\u2502<br \/>\n\u2514\u2500\u2500 Python 3.14 \u5bb9\u5668<br \/>\n    \u2514\u2500\u2500 \u9879\u76ee C<\/p>\n<p>\u8fd9\u6837 Python \u7248\u672c\u548c\u7cfb\u7edf\u73af\u5883\u5b8c\u5168\u9694\u79bb\u3002<\/p>\n<hr \/>\n<h2>\u4e8c\u5341\u3001\u751f\u4ea7\u670d\u52a1\u5668\u4e0d\u8981\u4f7f\u7528 root \u8fd0\u884c Python<\/h2>\n<p>\u5f00\u53d1\u6d4b\u8bd5\u7684\u65f6\u5019&#xff1a;<\/p>\n<p>root<\/p>\n<p>\u8fd0\u884c\u7a0b\u5e8f\u6bd4\u8f83\u7b80\u5355\u3002<\/p>\n<p>\u4f46\u662f\u751f\u4ea7\u73af\u5883\u4e0d\u63a8\u8350\u3002<\/p>\n<p>\u4f8b\u5982\u521b\u5efa\u4e13\u7528\u7528\u6237&#xff1a;<\/p>\n<p><span class=\"token function\">sudo<\/span> <span class=\"token function\">useradd<\/span> <span class=\"token parameter variable\">-r<\/span> <span class=\"token parameter variable\">-m<\/span> <span class=\"token parameter variable\">-s<\/span> \/bin\/bash pythonapp<\/p>\n<p>\u7136\u540e\u8ba9 Python \u9879\u76ee\u4f7f\u7528&#xff1a;<\/p>\n<p>pythonapp<\/p>\n<p>\u8fd0\u884c\u3002<\/p>\n<p>\u6574\u4f53\u7ed3\u6784&#xff1a;<\/p>\n<p>Internet<br \/>\n    \u2193<br \/>\nNginx<br \/>\n    \u2193<br \/>\nPython Web \u670d\u52a1<br \/>\n    \u2193<br \/>\npythonapp \u7528\u6237<br \/>\n    \u2193<br \/>\n\u9879\u76ee .venv<\/p>\n<p>\u8fd9\u6837\u53ef\u4ee5\u964d\u4f4e Python \u5e94\u7528\u51fa\u73b0\u5b89\u5168\u6f0f\u6d1e\u65f6\u5bf9\u670d\u52a1\u5668\u9020\u6210\u7684\u5f71\u54cd\u3002<\/p>\n<hr \/>\n<h2>\u4e8c\u5341\u4e00\u3001Python Web \u670d\u52a1\u63a8\u8350\u67b6\u6784<\/h2>\n<p>\u5982\u679c\u4ee5\u540e\u4f7f\u7528 FastAPI\u3001Flask \u7b49\u5f00\u53d1\u540e\u7aef\u670d\u52a1&#xff0c;\u751f\u4ea7\u73af\u5883\u901a\u5e38\u4e0d\u8981\u76f4\u63a5&#xff1a;<\/p>\n<p>python app.py<\/p>\n<p>\u63a8\u8350&#xff1a;<\/p>\n<p>                 Internet<br \/>\n                    \u2502<br \/>\n                    \u25bc<br \/>\n                 Nginx<br \/>\n                    \u2502<br \/>\n                    \u25bc<br \/>\n             Uvicorn \/ Gunicorn<br \/>\n                    \u2502<br \/>\n                    \u25bc<br \/>\n                FastAPI<br \/>\n                 \/    \\\\<br \/>\n                \/      \\\\<br \/>\n             MySQL     Redis<\/p>\n<p>\u4f8b\u5982 FastAPI&#xff1a;<\/p>\n<p>python <span class=\"token parameter variable\">-m<\/span> pip <span class=\"token function\">install<\/span> fastapi uvicorn<\/p>\n<p>\u542f\u52a8&#xff1a;<\/p>\n<p>uvicorn app:app <span class=\"token parameter variable\">&#8211;host<\/span> <span class=\"token number\">0.0<\/span>.0.0 <span class=\"token parameter variable\">&#8211;port<\/span> <span class=\"token number\">8000<\/span><\/p>\n<p>\u751f\u4ea7\u73af\u5883\u518d\u7ed3\u5408&#xff1a;<\/p>\n<p>systemd<br \/>\nDocker<br \/>\nNginx<br \/>\nGitLab CI\/CD<\/p>\n<p>\u5b9e\u73b0\u81ea\u52a8\u90e8\u7f72\u548c\u670d\u52a1\u7ba1\u7406\u3002<\/p>\n<hr \/>\n<h2>\u4e8c\u5341\u4e8c\u3001\u5b8c\u6574\u5b89\u88c5\u6d41\u7a0b<\/h2>\n<p>\u5982\u679c\u4f60\u662f\u65b0\u624b&#xff0c;\u4e0d\u60f3\u770b\u4e0a\u9762\u7684\u89e3\u91ca&#xff0c;\u53ef\u4ee5\u8bb0\u4f4f\u4e0b\u9762\u8fd9\u4e00\u5957\u3002<\/p>\n<h3>\u7b2c\u4e00\u6b65&#xff1a;\u5b89\u88c5 Python<\/h3>\n<p><span class=\"token function\">sudo<\/span> <span class=\"token function\">apt<\/span> update<\/p>\n<p><span class=\"token function\">sudo<\/span> <span class=\"token function\">apt<\/span> <span class=\"token function\">install<\/span> <span class=\"token parameter variable\">-y<\/span> <span class=\"token punctuation\">\\\\<\/span><br \/>\n    python3 <span class=\"token punctuation\">\\\\<\/span><br \/>\n    python3-pip <span class=\"token punctuation\">\\\\<\/span><br \/>\n    python3-venv <span class=\"token punctuation\">\\\\<\/span><br \/>\n    python-is-python3<\/p>\n<hr \/>\n<h3>\u7b2c\u4e8c\u6b65&#xff1a;\u68c0\u67e5<\/h3>\n<p>python3 <span class=\"token parameter variable\">&#8211;version<\/span><br \/>\npython <span class=\"token parameter variable\">&#8211;version<\/span><br \/>\npython3 <span class=\"token parameter variable\">-m<\/span> pip <span class=\"token parameter variable\">&#8211;version<\/span><\/p>\n<hr \/>\n<h3>\u7b2c\u4e09\u6b65&#xff1a;\u521b\u5efa\u9879\u76ee<\/h3>\n<p><span class=\"token function\">mkdir<\/span> <span class=\"token parameter variable\">-p<\/span> ~\/projects\/python-demo<br \/>\n<span class=\"token builtin class-name\">cd<\/span> ~\/projects\/python-demo<\/p>\n<hr \/>\n<h3>\u7b2c\u56db\u6b65&#xff1a;\u521b\u5efa\u865a\u62df\u73af\u5883<\/h3>\n<p>python3 <span class=\"token parameter variable\">-m<\/span> venv .venv<\/p>\n<hr \/>\n<h3>\u7b2c\u4e94\u6b65&#xff1a;\u8fdb\u5165\u865a\u62df\u73af\u5883<\/h3>\n<p><span class=\"token builtin class-name\">source<\/span> .venv\/bin\/activate<\/p>\n<hr \/>\n<h3>\u7b2c\u516d\u6b65&#xff1a;\u5347\u7ea7 pip<\/h3>\n<p>python <span class=\"token parameter variable\">-m<\/span> pip <span class=\"token function\">install<\/span> <span class=\"token parameter variable\">&#8211;upgrade<\/span> pip<\/p>\n<hr \/>\n<h3>\u7b2c\u4e03\u6b65&#xff1a;\u5b89\u88c5\u4f9d\u8d56<\/h3>\n<p>\u4f8b\u5982&#xff1a;<\/p>\n<p>python <span class=\"token parameter variable\">-m<\/span> pip <span class=\"token function\">install<\/span> requests<\/p>\n<hr \/>\n<h3>\u7b2c\u516b\u6b65&#xff1a;\u8fd0\u884c Python<\/h3>\n<p>python hello.py<\/p>\n<hr \/>\n<h3>\u7b2c\u4e5d\u6b65&#xff1a;\u9000\u51fa\u865a\u62df\u73af\u5883<\/h3>\n<p>deactivate<\/p>\n<hr \/>\n<h2>\u4e8c\u5341\u4e09\u3001\u6700\u7ec8\u63a8\u8350\u7684\u76ee\u5f55\u7ed3\u6784<\/h2>\n<p>\u4e00\u4e2a\u7b80\u5355\u7684 Python \u9879\u76ee\u53ef\u4ee5\u8fd9\u6837\u7ec4\u7ec7&#xff1a;<\/p>\n<p>python-demo\/<br \/>\n\u2502<br \/>\n\u251c\u2500\u2500 .venv\/              # Python \u865a\u62df\u73af\u5883<br \/>\n\u2502<br \/>\n\u251c\u2500\u2500 app.py              # \u7a0b\u5e8f\u5165\u53e3<br \/>\n\u2502<br \/>\n\u251c\u2500\u2500 requirements.txt    # Python \u4f9d\u8d56<br \/>\n\u2502<br \/>\n\u251c\u2500\u2500 README.md           # \u9879\u76ee\u8bf4\u660e<br \/>\n\u2502<br \/>\n\u2514\u2500\u2500 .gitignore          # Git \u5ffd\u7565\u6587\u4ef6<\/p>\n<p>\u5176\u4e2d&#xff1a;<\/p>\n<p>.venv\/ \u4e0d\u5e94\u8be5\u63d0\u4ea4\u5230 Git\u3002<\/p>\n<p>.gitignore&#xff1a;<\/p>\n<p>.venv\/<br \/>\n__pycache__\/<br \/>\n*.pyc<br \/>\n.env<\/p>\n<hr \/>\n<h2>\u4e8c\u5341\u56db\u3001\u5e38\u89c1\u95ee\u9898<\/h2>\n<h4>Q1&#xff1a;\u4e3a\u4ec0\u4e48\u6709 python3&#xff0c;\u6ca1\u6709 python&#xff1f;<\/h4>\n<p>Ubuntu \u9ed8\u8ba4\u53ef\u80fd\u53ea\u63d0\u4f9b&#xff1a;<\/p>\n<p>python3<\/p>\n<p>\u5982\u679c\u9700\u8981&#xff1a;<\/p>\n<p>python<\/p>\n<p>\u53ef\u4ee5\u5b89\u88c5&#xff1a;<\/p>\n<p><span class=\"token function\">sudo<\/span> <span class=\"token function\">apt<\/span> <span class=\"token function\">install<\/span> python-is-python3<\/p>\n<hr \/>\n<h4>Q2&#xff1a;\u4e3a\u4ec0\u4e48 Python \u6709\u4e86&#xff0c;\u4f46\u662f pip \u6ca1\u6709&#xff1f;<\/h4>\n<p>\u56e0\u4e3a Python \u548c pip \u662f\u4e0d\u540c\u7684\u8f6f\u4ef6\u5305\u3002<\/p>\n<p>\u5b89\u88c5&#xff1a;<\/p>\n<p><span class=\"token function\">sudo<\/span> <span class=\"token function\">apt<\/span> <span class=\"token function\">install<\/span> python3-pip<\/p>\n<hr \/>\n<h4>Q3&#xff1a;\u4e3a\u4ec0\u4e48 pip3 install \u4e0d\u63a8\u8350\u76f4\u63a5\u4f7f\u7528&#xff1f;<\/h4>\n<p>\u4e0d\u662f\u4e0d\u80fd\u7528&#xff0c;\u800c\u662f\u670d\u52a1\u5668\u53ef\u80fd\u5b58\u5728\u591a\u4e2a Python\u3002<\/p>\n<p>\u66f4\u63a8\u8350&#xff1a;<\/p>\n<p>python3 <span class=\"token parameter variable\">-m<\/span> pip<\/p>\n<p>\u8fdb\u5165\u865a\u62df\u73af\u5883\u4ee5\u540e&#xff1a;<\/p>\n<p>python <span class=\"token parameter variable\">-m<\/span> pip<\/p>\n<hr \/>\n<h4>Q4&#xff1a;\u4e3a\u4ec0\u4e48\u8981\u521b\u5efa .venv&#xff1f;<\/h4>\n<p>\u4e3a\u4e86\u8ba9\u4e0d\u540c\u9879\u76ee\u4e4b\u95f4\u7684 Python \u4f9d\u8d56\u76f8\u4e92\u9694\u79bb\u3002<\/p>\n<p>\u4f8b\u5982&#xff1a;<\/p>\n<p>\u9879\u76ee A<br \/>\nrequests 2.x<\/p>\n<p>\u9879\u76ee B<br \/>\nrequests 3.x<\/p>\n<p>\u4e92\u4e0d\u5f71\u54cd\u3002<\/p>\n<hr \/>\n<h4>Q5&#xff1a;.venv \u53ef\u4ee5\u5220\u9664\u5417&#xff1f;<\/h4>\n<p>\u53ef\u4ee5\u3002<\/p>\n<p>\u865a\u62df\u73af\u5883\u672c\u8d28\u4e0a\u5c31\u662f\u4e00\u4e2a\u76ee\u5f55\u3002<\/p>\n<p>\u5220\u9664&#xff1a;<\/p>\n<p><span class=\"token function\">rm<\/span> <span class=\"token parameter variable\">-rf<\/span> .venv<\/p>\n<p>\u7136\u540e\u91cd\u65b0\u521b\u5efa&#xff1a;<\/p>\n<p>python3 <span class=\"token parameter variable\">-m<\/span> venv .venv<\/p>\n<p>\u518d\u5b89\u88c5&#xff1a;<\/p>\n<p>python <span class=\"token parameter variable\">-m<\/span> pip <span class=\"token function\">install<\/span> <span class=\"token parameter variable\">-r<\/span> requirements.txt<\/p>\n<p>\u5373\u53ef\u6062\u590d\u3002<\/p>\n<hr \/>\n<h2>\u4e8c\u5341\u4e94\u3001\u5b89\u88c5\u5b8c\u6210\u540e\u7684\u68c0\u67e5\u6e05\u5355<\/h2>\n<p>\u6700\u7ec8\u53ef\u4ee5\u6267\u884c&#xff1a;<\/p>\n<p>python3 <span class=\"token parameter variable\">&#8211;version<\/span><\/p>\n<p>python <span class=\"token parameter variable\">&#8211;version<\/span><\/p>\n<p>python3 <span class=\"token parameter variable\">-m<\/span> pip <span class=\"token parameter variable\">&#8211;version<\/span><\/p>\n<p><span class=\"token function\">which<\/span> python3<\/p>\n<p>\u521b\u5efa\u9879\u76ee&#xff1a;<\/p>\n<p><span class=\"token function\">mkdir<\/span> <span class=\"token parameter variable\">-p<\/span> ~\/projects\/python-demo<br \/>\n<span class=\"token builtin class-name\">cd<\/span> ~\/projects\/python-demo<\/p>\n<p>\u521b\u5efa\u73af\u5883&#xff1a;<\/p>\n<p>python3 <span class=\"token parameter variable\">-m<\/span> venv .venv<br \/>\n<span class=\"token builtin class-name\">source<\/span> .venv\/bin\/activate<\/p>\n<p>\u68c0\u67e5&#xff1a;<\/p>\n<p><span class=\"token function\">which<\/span> python<br \/>\npython <span class=\"token parameter variable\">&#8211;version<\/span><br \/>\npython <span class=\"token parameter variable\">-m<\/span> pip <span class=\"token parameter variable\">&#8211;version<\/span><\/p>\n<p>\u5982\u679c\u770b\u5230&#xff1a;<\/p>\n<p>Python 3.12.3<\/p>\n<p>\/home\/ayy\/projects\/python-demo\/.venv\/bin\/python<\/p>\n<p>pip xx.x from \/home\/ayy\/projects\/python-demo\/.venv\/&#8230;<\/p>\n<p>\u90a3\u4e48\u8bf4\u660e&#xff1a;<\/p>\n<p>Python &#043; pip &#043; \u865a\u62df\u73af\u5883\u5df2\u7ecf\u5168\u90e8\u914d\u7f6e\u5b8c\u6210\u3002<\/p>\n<hr \/>\n<h2>\u603b\u7ed3<\/h2>\n<p>\u5bf9\u4e8e Ubuntu \u670d\u52a1\u5668&#xff0c;\u65b0\u624b\u8bb0\u4f4f\u4e0b\u9762\u8fd9\u4e2a\u539f\u5219\u5c31\u591f\u4e86&#xff1a;<\/p>\n<p>\u2460 Ubuntu \u7cfb\u7edf<br \/>\n      \u2502<br \/>\n      \u25bc<br \/>\n\u2461 \u5b89\u88c5 Python 3<br \/>\n      \u2502<br \/>\n      \u25bc<br \/>\n\u2462 \u5b89\u88c5 pip &#043; venv<br \/>\n      \u2502<br \/>\n      \u25bc<br \/>\n\u2463 \u521b\u5efa Python \u9879\u76ee<br \/>\n      \u2502<br \/>\n      \u25bc<br \/>\n\u2464 \u521b\u5efa .venv \u865a\u62df\u73af\u5883<br \/>\n      \u2502<br \/>\n      \u25bc<br \/>\n\u2465 \u6fc0\u6d3b .venv<br \/>\n      \u2502<br \/>\n      \u25bc<br \/>\n\u2466 pip \u5b89\u88c5\u9879\u76ee\u4f9d\u8d56<br \/>\n      \u2502<br \/>\n      \u25bc<br \/>\n\u2467 \u8fd0\u884c Python \u9879\u76ee<\/p>\n<p>\u6700\u63a8\u8350\u7684\u57fa\u7840\u547d\u4ee4\u5c31\u662f&#xff1a;<\/p>\n<p><span class=\"token function\">sudo<\/span> <span class=\"token function\">apt<\/span> update<br \/>\n<span class=\"token function\">sudo<\/span> <span class=\"token function\">apt<\/span> <span class=\"token function\">install<\/span> <span class=\"token parameter variable\">-y<\/span> python3 python3-pip python3-venv python-is-python3<\/p>\n<p><span class=\"token function\">mkdir<\/span> <span class=\"token parameter variable\">-p<\/span> ~\/projects\/python-demo<br \/>\n<span class=\"token builtin class-name\">cd<\/span> ~\/projects\/python-demo<\/p>\n<p>python3 <span class=\"token parameter variable\">-m<\/span> venv .venv<br \/>\n<span class=\"token builtin class-name\">source<\/span> .venv\/bin\/activate<\/p>\n<p>python <span class=\"token parameter variable\">-m<\/span> pip <span class=\"token function\">install<\/span> <span class=\"token parameter variable\">&#8211;upgrade<\/span> pip<\/p>\n<p>\u5bf9\u4e8e\u666e\u901a Ubuntu \u670d\u52a1\u5668&#xff0c;\u8fd9\u5957\u65b9\u6848\u5df2\u7ecf\u8db3\u591f\u7a33\u5b9a&#xff0c;\u4e0d\u9700\u8981\u4e00\u5f00\u59cb\u5c31\u6298\u817e pyenv\u3001\u6e90\u7801\u7f16\u8bd1 Python \u6216\u66ff\u6362\u7cfb\u7edf Python\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\/* MD \/ \u5bcc\u6587\u672c\u4e2d\u7684 .toc\uff08\u542b\u535a\u5ba2\u56ed\u642c\u5bb6\u7b49\u5d4c\u5957\u7ed3\u6784\uff09\uff1b.toc-box \u5728\u4fa7\u680f\uff0c\u4e0d\u53d7\u5f71\u54cd *\/#content_views .toc,\/* \u7f16\u8f91\u5668\u5e38\u5728\u76ee\u5f55\u524d\u540e\u63d2\u5165\u7a7a p\uff08:empty \u4ecd\u5360 20px\uff09\uff0c\u4e00\u5e76\u53bb\u6389\u907f\u514d\u9876\u7a7a\u9699 *\/#content_views.markdown_views &gt; p:empty:has(+ .toc),#content_views.markdown_views &gt; .toc + p:empty,\/* \u5bcc\u6587\u672c\u65e7\u7248\u76ee\u5f55\u6807\u8bb0 *\/#content<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[81,103,43],"topic":[],"class_list":["post-116014","post","type-post","status-publish","format-standard","hentry","category-server","tag-python","tag-ubuntu","tag-43"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v20.3 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Ubuntu \u670d\u52a1\u5668\u5b89\u88c5 Python \u6559\u7a0b - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.wsisp.com\/helps\/116014.html\" \/>\n<meta property=\"og:locale\" content=\"zh_CN\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Ubuntu \u670d\u52a1\u5668\u5b89\u88c5 Python \u6559\u7a0b - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"og:description\" content=\"\/* MD \/ \u5bcc\u6587\u672c\u4e2d\u7684 .toc\uff08\u542b\u535a\u5ba2\u56ed\u642c\u5bb6\u7b49\u5d4c\u5957\u7ed3\u6784\uff09\uff1b.toc-box \u5728\u4fa7\u680f\uff0c\u4e0d\u53d7\u5f71\u54cd *\/#content_views .toc,\/* \u7f16\u8f91\u5668\u5e38\u5728\u76ee\u5f55\u524d\u540e\u63d2\u5165\u7a7a p\uff08:empty \u4ecd\u5360 20px\uff09\uff0c\u4e00\u5e76\u53bb\u6389\u907f\u514d\u9876\u7a7a\u9699 *\/#content_views.markdown_views &gt; p:empty:has(+ .toc),#content_views.markdown_views &gt; .toc + p:empty,\/* \u5bcc\u6587\u672c\u65e7\u7248\u76ee\u5f55\u6807\u8bb0 *\/#content\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.wsisp.com\/helps\/116014.html\" \/>\n<meta property=\"og:site_name\" content=\"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"article:published_time\" content=\"2026-10-20T07:40:50+00:00\" \/>\n<meta name=\"author\" content=\"admin\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"\u4f5c\u8005\" \/>\n\t<meta name=\"twitter:data1\" content=\"admin\" \/>\n\t<meta name=\"twitter:label2\" content=\"\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4\" \/>\n\t<meta name=\"twitter:data2\" content=\"6 \u5206\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/116014.html\",\"url\":\"https:\/\/www.wsisp.com\/helps\/116014.html\",\"name\":\"Ubuntu \u670d\u52a1\u5668\u5b89\u88c5 Python \u6559\u7a0b - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"isPartOf\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\"},\"datePublished\":\"2026-10-20T07:40:50+00:00\",\"dateModified\":\"2026-10-20T07:40:50+00:00\",\"author\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\"},\"breadcrumb\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/116014.html#breadcrumb\"},\"inLanguage\":\"zh-Hans\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.wsisp.com\/helps\/116014.html\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/116014.html#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"\u9996\u9875\",\"item\":\"https:\/\/www.wsisp.com\/helps\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Ubuntu \u670d\u52a1\u5668\u5b89\u88c5 Python \u6559\u7a0b\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\",\"url\":\"https:\/\/www.wsisp.com\/helps\/\",\"name\":\"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"description\":\"\u9999\u6e2f\u670d\u52a1\u5668_\u9999\u6e2f\u4e91\u670d\u52a1\u5668\u8d44\u8baf_\u670d\u52a1\u5668\u5e2e\u52a9\u6587\u6863_\u670d\u52a1\u5668\u6559\u7a0b\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.wsisp.com\/helps\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"zh-Hans\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\",\"name\":\"admin\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"zh-Hans\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery\",\"contentUrl\":\"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery\",\"caption\":\"admin\"},\"sameAs\":[\"http:\/\/wp.wsisp.com\"],\"url\":\"https:\/\/www.wsisp.com\/helps\/author\/admin\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Ubuntu \u670d\u52a1\u5668\u5b89\u88c5 Python \u6559\u7a0b - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.wsisp.com\/helps\/116014.html","og_locale":"zh_CN","og_type":"article","og_title":"Ubuntu \u670d\u52a1\u5668\u5b89\u88c5 Python \u6559\u7a0b - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","og_description":"\/* MD \/ \u5bcc\u6587\u672c\u4e2d\u7684 .toc\uff08\u542b\u535a\u5ba2\u56ed\u642c\u5bb6\u7b49\u5d4c\u5957\u7ed3\u6784\uff09\uff1b.toc-box \u5728\u4fa7\u680f\uff0c\u4e0d\u53d7\u5f71\u54cd *\/#content_views .toc,\/* \u7f16\u8f91\u5668\u5e38\u5728\u76ee\u5f55\u524d\u540e\u63d2\u5165\u7a7a p\uff08:empty \u4ecd\u5360 20px\uff09\uff0c\u4e00\u5e76\u53bb\u6389\u907f\u514d\u9876\u7a7a\u9699 *\/#content_views.markdown_views &gt; p:empty:has(+ .toc),#content_views.markdown_views &gt; .toc + p:empty,\/* \u5bcc\u6587\u672c\u65e7\u7248\u76ee\u5f55\u6807\u8bb0 *\/#content","og_url":"https:\/\/www.wsisp.com\/helps\/116014.html","og_site_name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","article_published_time":"2026-10-20T07:40:50+00:00","author":"admin","twitter_card":"summary_large_image","twitter_misc":{"\u4f5c\u8005":"admin","\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4":"6 \u5206"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.wsisp.com\/helps\/116014.html","url":"https:\/\/www.wsisp.com\/helps\/116014.html","name":"Ubuntu \u670d\u52a1\u5668\u5b89\u88c5 Python \u6559\u7a0b - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","isPartOf":{"@id":"https:\/\/www.wsisp.com\/helps\/#website"},"datePublished":"2026-10-20T07:40:50+00:00","dateModified":"2026-10-20T07:40:50+00:00","author":{"@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41"},"breadcrumb":{"@id":"https:\/\/www.wsisp.com\/helps\/116014.html#breadcrumb"},"inLanguage":"zh-Hans","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.wsisp.com\/helps\/116014.html"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.wsisp.com\/helps\/116014.html#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"\u9996\u9875","item":"https:\/\/www.wsisp.com\/helps"},{"@type":"ListItem","position":2,"name":"Ubuntu \u670d\u52a1\u5668\u5b89\u88c5 Python \u6559\u7a0b"}]},{"@type":"WebSite","@id":"https:\/\/www.wsisp.com\/helps\/#website","url":"https:\/\/www.wsisp.com\/helps\/","name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","description":"\u9999\u6e2f\u670d\u52a1\u5668_\u9999\u6e2f\u4e91\u670d\u52a1\u5668\u8d44\u8baf_\u670d\u52a1\u5668\u5e2e\u52a9\u6587\u6863_\u670d\u52a1\u5668\u6559\u7a0b","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.wsisp.com\/helps\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"zh-Hans"},{"@type":"Person","@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41","name":"admin","image":{"@type":"ImageObject","inLanguage":"zh-Hans","@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/image\/","url":"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery","contentUrl":"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery","caption":"admin"},"sameAs":["http:\/\/wp.wsisp.com"],"url":"https:\/\/www.wsisp.com\/helps\/author\/admin"}]}},"_links":{"self":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/116014","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/comments?post=116014"}],"version-history":[{"count":0,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/116014\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/media?parent=116014"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/categories?post=116014"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/tags?post=116014"},{"taxonomy":"topic","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/topic?post=116014"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}