{"id":175285,"date":"2024-05-08T18:48:30","date_gmt":"2024-05-08T10:48:30","guid":{"rendered":"https:\/\/docs.pingcode.com\/ask\/ask-ask\/175285.html"},"modified":"2024-05-08T18:48:39","modified_gmt":"2024-05-08T10:48:39","slug":"%e5%a6%82%e4%bd%95%e5%9c%a8linux%e9%87%8c%e4%b8%8b%e8%bd%bdpython%e5%b9%b6%e9%85%8d%e7%bd%aepython%e7%8e%af%e5%a2%83","status":"publish","type":"post","link":"https:\/\/docs.pingcode.com\/ask\/175285.html","title":{"rendered":"\u5982\u4f55\u5728Linux\u91cc\u4e0b\u8f7dpython\u5e76\u914d\u7f6epython\u73af\u5883"},"content":{"rendered":"<p style=\"text-align:center\"><img decoding=\"async\" src=\"https:\/\/cdn-kb.worktile.com\/kb\/wp-content\/uploads\/2024\/04\/27053156\/432591b8-4d6c-4486-9650-2a58b02d2f57.webp\" alt=\"\u5982\u4f55\u5728Linux\u91cc\u4e0b\u8f7dpython\u5e76\u914d\u7f6epython\u73af\u5883\" \/><\/p>\n<p><p>\u5728Linux\u7cfb\u7edf\u4e2d\u4e0b\u8f7dPython\u5e76\u914d\u7f6e\u73af\u5883\u5305\u542b\u51e0\u4e2a\u6838\u5fc3\u6b65\u9aa4\uff1a<strong>\u5b89\u88c5Python\u3001\u9a8c\u8bc1\u5b89\u88c5\u3001\u5b89\u88c5pip\u3001\u914d\u7f6e\u865a\u62df\u73af\u5883<\/strong>\u3002\u5176\u4e2d\uff0c<strong>\u5b89\u88c5pip<\/strong>\u662f\u4e00\u4e2a\u5173\u952e\u6b65\u9aa4\uff0c\u56e0\u4e3a\u5b83\u662fPython\u7684\u5305\u7ba1\u7406\u5de5\u5177\uff0c\u7528\u4e8e\u5b89\u88c5\u548c\u7ba1\u7406Python\u5305\u3002\u8fd9\u53ef\u4ee5\u5927\u5927\u7b80\u5316Python\u8f6f\u4ef6\u5305\u7684\u5b89\u88c5\u548c\u7ba1\u7406\u8fc7\u7a0b\u3002<\/p>\n<\/p>\n<p><p>\u63a5\u4e0b\u6765\uff0c\u6211\u4eec\u5c06\u8be6\u7ec6\u4ecb\u7ecd\u5728Linux\u7cfb\u7edf\u4e2d\u914d\u7f6ePython\u73af\u5883\u7684\u6bcf\u4e2a\u6b65\u9aa4\u3002<\/p>\n<\/p>\n<p><h3>\u4e00\u3001\u5b89\u88c5PYTHON<\/h3>\n<\/p>\n<p><p>\u7b2c\u4e00\u6b65\uff0c\u60a8\u9700\u8981\u5728Linux\u4e0a\u5b89\u88c5Python\u3002\u591a\u6570Linux\u53d1\u884c\u7248\u5df2\u9884\u88c5\u4e86Python\uff0c\u4f46\u60a8\u53ef\u80fd\u60f3\u8981\u5b89\u88c5\u4e0d\u540c\u7684\u7248\u672c\u6216\u66f4\u65b0\u73b0\u6709\u7248\u672c\u3002<\/p>\n<\/p>\n<ol>\n<li>\u6253\u5f00\u7ec8\u7aef\u3002<\/li>\n<li>\u9996\u5148\uff0c\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u66f4\u65b0\u60a8\u7684\u5305\u5217\u8868\uff0c\u4ee5\u786e\u4fdd\u60a8\u53ef\u4ee5\u4e0b\u8f7d\u6700\u65b0\u7684\u8f6f\u4ef6\u5305\u7248\u672c\uff1a\n<pre><code class=\"language-shell\">sudo apt-get update<\/p>\n<p><\/code><\/pre>\n<\/p>\n<\/li>\n<li>\u7136\u540e\uff0c\u5b89\u88c5Python\u3002\u60a8\u53ef\u4ee5\u5b89\u88c5Python 2.x\u7248\u672c\u6216Python 3.x\u7248\u672c\u3002\u73b0\u5728\u5927\u591a\u6570\u5e94\u7528\u90fd\u63a8\u8350\u4f7f\u7528Python 3\u3002\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u5b89\u88c5Python 3\uff1a\n<pre><code class=\"language-shell\">sudo apt-get install python3<\/p>\n<p><\/code><\/pre>\n<\/p>\n<\/li>\n<\/ol>\n<p><h3>\u4e8c\u3001\u9a8c\u8bc1\u5b89\u88c5<\/h3>\n<\/p>\n<p><p>\u5728Python\u5b89\u88c5\u5b8c\u6bd5\u540e\uff0c\u60a8\u9996\u8981\u9a8c\u8bc1\u5b89\u88c5\u662f\u5426\u6210\u529f\u3002<\/p>\n<\/p>\n<ol>\n<li>\u6253\u5f00\u7ec8\u7aef\u3002<\/li>\n<li>\u5728\u547d\u4ee4\u884c\u8f93\u5165\uff1a\n<pre><code class=\"language-shell\">python3 --version<\/p>\n<p><\/code><\/pre>\n<\/p>\n<\/li>\n<li>\u5982\u679c\u5b89\u88c5\u6210\u529f\uff0c\u7cfb\u7edf\u5c06\u663e\u793aPython\u7684\u7248\u672c\u53f7\u3002\u8fd9\u786e\u8ba4\u4e86Python\u5df2\u6210\u529f\u5b89\u88c5\u5728\u60a8\u7684Linux\u7cfb\u7edf\u4e2d\u3002<\/li>\n<\/ol>\n<p><h3>\u4e09\u3001\u5b89\u88c5PIP<\/h3>\n<\/p>\n<p><p>pip\u662fPython\u7684\u5305\u7ba1\u7406\u5de5\u5177\uff0c\u6b64\u6b65\u9aa4\u5bf9\u4e8e\u7ba1\u7406Python\u5e93\u975e\u5e38\u5173\u952e\u3002<\/p>\n<\/p>\n<ol>\n<li>\u5728\u5b89\u88c5pip\u4e4b\u524d\uff0c\u60a8\u53ef\u80fd\u9700\u8981\u5148\u5b89\u88c5<code>curl<\/code>\u3002\u53ef\u4ee5\u901a\u8fc7\u6267\u884c\u4ee5\u4e0b\u547d\u4ee4\u6765\u5b89\u88c5<code>curl<\/code>\uff1a\n<pre><code class=\"language-shell\">sudo apt-get install curl<\/p>\n<p><\/code><\/pre>\n<\/p>\n<\/li>\n<li>\u4f7f\u7528\u4e0b\u5217\u547d\u4ee4\u5b89\u88c5pip for Python 3\uff1a\n<pre><code class=\"language-shell\">curl https:\/\/bootstrap.pypa.io\/get-pip.py -o get-pip.py<\/p>\n<p>python3 get-pip.py<\/p>\n<p><\/code><\/pre>\n<\/p>\n<\/li>\n<li>\u5b89\u88c5\u5b8c\u6210\u540e\uff0c\u901a\u8fc7\u8fd0\u884c\u4ee5\u4e0b\u547d\u4ee4\u9a8c\u8bc1pip\u662f\u5426\u6210\u529f\u5b89\u88c5\uff1a\n<pre><code class=\"language-shell\">pip3 --version<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p>\u5982\u679c\u663e\u793a\u4e86\u7248\u672c\u53f7\uff0c\u5373\u8868\u793a\u6210\u529f\u5b89\u88c5\u4e86pip\u3002<\/li>\n<\/p>\n<\/ol>\n<p><h3>\u56db\u3001\u914d\u7f6e\u865a\u62df\u73af\u5883<\/h3>\n<\/p>\n<p><p>\u865a\u62df\u73af\u5883\u5141\u8bb8\u60a8\u4e3a\u6bcf\u4e2a<a href=\"https:\/\/docs.pingcode.com\/blog\/project-management\/23316.html\" target=\"_blank\">\u9879\u76ee\u7ba1\u7406<\/a>\u4e0d\u540c\u7684Python\u7248\u672c\u548c\u5305\uff0c\u8fd9\u662f\u4e00\u4e2a\u975e\u5e38\u597d\u7684\u5b9e\u8df5\uff0c\u53ef\u4ee5\u907f\u514d\u7248\u672c\u51b2\u7a81\u3002<\/p>\n<\/p>\n<ol>\n<li>\u9996\u5148\uff0c\u60a8\u9700\u8981\u5b89\u88c5<code>virtualenv<\/code>\u5de5\u5177\u3002\u4f7f\u7528pip\u5b89\u88c5\uff1a\n<pre><code class=\"language-shell\">pip3 install virtualenv<\/p>\n<p><\/code><\/pre>\n<\/p>\n<\/li>\n<li>\u521b\u5efa\u4e00\u4e2a\u65b0\u7684\u865a\u62df\u73af\u5883\u3002\u9996\u5148\uff0c\u51b3\u5b9a\u60a8\u7684\u73af\u5883\u653e\u7f6e\u4f4d\u7f6e\uff0c\u7136\u540e\u8fd0\u884c\uff1a\n<pre><code class=\"language-shell\">virtualenv mypythonenv<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p>\u8fd9\u5c06\u5728<code>mypythonenv<\/code>\u76ee\u5f55\u4e2d\u521b\u5efa\u4e00\u4e2a\u65b0\u7684\u865a\u62df\u73af\u5883\u3002\u60a8\u53ef\u4ee5\u5c06<code>mypythonenv<\/code>\u66ff\u6362\u4e3a\u60a8\u81ea\u5df1\u9009\u62e9\u7684\u4efb\u4f55\u76ee\u5f55\u540d\u3002<\/li>\n<\/p>\n<li>\u6fc0\u6d3b\u865a\u62df\u73af\u5883\u3002\u5728\u60a8\u7684\u865a\u62df\u73af\u5883\u76ee\u5f55\u4e2d\uff0c\u8fd0\u884c\uff1a\n<pre><code class=\"language-shell\">source mypythonenv\/bin\/activate<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p>\u5728\u865a\u62df\u73af\u5883\u6fc0\u6d3b\u671f\u95f4\uff0c\u60a8\u53ef\u4ee5\u81ea\u7531\u5730\u5b89\u88c5\u3001\u5347\u7ea7\u548c\u5220\u9664Python\u5305\uff0c\u800c\u4e0d\u4f1a\u5f71\u54cd\u7cfb\u7edf\u7684\u5176\u4ed6\u90e8\u5206\u3002<\/li>\n<\/p>\n<\/ol>\n<p><p><strong>\u901a\u8fc7\u4ee5\u4e0a\u6b65\u9aa4\uff0c\u60a8\u5df2\u7ecf\u5b8c\u6210\u4e86\u5728Linux\u4e2d\u4e0b\u8f7dPython\u5e76\u914d\u7f6e\u73af\u5883\u7684\u8fc7\u7a0b\u3002<\/strong> \u8fd9\u4e9b\u6b65\u9aa4\u5c06\u786e\u4fdd\u60a8\u53ef\u4ee5\u5f00\u59cb\u5f00\u53d1Python\u9879\u76ee\uff0c\u540c\u65f6\u4fdd\u6301\u7cfb\u7edf\u7684\u6574\u6d01\u548c\u6709\u5e8f\u3002<\/p>\n<\/p>\n<h2><strong>\u76f8\u5173\u95ee\u7b54FAQs\uff1a<\/strong><\/h2>\n<p><strong>1. \u5728Linux\u4e0a\u5982\u4f55\u4e0b\u8f7dPython\uff1f<\/strong><\/p>\n<p>\u60a8\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u6b65\u9aa4\u5728Linux\u4e0a\u4e0b\u8f7dPython\uff1a<\/p>\n<ul>\n<li>\u9996\u5148\uff0c\u6253\u5f00\u7ec8\u7aef\u3002\u53ef\u4ee5\u4f7f\u7528\u5feb\u6377\u952eCtrl+Alt+T\u6765\u6253\u5f00\u7ec8\u7aef\u3002<\/li>\n<li>\u5176\u6b21\uff0c\u4f7f\u7528\u547d\u4ee4\u884c\u5305\u7ba1\u7406\u5668\u6765\u5b89\u88c5Python\u3002\u6839\u636e\u60a8\u7684Linux\u53d1\u884c\u7248\u7684\u4e0d\u540c\uff0c\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u5b89\u88c5Python\uff1a\n<ul>\n<li>Debian\u548cUbuntu\uff1a<code>sudo apt-get install python3<\/code><\/li>\n<li>CentOS\u548cFedora\uff1a<code>sudo dnf install python3<\/code><\/li>\n<li>Arch Linux\uff1a<code>sudo pacman -S python<\/code><\/li>\n<li>\u5176\u4ed6\u53d1\u884c\u7248\uff0c\u8bf7\u67e5\u627e\u76f8\u5e94\u7684\u547d\u4ee4\u3002<\/li>\n<\/ul>\n<\/li>\n<li>\u6700\u540e\uff0c\u7b49\u5f85\u4e0b\u8f7d\u548c\u5b89\u88c5\u5b8c\u6210\u3002\u4e00\u65e6\u5b8c\u6210\uff0c\u60a8\u5c31\u53ef\u4ee5\u5728\u7ec8\u7aef\u4e2d\u8f93\u5165<code>python3<\/code>\uff08\u6216<code>python<\/code>\uff09\u547d\u4ee4\u6765\u9a8c\u8bc1Python\u662f\u5426\u6b63\u786e\u5b89\u88c5\u3002<\/li>\n<\/ul>\n<p><strong>2. \u5728Linux\u4e0a\u5982\u4f55\u914d\u7f6ePython\u73af\u5883\uff1f<\/strong><\/p>\n<p>\u8981\u914d\u7f6ePython\u73af\u5883\uff0c\u8bf7\u6309\u7167\u4ee5\u4e0b\u6b65\u9aa4\u8fdb\u884c\u64cd\u4f5c\uff1a<\/p>\n<ul>\n<li>\u9996\u5148\uff0c\u786e\u5b9a\u60a8\u5df2\u7ecf\u5b89\u88c5\u4e86\u6240\u9700\u7684Python\u7248\u672c\u3002\u53ef\u4ee5\u5728\u7ec8\u7aef\u4e2d\u8f93\u5165<code>python --version<\/code>\u547d\u4ee4\u6765\u67e5\u770b\u5f53\u524dPython\u7248\u672c\u3002<\/li>\n<li>\u5176\u6b21\uff0c\u8bbe\u7f6ePython\u7684\u8def\u5f84\u3002\u8981\u505a\u5230\u8fd9\u4e00\u70b9\uff0c\u60a8\u53ef\u4ee5\u7f16\u8f91\u60a8\u7684<code>.bashrc<\/code>\u6587\u4ef6\uff08\u6216\u5176\u4ed6shell\u6587\u4ef6\uff09\u5e76\u6dfb\u52a0\u4ee5\u4e0b\u884c\uff1a<br \/>\n<code>export PATH=&quot;\/path\/to\/python\/bin:$PATH&quot;<\/code><br \/>\n\u8fd9\u91cc\u7684<code>\/path\/to\/python<\/code>\u5e94\u8be5\u662f\u60a8Python\u5b89\u88c5\u7684\u8def\u5f84\u3002<\/li>\n<li>\u6700\u540e\uff0c\u4fdd\u5b58\u6587\u4ef6\u5e76\u91cd\u65b0\u52a0\u8f7d\u60a8\u7684shell\u914d\u7f6e\u3002\u53ef\u4ee5\u8f93\u5165<code>source ~\/.bashrc<\/code>\uff08\u6216\u5176\u4ed6shell\u6587\u4ef6\u540d\uff09\u6765\u4f7f\u66f4\u6539\u751f\u6548\u3002<\/li>\n<\/ul>\n<p><strong>3. \u5728Linux\u4e0a\u5982\u4f55\u540c\u65f6\u5b89\u88c5\u591a\u4e2aPython\u7248\u672c\uff1f<\/strong><\/p>\n<p>\u60a8\u53ef\u4ee5\u5728Linux\u4e0a\u540c\u65f6\u5b89\u88c5\u591a\u4e2aPython\u7248\u672c\uff0c\u4ee5\u4fbf\u5728\u9700\u8981\u65f6\u8f7b\u677e\u5207\u6362\u7248\u672c\u3002\u4ee5\u4e0b\u662f\u5b9e\u73b0\u8fd9\u4e2a\u76ee\u6807\u7684\u4e00\u4e9b\u6b65\u9aa4\uff1a<\/p>\n<ul>\n<li>\u9996\u5148\uff0c\u5728\u5b98\u65b9Python\u7f51\u7ad9\u4e0a\u4e0b\u8f7d\u60a8\u60f3\u8981\u7684Python\u7248\u672c\u7684\u6e90\u4ee3\u7801\u5305\u3002<\/li>\n<li>\u5176\u6b21\uff0c\u89e3\u538b\u4e0b\u8f7d\u7684\u6e90\u4ee3\u7801\u5305\u3002<\/li>\n<li>\u63a5\u4e0b\u6765\uff0c\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u7f16\u8bd1\u548c\u5b89\u88c5Python\u7248\u672c\uff1a\n<ul>\n<li><code>.\/configure --prefix=\/path\/to\/installation\/directory<\/code><\/li>\n<li><code>make<\/code><\/li>\n<li><code>make install<\/code><br \/>\n\u8fd9\u91cc\u7684<code>\/path\/to\/installation\/directory<\/code>\u5e94\u8be5\u662f\u60a8\u60f3\u8981\u5b89\u88c5Python\u7684\u76ee\u5f55\u3002<\/li>\n<\/ul>\n<\/li>\n<li>\u6700\u540e\uff0c\u4f7f\u7528\u7c7b\u4f3c\u7684\u6b65\u9aa4\u5b89\u88c5\u5176\u4ed6\u60f3\u8981\u7684Python\u7248\u672c\u3002\u786e\u4fdd\u5728\u6bcf\u4e2a\u7248\u672c\u5b89\u88c5\u65f6\u6307\u5b9a\u4e0d\u540c\u7684\u5b89\u88c5\u76ee\u5f55\u3002<\/li>\n<\/ul>\n<p>\u5b8c\u6210\u8fd9\u4e9b\u6b65\u9aa4\u540e\uff0c\u60a8\u5c06\u5728Linux\u4e0a\u5b89\u88c5\u5e76\u914d\u7f6e\u591a\u4e2aPython\u7248\u672c\u3002\u53ef\u4ee5\u4f7f\u7528\u76f8\u5e94\u7684\u547d\u4ee4\uff08\u5982<code>python3.8<\/code>\u3001<code>python3.9<\/code>\u7b49\uff09\u6765\u8fd0\u884c\u60a8\u9009\u62e9\u7684Python\u7248\u672c\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"\u5728Linux\u7cfb\u7edf\u4e2d\u4e0b\u8f7dPython\u5e76\u914d\u7f6e\u73af\u5883\u5305\u542b\u51e0\u4e2a\u6838\u5fc3\u6b65\u9aa4\uff1a\u5b89\u88c5Python\u3001\u9a8c\u8bc1\u5b89\u88c5\u3001\u5b89\u88c5pip\u3001\u914d\u7f6e\u865a\u62df [&hellip;]","protected":false},"author":3,"featured_media":175300,"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\/175285"}],"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=175285"}],"version-history":[{"count":0,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/175285\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media\/175300"}],"wp:attachment":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media?parent=175285"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/categories?post=175285"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/tags?post=175285"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}