{"id":16704,"date":"2024-11-25T09:48:12","date_gmt":"2024-11-25T01:48:12","guid":{"rendered":"https:\/\/92it.top\/?p=16704"},"modified":"2024-11-27T08:41:33","modified_gmt":"2024-11-27T00:41:33","slug":"python-%e8%99%9a%e6%8b%9f%e7%8e%af%e5%a2%83","status":"publish","type":"post","link":"https:\/\/92it.top\/?p=16704","title":{"rendered":"Python \u865a\u62df\u73af\u5883"},"content":{"rendered":"\n<p>\u8fd0\u884c <code><code>python -m venv python-venv<\/code><\/code> \u4f1a\u521b\u5efa\u4e00\u4e2a <strong>Python \u865a\u62df\u73af\u5883<\/strong>\uff0c\u5177\u4f53\u6765\u8bf4\u662f\u4e00\u4e2a\u72ec\u7acb\u7684 Python \u8fd0\u884c\u73af\u5883\u3002\u8fd9\u4e2a\u865a\u62df\u73af\u5883\u4f7f\u5f97\u4f60\u53ef\u4ee5\u5728\u9879\u76ee\u4e2d\u4f7f\u7528\u9694\u79bb\u7684 Python \u7248\u672c\u548c\u4f9d\u8d56\u5e93\uff0c\u800c\u4e0d\u4f1a\u5f71\u54cd\u5168\u5c40 Python \u73af\u5883\u6216\u5176\u4ed6\u9879\u76ee\u3002<\/p>\n\n\n\n<p>\u5728Python\u5f00\u53d1\u4e2d\uff0c\u865a\u62df\u73af\u5883\uff08venv\uff09\u662f\u4e00\u4e2a\u975e\u5e38\u91cd\u8981\u7684\u6982\u5ff5\u3002\u5b83\u5141\u8bb8\u5f00\u53d1\u8005\u4e3a\u4e0d\u540c\u7684\u9879\u76ee\u521b\u5efa\u9694\u79bb\u7684\u73af\u5883\uff0c\u786e\u4fdd\u9879\u76ee\u4e4b\u95f4\u4e0d\u4f1a\u4ea7\u751f\u4f9d\u8d56\u51b2\u7a81\u3002\u7136\u800c\uff0c\u6709\u65f6\u5019\u4f60\u53ef\u80fd\u4f1a\u53d1\u73b0\u4f60\u7684venv\u73af\u5883\u5df2\u7ecf\u4e22\u5931\u6216\u88ab\u8bef\u5220\u3002\u5728\u8fd9\u7bc7\u6587\u7ae0\u4e2d\uff0c\u6211\u4eec\u5c06\u8ba8\u8bba\u5982\u4f55\u91cd\u65b0\u521b\u5efa\u4e00\u4e2aPython venv\u73af\u5883\uff0c\u5e76\u786e\u4fdd\u4f60\u80fd\u591f\u987a\u5229\u5730\u7ee7\u7eed\u4f60\u7684\u5f00\u53d1\u5de5\u4f5c\u3002<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-large is-resized\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"438\" src=\"https:\/\/92it.top\/wp-content\/uploads\/2024\/11\/image-176-1024x438.png\" alt=\"\" class=\"wp-image-16718\" style=\"width:554px;height:auto\" srcset=\"https:\/\/92it.top\/wp-content\/uploads\/2024\/11\/image-176-1024x438.png 1024w, https:\/\/92it.top\/wp-content\/uploads\/2024\/11\/image-176-300x128.png 300w, https:\/\/92it.top\/wp-content\/uploads\/2024\/11\/image-176-768x328.png 768w, https:\/\/92it.top\/wp-content\/uploads\/2024\/11\/image-176-830x355.png 830w, https:\/\/92it.top\/wp-content\/uploads\/2024\/11\/image-176-230x98.png 230w, https:\/\/92it.top\/wp-content\/uploads\/2024\/11\/image-176-350x150.png 350w, https:\/\/92it.top\/wp-content\/uploads\/2024\/11\/image-176-480x205.png 480w, https:\/\/92it.top\/wp-content\/uploads\/2024\/11\/image-176.png 1530w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure><\/div>\n\n\n<p><strong>\u865a\u62df\u73af\u5883\u7684\u7279\u70b9<\/strong><\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<ol>\n<li><strong>\u72ec\u7acb\u6027<\/strong>\uff1a\n<ul>\n<li>\u6bcf\u4e2a\u865a\u62df\u73af\u5883\u6709\u81ea\u5df1\u7684 Python \u89e3\u91ca\u5668\u548c <code>site-packages<\/code>\uff08\u7528\u4e8e\u5b58\u653e\u4f9d\u8d56\u5305\u7684\u76ee\u5f55\uff09\u3002<\/li>\n\n\n\n<li>\u4e0d\u4f1a\u4e0e\u5168\u5c40\u7684 Python \u5305\u6df7\u6dc6\u6216\u5e72\u6270\u3002<\/li>\n<\/ul>\n<\/li>\n\n\n\n<li><strong>\u9694\u79bb\u4f9d\u8d56<\/strong>\uff1a\n<ul>\n<li>\u9879\u76ee\u4f7f\u7528\u7684\u5e93\u4ec5\u5b89\u88c5\u5728\u865a\u62df\u73af\u5883\u4e2d\uff0c\u4e0d\u4f1a\u6c61\u67d3\u5168\u5c40\u73af\u5883\uff0c\u4e5f\u4e0d\u4f1a\u5f71\u54cd\u5176\u4ed6\u9879\u76ee\u3002<\/li>\n<\/ul>\n<\/li>\n\n\n\n<li><strong>\u517c\u5bb9\u6027\u6d4b\u8bd5<\/strong>\uff1a\n<ul>\n<li>\u5141\u8bb8\u4f7f\u7528\u4e0d\u540c\u7248\u672c\u7684 Python \u6216\u4e0d\u540c\u7248\u672c\u7684\u5e93\u6765\u6d4b\u8bd5\u4ee3\u7801\u7684\u517c\u5bb9\u6027\u3002<\/li>\n<\/ul>\n<\/li>\n<\/ol>\n\n\n\n<p><strong><code>venv<\/code> \u547d\u4ee4\u505a\u4e86\u4ec0\u4e48<\/strong><\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<ol>\n<li>\u521b\u5efa\u4e00\u4e2a\u76ee\u5f55\uff08\u5982 <code><code><code>python-venv<\/code><\/code><\/code>\uff09<code>python-venv<\/code> \u662f\u865a\u62df\u73af\u5883\u7684\u76ee\u5f55\u540d\u79f0\uff0c\u865a\u62df\u73af\u5883\u7684\u6240\u6709\u5185\u5bb9\u90fd\u5b58\u653e\u5728\u8fd9\u4e2a\u6587\u4ef6\u5939\u4e2d\uff0c\u4f60\u53ef\u4ee5\u4e3a\u865a\u62df\u73af\u5883\u9009\u62e9\u4efb\u4f55\u540d\u5b57\uff0c\u6bd4\u5982 <code>env<\/code>\u3001<code>venv<\/code> \u6216\u9879\u76ee\u76f8\u5173\u7684\u540d\u5b57\u3002<\/li>\n\n\n\n<li>\u5728\u8be5\u76ee\u5f55\u4e2d\u751f\u6210\u4ee5\u4e0b\u5185\u5bb9\uff1a\n<ul>\n<li><strong>Python \u89e3\u91ca\u5668\u7684\u526f\u672c<\/strong>\uff1a\u72ec\u7acb\u7684 <code>python<\/code>\u3001<code>pip<\/code> \u7b49\u5de5\u5177\u3002<\/li>\n\n\n\n<li><strong><code>site-packages<\/code><\/strong>\uff1a\u5b58\u653e\u865a\u62df\u73af\u5883\u5b89\u88c5\u7684\u7b2c\u4e09\u65b9\u5e93\u3002<\/li>\n\n\n\n<li><strong>\u6fc0\u6d3b\u811a\u672c<\/strong>\uff1a\u7528\u4e8e\u6fc0\u6d3b\u865a\u62df\u73af\u5883\u3002<\/li>\n<\/ul>\n<\/li>\n<\/ol>\n\n\n\n<p><strong>\u865a\u62df\u73af\u5883\u7684\u76ee\u5f55\u7ed3\u6784<\/strong>\uff08\u53d6\u51b3\u4e8e\u64cd\u4f5c\u7cfb\u7edf\uff09<\/p>\n\n\n\n<p>Linux\/macOS<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">python-venv\/\n\u251c\u2500\u2500 bin\/              # \u5305\u542b\u6fc0\u6d3b\u811a\u672c\u548c\u865a\u62df\u73af\u5883\u7684 Python \u53ef\u6267\u884c\u6587\u4ef6\n\u251c\u2500\u2500 include\/          # \u5305\u542b C \u5934\u6587\u4ef6\uff08\u7528\u4e8e\u7f16\u8bd1\u4f9d\u8d56\u65f6\uff09\n\u251c\u2500\u2500 lib\/              # \u5305\u542b `site-packages`\uff08\u5b58\u653e\u4f9d\u8d56\u5305\u7684\u5730\u65b9\uff09\n\u251c\u2500\u2500 pyvenv.cfg        # \u865a\u62df\u73af\u5883\u7684\u914d\u7f6e\u4fe1\u606f<\/pre>\n\n\n\n<p>Windows<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">python-venv\/\n\u251c\u2500\u2500 Scripts\/          # \u5305\u542b\u6fc0\u6d3b\u811a\u672c\u548c\u865a\u62df\u73af\u5883\u7684 Python \u53ef\u6267\u884c\u6587\u4ef6\n\u251c\u2500\u2500 Include\/          # \u5305\u542b C \u5934\u6587\u4ef6\uff08\u7528\u4e8e\u7f16\u8bd1\u4f9d\u8d56\u65f6\uff09\n\u251c\u2500\u2500 Lib\/              # \u5305\u542b `site-packages`\uff08\u5b58\u653e\u4f9d\u8d56\u5305\u7684\u5730\u65b9\uff09\n\u251c\u2500\u2500 pyvenv.cfg        # \u865a\u62df\u73af\u5883\u7684\u914d\u7f6e\u4fe1\u606f\n<\/pre>\n\n\n\n<p><strong>\u4f5c\u7528<\/strong><\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<p>\u865a\u62df\u73af\u5883\u9694\u79bb\u9879\u76ee\u7684\u4f9d\u8d56\uff0c\u5177\u4f53\u6765\u8bf4\uff1a<\/p>\n\n\n\n<ol>\n<li><strong>\u72ec\u7acb\u7684 Python \u53ef\u6267\u884c\u6587\u4ef6<\/strong>\uff1a\n<ul>\n<li>\u865a\u62df\u73af\u5883\u4e2d\u5305\u542b\u72ec\u7acb\u7684 <code>python<\/code> \u548c <code>pip<\/code> \u5de5\u5177\uff0c\u4f7f\u7528\u7684\u4f9d\u8d56\u5e93\u4e0d\u4f1a\u5f71\u54cd\u7cfb\u7edf\u5168\u5c40\u73af\u5883\u3002<\/li>\n<\/ul>\n<\/li>\n\n\n\n<li><strong>\u9879\u76ee\u4f9d\u8d56\u9694\u79bb<\/strong>\uff1a\n<ul>\n<li>\u4efb\u4f55\u901a\u8fc7 <code>pip<\/code> \u5b89\u88c5\u7684\u5e93\uff08\u5982 <code>numpy<\/code>\u3001<code>flask<\/code> \u7b49\uff09\u90fd\u5b58\u50a8\u5728 <code>python-venv<\/code> \u7684 <code>site-packages<\/code> \u76ee\u5f55\u4e2d\uff0c\u4e0e\u5168\u5c40\u73af\u5883\u5b8c\u5168\u9694\u79bb\u3002<\/li>\n<\/ul>\n<\/li>\n\n\n\n<li><strong>\u591a\u7248\u672c\u517c\u5bb9\u6027<\/strong>\uff1a\n<ul>\n<li>\u53ef\u4ee5\u5728\u4e0d\u540c\u7684\u9879\u76ee\u4e2d\u4f7f\u7528\u4e0d\u540c\u7684 Python \u6216\u5e93\u7248\u672c\uff0c\u800c\u4e0d\u4f1a\u5f15\u53d1\u51b2\u7a81\u3002<\/li>\n<\/ul>\n<\/li>\n<\/ol>\n\n\n\n<p><strong>\u5982\u4f55\u4f7f\u7528<\/strong><\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<p><strong>1. \u521b\u5efa\u865a\u62df\u73af\u5883<\/strong><\/p>\n\n\n\n<p>\u8fd0\u884c\uff1a<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">python -m venv python-venv<\/pre>\n\n\n\n<p><strong>2. \u6fc0\u6d3b\u865a\u62df\u73af\u5883<\/strong><\/p>\n\n\n\n<p>Windows:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">python-venv\\Scripts\\activate<\/pre>\n\n\n\n<p>Linux\/macOS:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">source python-venv\/bin\/activate<\/pre>\n\n\n\n<p>\u6fc0\u6d3b\u540e\uff0c\u7ec8\u7aef\u63d0\u793a\u7b26\u4f1a\u663e\u793a\u865a\u62df\u73af\u5883\u540d\u79f0\uff0c\u4f8b\u5982\uff1a<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">(python-venv) $<\/pre>\n\n\n\n<p><strong>3. \u5b89\u88c5\u4f9d\u8d56<\/strong><\/p>\n\n\n\n<p>\u5728\u865a\u62df\u73af\u5883\u4e2d\u4f7f\u7528 <code>pip<\/code> \u5b89\u88c5\u4f9d\u8d56\uff0c\u4f8b\u5982\uff1a<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">pip install &lt;package-name>\npip install numpy<\/pre>\n\n\n\n<p><strong>4. \u9000\u51fa\u865a\u62df\u73af\u5883<\/strong><\/p>\n\n\n\n<p>\u8981\u9000\u51fa\u865a\u62df\u73af\u5883\uff0c\u8fd0\u884c\uff1a<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">deactivate<\/pre>\n\n\n\n<p><strong>\u603b\u7ed3<\/strong><\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<p>\u521b\u5efa <code>python-venv<\/code> \u7684\u76ee\u7684\u662f\u6784\u5efa\u4e00\u4e2a\u9694\u79bb\u7684 Python \u73af\u5883\uff0c\u7528\u4e8e\u5b89\u88c5\u548c\u7ba1\u7406\u7279\u5b9a\u9879\u76ee\u7684\u4f9d\u8d56\uff0c\u800c\u4e0d\u4f1a\u5e72\u6270\u7cfb\u7edf\u5168\u5c40\u7684 Python \u73af\u5883\u3002\u8fd9\u662f\u7ba1\u7406 Python \u9879\u76ee\u7684\u63a8\u8350\u5b9e\u8df5\uff0c\u5c24\u5176\u662f\u5728\u5f00\u53d1\u548c\u90e8\u7f72\u4e2d\u3002<\/p>\n\n\n\n<ul>\n<li>\u521b\u5efa\u4e0e\u9879\u76ee\u9694\u79bb\u7684\u73af\u5883\u3002<\/li>\n\n\n\n<li>\u5728\u540c\u4e00\u53f0\u673a\u5668\u4e0a\u8fd0\u884c\u4e0d\u540c\u7248\u672c\u7684 Python \u6216\u4f9d\u8d56\u5305\u3002<\/li>\n\n\n\n<li>\u6d4b\u8bd5\u4ee3\u7801\u5728\u4e0d\u540c\u73af\u5883\u4e0b\u7684\u517c\u5bb9\u6027\u3002<\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>\u8fd0\u884c python -m venv python-venv \u4f1a\u521b\u5efa\u4e00\u4e2a Python \u865a\u62df\u73af\u5883\uff0c\u5177\u4f53\u6765\u8bf4\u662f\u4e00\u4e2a [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[37],"tags":[],"_links":{"self":[{"href":"https:\/\/92it.top\/index.php?rest_route=\/wp\/v2\/posts\/16704"}],"collection":[{"href":"https:\/\/92it.top\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/92it.top\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/92it.top\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/92it.top\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=16704"}],"version-history":[{"count":4,"href":"https:\/\/92it.top\/index.php?rest_route=\/wp\/v2\/posts\/16704\/revisions"}],"predecessor-version":[{"id":16720,"href":"https:\/\/92it.top\/index.php?rest_route=\/wp\/v2\/posts\/16704\/revisions\/16720"}],"wp:attachment":[{"href":"https:\/\/92it.top\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=16704"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/92it.top\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=16704"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/92it.top\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=16704"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}