{"id":996625,"date":"2024-12-27T09:16:35","date_gmt":"2024-12-27T01:16:35","guid":{"rendered":"https:\/\/docs.pingcode.com\/ask\/ask-ask\/996625.html"},"modified":"2024-12-27T09:16:37","modified_gmt":"2024-12-27T01:16:37","slug":"centos%e5%a6%82%e4%bd%95%e4%bd%bf%e7%94%a8python%e7%bc%96%e7%a8%8b","status":"publish","type":"post","link":"https:\/\/docs.pingcode.com\/ask\/996625.html","title":{"rendered":"centos\u5982\u4f55\u4f7f\u7528python\u7f16\u7a0b"},"content":{"rendered":"<p style=\"text-align:center;\" ><img decoding=\"async\" src=\"https:\/\/cdn-kb.worktile.com\/kb\/wp-content\/uploads\/2024\/04\/25072754\/762a85e6-2c4e-4660-ae8b-9454ec86ccbe.webp\" alt=\"centos\u5982\u4f55\u4f7f\u7528python\u7f16\u7a0b\" \/><\/p>\n<p><p> <strong>\u5728CentOS\u4e0a\u4f7f\u7528Python\u7f16\u7a0b\uff0c\u9996\u5148\u9700\u8981\u786e\u4fddPython\u73af\u5883\u5df2\u5b89\u88c5\u3001\u914d\u7f6ePython\u865a\u62df\u73af\u5883\u4ee5\u9694\u79bb\u9879\u76ee\u3001\u4f7f\u7528\u6587\u672c\u7f16\u8f91\u5668\u6216IDE\u7f16\u5199Python\u4ee3\u7801\u3001\u8fd0\u884c\u5e76\u8c03\u8bd5Python\u7a0b\u5e8f\u3002<\/strong>\u63a5\u4e0b\u6765\uff0c\u6211\u4eec\u5c06\u8be6\u7ec6\u4ecb\u7ecd\u8fd9\u4e9b\u6b65\u9aa4\u4e2d\u7684\u4e00\u4e2a\uff1a\u914d\u7f6ePython\u865a\u62df\u73af\u5883\u3002<\/p>\n<\/p>\n<p><p>\u914d\u7f6ePython\u865a\u62df\u73af\u5883\u5bf9\u4e8e\u9694\u79bb\u9879\u76ee\u4f9d\u8d56\u548c\u7248\u672c\u63a7\u5236\u975e\u5e38\u91cd\u8981\u3002\u9996\u5148\uff0c\u786e\u4fdd\u5df2\u5b89\u88c5<code>python3-venv<\/code>\u5305\uff0c\u53ef\u4ee5\u901a\u8fc7\u547d\u4ee4<code>sudo yum install python3-venv<\/code>\u8fdb\u884c\u5b89\u88c5\u3002\u7136\u540e\uff0c\u9009\u62e9\u4e00\u4e2a\u76ee\u5f55\u6765\u5b58\u653e\u9879\u76ee\uff0c\u5e76\u5728\u8be5\u76ee\u5f55\u4e0b\u4f7f\u7528\u547d\u4ee4<code>python3 -m venv myenv<\/code>\u521b\u5efa\u4e00\u4e2a\u865a\u62df\u73af\u5883\u3002\u8fd9\u4e2a\u547d\u4ee4\u4f1a\u5728\u5f53\u524d\u76ee\u5f55\u4e0b\u521b\u5efa\u4e00\u4e2a\u540d\u4e3a<code>myenv<\/code>\u7684\u6587\u4ef6\u5939\uff0c\u5176\u4e2d\u5305\u542b\u72ec\u7acb\u7684Python\u89e3\u91ca\u5668\u548cpip\u5de5\u5177\u3002\u6fc0\u6d3b\u865a\u62df\u73af\u5883\uff0c\u901a\u8fc7\u547d\u4ee4<code>source myenv\/bin\/activate<\/code>\uff0c\u6fc0\u6d3b\u540e\u7ec8\u7aef\u63d0\u793a\u7b26\u4f1a\u53d1\u751f\u53d8\u5316\uff0c\u8868\u660e\u6b63\u5728\u4f7f\u7528\u865a\u62df\u73af\u5883\u3002\u73b0\u5728\uff0c\u60a8\u53ef\u4ee5\u5728\u8be5\u73af\u5883\u4e0b\u5b89\u88c5\u9879\u76ee\u6240\u9700\u7684\u4f9d\u8d56\u5305\uff0c\u800c\u4e0d\u5f71\u54cd\u5168\u5c40\u7684Python\u73af\u5883\u3002<\/p>\n<\/p>\n<p><p>\u4e00\u3001\u5728CentOS\u4e0a\u5b89\u88c5Python<\/p>\n<\/p>\n<p><p>\u5728CentOS\u4e0a\u5b89\u88c5Python\u662f\u5f00\u59cb\u7f16\u5199Python\u7a0b\u5e8f\u7684\u7b2c\u4e00\u6b65\u3002CentOS\u9ed8\u8ba4\u53ef\u80fd\u9884\u88c5\u4e86Python 2.x\u7248\u672c\uff0c\u4f46\u4e3a\u4e86\u4f7f\u7528Python\u7684\u6700\u65b0\u529f\u80fd\u548c\u5e93\uff0c\u6211\u4eec\u901a\u5e38\u9700\u8981\u5b89\u88c5Python 3.x\u7248\u672c\u3002<\/p>\n<\/p>\n<ol>\n<li>\n<p><strong>\u68c0\u67e5\u5f53\u524d\u7684Python\u7248\u672c<\/strong>\uff1a\u5728\u7ec8\u7aef\u4e2d\u8f93\u5165<code>python --version<\/code>\u6216<code>python3 --version<\/code>\u6765\u67e5\u770b\u7cfb\u7edf\u4e2d\u662f\u5426\u5df2\u7ecf\u5b89\u88c5\u4e86Python\u4ee5\u53ca\u5176\u7248\u672c\u3002\u5982\u679c\u6ca1\u6709\u5b89\u88c5\u6216\u7248\u672c\u8fc7\u4f4e\uff0c\u53ef\u4ee5\u901a\u8fc7\u4ee5\u4e0b\u6b65\u9aa4\u5b89\u88c5Python 3\u3002<\/p>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u5b89\u88c5Python 3<\/strong>\uff1a\u9996\u5148\uff0c\u66f4\u65b0\u7cfb\u7edf\u5305\u7ba1\u7406\u5668\uff0c\u4f7f\u7528\u547d\u4ee4<code>sudo yum update<\/code>\u3002\u63a5\u4e0b\u6765\uff0c\u901a\u8fc7<code>sudo yum install python3<\/code>\u547d\u4ee4\u5b89\u88c5Python 3\u3002\u5b89\u88c5\u5b8c\u6210\u540e\uff0c\u518d\u6b21\u68c0\u67e5Python\u7248\u672c\u4ee5\u786e\u8ba4\u5b89\u88c5\u6210\u529f\u3002<\/p>\n<\/p>\n<\/li>\n<\/ol>\n<p><p>\u5b89\u88c5\u5b8c\u6210\u540e\uff0c\u60a8\u8fd8\u53ef\u4ee5\u5b89\u88c5pip\uff0c\u8fd9\u662fPython\u7684\u5305\u7ba1\u7406\u5668\uff0c\u65b9\u4fbf\u5b89\u88c5\u5404\u79cdPython\u5e93\u3002\u4f7f\u7528\u547d\u4ee4<code>sudo yum install python3-pip<\/code>\u8fdb\u884c\u5b89\u88c5\u3002<\/p>\n<\/p>\n<p><p>\u4e8c\u3001\u914d\u7f6ePython\u865a\u62df\u73af\u5883<\/p>\n<\/p>\n<p><p>\u914d\u7f6ePython\u865a\u62df\u73af\u5883\u662f\u4e3a\u4e86\u5728\u4e0d\u540c\u9879\u76ee\u4e4b\u95f4\u9694\u79bbPython\u5305\u548c\u4f9d\u8d56\u3002\u8fd9\u6837\u53ef\u4ee5\u9632\u6b62\u4e0d\u540c\u9879\u76ee\u4e4b\u95f4\u7684\u4f9d\u8d56\u51b2\u7a81\uff0c\u5e76\u4e14\u53ef\u4ee5\u65b9\u4fbf\u5730\u7ba1\u7406\u9879\u76ee\u7684\u4f9d\u8d56\u5305\u3002<\/p>\n<\/p>\n<ol>\n<li>\n<p><strong>\u5b89\u88c5Python\u865a\u62df\u73af\u5883\u5de5\u5177<\/strong>\uff1a\u786e\u4fdd\u60a8\u5df2\u7ecf\u5b89\u88c5\u4e86<code>python3-venv<\/code>\uff0c\u5982\u679c\u6ca1\u6709\uff0c\u53ef\u4ee5\u901a\u8fc7<code>sudo yum install python3-venv<\/code>\u6765\u5b89\u88c5\u3002<\/p>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u521b\u5efa\u865a\u62df\u73af\u5883<\/strong>\uff1a\u5728\u9879\u76ee\u76ee\u5f55\u4e0b\u8fd0\u884c<code>python3 -m venv myenv<\/code>\u6765\u521b\u5efa\u4e00\u4e2a\u65b0\u7684\u865a\u62df\u73af\u5883<code>myenv<\/code>\u3002\u8fd9\u4e2a\u547d\u4ee4\u4f1a\u5728\u5f53\u524d\u76ee\u5f55\u4e0b\u521b\u5efa\u4e00\u4e2a\u540d\u4e3a<code>myenv<\/code>\u7684\u6587\u4ef6\u5939\uff0c\u5176\u4e2d\u5305\u542b\u72ec\u7acb\u7684Python\u73af\u5883\u3002<\/p>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u6fc0\u6d3b\u865a\u62df\u73af\u5883<\/strong>\uff1a\u4f7f\u7528\u547d\u4ee4<code>source myenv\/bin\/activate<\/code>\u6765\u6fc0\u6d3b\u865a\u62df\u73af\u5883\u3002\u6fc0\u6d3b\u540e\uff0c\u7ec8\u7aef\u7684\u63d0\u793a\u7b26\u4f1a\u53d1\u751f\u53d8\u5316\uff0c\u663e\u793a\u5f53\u524d\u6b63\u5728\u4f7f\u7528\u7684\u865a\u62df\u73af\u5883\u540d\u79f0\u3002<\/p>\n<\/p>\n<\/li>\n<\/ol>\n<p><p>\u5728\u865a\u62df\u73af\u5883\u6fc0\u6d3b\u72b6\u6001\u4e0b\uff0c\u60a8\u53ef\u4ee5\u4f7f\u7528<code>pip install &lt;package_name&gt;<\/code>\u6765\u5b89\u88c5\u9879\u76ee\u6240\u9700\u7684Python\u5e93\uff0c\u800c\u8fd9\u4e9b\u5e93\u53ea\u4f1a\u5b89\u88c5\u5728\u865a\u62df\u73af\u5883\u4e2d\uff0c\u4e0d\u4f1a\u5f71\u54cd\u5230\u7cfb\u7edf\u7684\u5168\u5c40\u73af\u5883\u3002<\/p>\n<\/p>\n<p><p>\u4e09\u3001\u9009\u62e9\u6587\u672c\u7f16\u8f91\u5668\u6216IDE<\/p>\n<\/p>\n<p><p>\u9009\u62e9\u5408\u9002\u7684\u6587\u672c\u7f16\u8f91\u5668\u6216\u96c6\u6210\u5f00\u53d1\u73af\u5883\uff08IDE\uff09\u5bf9\u4e8ePython\u7f16\u7a0b\u6548\u7387\u81f3\u5173\u91cd\u8981\u3002\u4e0d\u540c\u7684\u7f16\u8f91\u5668\u548cIDE\u63d0\u4f9b\u4e86\u4e0d\u540c\u7684\u529f\u80fd\u548c\u6269\u5c55\uff0c\u4ee5\u5e2e\u52a9\u5f00\u53d1\u4eba\u5458\u66f4\u9ad8\u6548\u5730\u7f16\u5199\u4ee3\u7801\u3002<\/p>\n<\/p>\n<ol>\n<li>\n<p><strong>\u6587\u672c\u7f16\u8f91\u5668<\/strong>\uff1a\u6587\u672c\u7f16\u8f91\u5668\u5982Vim\u3001Nano\u548cEmacs\u662f\u8f7b\u91cf\u7ea7\u7684\u9009\u9879\uff0c\u9002\u5408\u4e8e\u5feb\u901f\u7f16\u8f91\u6587\u4ef6\u3002Vim\u548cEmacs\u53ef\u4ee5\u901a\u8fc7\u63d2\u4ef6\u6269\u5c55\u529f\u80fd\uff0c\u5982\u8bed\u6cd5\u9ad8\u4eae\u3001\u81ea\u52a8\u5b8c\u6210\u548c\u8c03\u8bd5\u652f\u6301\u3002Nano\u5219\u662f\u4e00\u4e2a\u7b80\u5355\u6613\u7528\u7684\u7f16\u8f91\u5668\uff0c\u9002\u5408\u521d\u5b66\u8005\u3002<\/p>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u96c6\u6210\u5f00\u53d1\u73af\u5883\uff08IDE\uff09<\/strong>\uff1aIDE\u5982PyCharm\u3001Visual Studio Code\u548cEclipse PyDev\u63d0\u4f9b\u4e86\u5f3a\u5927\u7684\u529f\u80fd\uff0c\u5982\u4ee3\u7801\u81ea\u52a8\u8865\u5168\u3001\u8c03\u8bd5\u5668\u3001\u7248\u672c\u63a7\u5236\u96c6\u6210\u548c\u6d4b\u8bd5\u5de5\u5177\u3002PyCharm\u662f\u4e13\u4e3aPython\u5f00\u53d1\u8bbe\u8ba1\u7684IDE\uff0c\u63d0\u4f9b\u4e86\u4e30\u5bcc\u7684\u63d2\u4ef6\u548c\u5de5\u5177\u652f\u6301\u3002Visual Studio Code\u662f\u4e00\u4e2a\u8f7b\u91cf\u7ea7\u4e14\u7075\u6d3b\u7684\u7f16\u8f91\u5668\uff0c\u652f\u6301\u591a\u79cd\u8bed\u8a00\u548c\u63d2\u4ef6\u6269\u5c55\u3002Eclipse PyDev\u662f\u5728Eclipse IDE\u4e0a\u6269\u5c55\u7684Python\u5f00\u53d1\u73af\u5883\u3002<\/p>\n<\/p>\n<\/li>\n<\/ol>\n<p><p>\u9009\u62e9\u6587\u672c\u7f16\u8f91\u5668\u6216IDE\u65f6\uff0c\u5e94\u6839\u636e\u4e2a\u4eba\u9700\u6c42\u548c\u9879\u76ee\u89c4\u6a21\u6765\u51b3\u5b9a\u3002\u5bf9\u4e8e\u5927\u578b\u9879\u76ee\u548c\u56e2\u961f\u534f\u4f5c\uff0c\u4f7f\u7528\u529f\u80fd\u4e30\u5bcc\u7684IDE\u53ef\u80fd\u66f4\u4e3a\u5408\u9002\uff0c\u800c\u5bf9\u4e8e\u7b80\u5355\u7684\u811a\u672c\u548c\u5c0f\u578b\u9879\u76ee\uff0c\u8f7b\u91cf\u7ea7\u7684\u6587\u672c\u7f16\u8f91\u5668\u53ef\u80fd\u66f4\u4e3a\u65b9\u4fbf\u3002<\/p>\n<\/p>\n<p><p>\u56db\u3001\u7f16\u5199\u548c\u8fd0\u884cPython\u4ee3\u7801<\/p>\n<\/p>\n<p><p>\u7f16\u5199\u548c\u8fd0\u884cPython\u4ee3\u7801\u662fPython\u7f16\u7a0b\u7684\u6838\u5fc3\u90e8\u5206\u3002\u5728CentOS\u4e0a\uff0c\u60a8\u53ef\u4ee5\u4f7f\u7528\u9009\u62e9\u7684\u6587\u672c\u7f16\u8f91\u5668\u6216IDE\u6765\u7f16\u5199Python\u4ee3\u7801\uff0c\u5e76\u901a\u8fc7\u547d\u4ee4\u884c\u8fd0\u884c\u4ee3\u7801\u3002<\/p>\n<\/p>\n<ol>\n<li>\n<p><strong>\u7f16\u5199Python\u4ee3\u7801<\/strong>\uff1a\u5728\u6587\u672c\u7f16\u8f91\u5668\u6216IDE\u4e2d\u521b\u5efa\u4e00\u4e2a\u65b0\u7684Python\u6587\u4ef6\uff0c\u6587\u4ef6\u540d\u4ee5<code>.py<\/code>\u4e3a\u6269\u5c55\u540d\u3002\u7f16\u5199Python\u4ee3\u7801\u65f6\uff0c\u5e94\u6ce8\u610f\u4ee3\u7801\u7684\u683c\u5f0f\u548c\u89c4\u8303\uff0c\u4ee5\u63d0\u9ad8\u53ef\u8bfb\u6027\u548c\u53ef\u7ef4\u62a4\u6027\u3002<\/p>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u8fd0\u884cPython\u4ee3\u7801<\/strong>\uff1a\u5728\u7ec8\u7aef\u4e2d\u5bfc\u822a\u5230Python\u6587\u4ef6\u6240\u5728\u7684\u76ee\u5f55\uff0c\u4f7f\u7528\u547d\u4ee4<code>python3 &lt;filename&gt;.py<\/code>\u6765\u8fd0\u884cPython\u4ee3\u7801\u3002\u786e\u4fdd\u5728\u8fd0\u884c\u4ee3\u7801\u4e4b\u524d\uff0c\u6fc0\u6d3b\u865a\u62df\u73af\u5883\uff0c\u4ee5\u786e\u4fdd\u4f7f\u7528\u6b63\u786e\u7684Python\u89e3\u91ca\u5668\u548c\u4f9d\u8d56\u5305\u3002<\/p>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u8c03\u8bd5Python\u4ee3\u7801<\/strong>\uff1a\u5728\u7f16\u5199\u548c\u8fd0\u884c\u4ee3\u7801\u65f6\uff0c\u53ef\u80fd\u4f1a\u9047\u5230\u9519\u8bef\u548c\u5f02\u5e38\u3002\u4f7f\u7528\u8c03\u8bd5\u5de5\u5177\u548c\u65e5\u5fd7\u8bb0\u5f55\u6765\u8bca\u65ad\u548c\u89e3\u51b3\u95ee\u9898\u3002\u8bb8\u591aIDE\u63d0\u4f9b\u4e86\u5185\u7f6e\u7684\u8c03\u8bd5\u5668\uff0c\u53ef\u4ee5\u8bbe\u7f6e\u65ad\u70b9\u3001\u67e5\u770b\u53d8\u91cf\u503c\u548c\u9010\u6b65\u6267\u884c\u4ee3\u7801\u3002<\/p>\n<\/p>\n<\/li>\n<\/ol>\n<p><p>\u4e94\u3001\u7ba1\u7406Python\u5305\u548c\u4f9d\u8d56<\/p>\n<\/p>\n<p><p>\u7ba1\u7406Python\u5305\u548c\u4f9d\u8d56\u662f\u786e\u4fdd\u9879\u76ee\u6b63\u786e\u8fd0\u884c\u7684\u91cd\u8981\u6b65\u9aa4\u3002\u5728CentOS\u4e0a\uff0c\u60a8\u53ef\u4ee5\u4f7f\u7528pip\u5de5\u5177\u6765\u5b89\u88c5\u548c\u7ba1\u7406Python\u5305\u3002<\/p>\n<\/p>\n<ol>\n<li>\n<p><strong>\u5b89\u88c5Python\u5305<\/strong>\uff1a\u5728\u865a\u62df\u73af\u5883\u4e2d\uff0c\u4f7f\u7528<code>pip install &lt;package_name&gt;<\/code>\u547d\u4ee4\u5b89\u88c5\u6240\u9700\u7684Python\u5305\u3002\u53ef\u4ee5\u901a\u8fc7<code>pip list<\/code>\u547d\u4ee4\u67e5\u770b\u5df2\u5b89\u88c5\u7684\u5305\u53ca\u5176\u7248\u672c\u3002<\/p>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u7ba1\u7406\u4f9d\u8d56\u6587\u4ef6<\/strong>\uff1a\u4e3a\u4e86\u65b9\u4fbf\u5171\u4eab\u548c\u91cd\u73b0\u9879\u76ee\u73af\u5883\uff0c\u53ef\u4ee5\u4f7f\u7528<code>pip freeze &gt; requirements.txt<\/code>\u547d\u4ee4\u751f\u6210\u4e00\u4e2a\u4f9d\u8d56\u6587\u4ef6<code>requirements.txt<\/code>\uff0c\u5176\u4e2d\u5217\u51fa\u4e86\u6240\u6709\u5df2\u5b89\u88c5\u7684\u5305\u53ca\u5176\u7248\u672c\u3002\u5728\u65b0\u73af\u5883\u4e2d\uff0c\u53ef\u4ee5\u4f7f\u7528<code>pip install -r requirements.txt<\/code>\u547d\u4ee4\u5b89\u88c5\u6240\u6709\u4f9d\u8d56\u3002<\/p>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u5347\u7ea7\u548c\u5378\u8f7d\u5305<\/strong>\uff1a\u4f7f\u7528<code>pip install --upgrade &lt;package_name&gt;<\/code>\u547d\u4ee4\u6765\u5347\u7ea7\u5df2\u5b89\u88c5\u7684\u5305\uff0c\u4f7f\u7528<code>pip uninstall &lt;package_name&gt;<\/code>\u547d\u4ee4\u6765\u5378\u8f7d\u4e0d\u518d\u9700\u8981\u7684\u5305\u3002<\/p>\n<\/p>\n<\/li>\n<\/ol>\n<p><p>\u901a\u8fc7\u5408\u7406\u7ba1\u7406Python\u5305\u548c\u4f9d\u8d56\uff0c\u53ef\u4ee5\u786e\u4fdd\u9879\u76ee\u7684\u53ef\u79fb\u690d\u6027\u548c\u53ef\u7ef4\u62a4\u6027\u3002<\/p>\n<\/p>\n<p><p>\u516d\u3001\u4f7f\u7528\u7248\u672c\u63a7\u5236\u7cfb\u7edf<\/p>\n<\/p>\n<p><p>\u4f7f\u7528\u7248\u672c\u63a7\u5236\u7cfb\u7edf\uff08VCS\uff09\u662f\u8f6f\u4ef6\u5f00\u53d1\u4e2d\u7684\u6700\u4f73\u5b9e\u8df5\u4e4b\u4e00\u3002Git\u662f\u6700\u6d41\u884c\u7684\u7248\u672c\u63a7\u5236\u7cfb\u7edf\u4e4b\u4e00\uff0c\u9002\u7528\u4e8e\u7ba1\u7406Python\u9879\u76ee\u7684\u4ee3\u7801\u548c\u7248\u672c\u3002<\/p>\n<\/p>\n<ol>\n<li>\n<p><strong>\u5b89\u88c5Git<\/strong>\uff1a\u5728CentOS\u4e0a\uff0c\u4f7f\u7528\u547d\u4ee4<code>sudo yum install git<\/code>\u6765\u5b89\u88c5Git\u3002\u5b89\u88c5\u5b8c\u6210\u540e\uff0c\u901a\u8fc7<code>git --version<\/code>\u68c0\u67e5\u5b89\u88c5\u662f\u5426\u6210\u529f\u3002<\/p>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u521d\u59cb\u5316Git\u4ed3\u5e93<\/strong>\uff1a\u5728\u9879\u76ee\u76ee\u5f55\u4e0b\uff0c\u4f7f\u7528<code>git init<\/code>\u547d\u4ee4\u521d\u59cb\u5316\u4e00\u4e2a\u65b0\u7684Git\u4ed3\u5e93\u3002\u521b\u5efa<code>.gitignore<\/code>\u6587\u4ef6\u6765\u6307\u5b9a\u4e0d\u9700\u8981\u7248\u672c\u63a7\u5236\u7684\u6587\u4ef6\u548c\u76ee\u5f55\u3002<\/p>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u63d0\u4ea4\u4ee3\u7801\u53d8\u66f4<\/strong>\uff1a\u4f7f\u7528<code>git add &lt;file&gt;<\/code>\u547d\u4ee4\u5c06\u66f4\u6539\u7684\u6587\u4ef6\u6dfb\u52a0\u5230\u6682\u5b58\u533a\uff0c\u7136\u540e\u4f7f\u7528<code>git commit -m &quot;commit message&quot;<\/code>\u547d\u4ee4\u63d0\u4ea4\u66f4\u6539\u3002<\/p>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u8fdc\u7a0b\u4ed3\u5e93\u7ba1\u7406<\/strong>\uff1a\u4f7f\u7528Git\u53ef\u4ee5\u8fde\u63a5\u5230\u8fdc\u7a0b\u4ed3\u5e93\uff08\u5982GitHub\u3001GitLab\uff09\uff0c\u4ee5\u4fbf\u4e0e\u56e2\u961f\u534f\u4f5c\u548c\u5907\u4efd\u4ee3\u7801\u3002\u4f7f\u7528<code>git remote add origin &lt;repository_url&gt;<\/code>\u547d\u4ee4\u6dfb\u52a0\u8fdc\u7a0b\u4ed3\u5e93\uff0c\u7136\u540e\u4f7f\u7528<code>git push<\/code>\u547d\u4ee4\u5c06\u672c\u5730\u66f4\u6539\u63a8\u9001\u5230\u8fdc\u7a0b\u4ed3\u5e93\u3002<\/p>\n<\/p>\n<\/li>\n<\/ol>\n<p><p>\u901a\u8fc7\u4f7f\u7528\u7248\u672c\u63a7\u5236\u7cfb\u7edf\uff0c\u53ef\u4ee5\u6709\u6548\u5730\u7ba1\u7406\u4ee3\u7801\u7248\u672c\u3001\u8ffd\u8e2a\u66f4\u6539\u5386\u53f2\uff0c\u5e76\u5728\u56e2\u961f\u534f\u4f5c\u4e2d\u63d0\u9ad8\u6548\u7387\u3002<\/p>\n<\/p>\n<p><p>\u4e03\u3001\u6d4b\u8bd5\u548c\u8c03\u8bd5Python\u4ee3\u7801<\/p>\n<\/p>\n<p><p>\u6d4b\u8bd5\u548c\u8c03\u8bd5\u662f\u5f00\u53d1\u8fc7\u7a0b\u4e2d\u4e0d\u53ef\u6216\u7f3a\u7684\u90e8\u5206\uff0c\u786e\u4fdd\u4ee3\u7801\u7684\u6b63\u786e\u6027\u548c\u5065\u58ee\u6027\u3002\u5728CentOS\u4e0a\uff0c\u60a8\u53ef\u4ee5\u4f7f\u7528Python\u7684\u5185\u7f6e\u6a21\u5757\u548c\u7b2c\u4e09\u65b9\u5e93\u6765\u8fdb\u884c\u6d4b\u8bd5\u548c\u8c03\u8bd5\u3002<\/p>\n<\/p>\n<ol>\n<li>\n<p><strong>\u7f16\u5199\u6d4b\u8bd5\u7528\u4f8b<\/strong>\uff1a\u4f7f\u7528Python\u7684<code>unittest<\/code>\u6a21\u5757\u6765\u7f16\u5199\u6d4b\u8bd5\u7528\u4f8b\u3002\u521b\u5efa\u4e00\u4e2a\u6d4b\u8bd5\u6587\u4ef6\uff0c\u5e76\u5b9a\u4e49\u6d4b\u8bd5\u7c7b\u548c\u65b9\u6cd5\uff0c\u4f7f\u7528\u65ad\u8a00\u8bed\u53e5\u6765\u9a8c\u8bc1\u4ee3\u7801\u7684\u884c\u4e3a\u3002\u901a\u8fc7\u8fd0\u884c<code>python3 -m unittest &lt;test_file&gt;.py<\/code>\u547d\u4ee4\u6765\u6267\u884c\u6d4b\u8bd5\u3002<\/p>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u4f7f\u7528\u7b2c\u4e09\u65b9\u6d4b\u8bd5\u6846\u67b6<\/strong>\uff1a\u9664\u4e86<code>unittest<\/code>\uff0c\u8fd8\u6709\u8bb8\u591a\u7b2c\u4e09\u65b9\u6d4b\u8bd5\u6846\u67b6\u53ef\u4f9b\u9009\u62e9\uff0c\u5982<code>pytest<\/code>\u548c<code>nose<\/code>\u3002<code>pytest<\/code>\u63d0\u4f9b\u4e86\u7b80\u6d01\u7684\u8bed\u6cd5\u548c\u5f3a\u5927\u7684\u529f\u80fd\uff0c\u9002\u5408\u4e8e\u7f16\u5199\u548c\u8fd0\u884c\u6d4b\u8bd5\u3002\u5b89\u88c5<code>pytest<\/code>\u540e\uff0c\u53ef\u4ee5\u901a\u8fc7<code>pytest &lt;test_file&gt;.py<\/code>\u547d\u4ee4\u8fd0\u884c\u6d4b\u8bd5\u3002<\/p>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u8c03\u8bd5\u4ee3\u7801<\/strong>\uff1a\u4f7f\u7528Python\u7684<code>pdb<\/code>\u6a21\u5757\u8fdb\u884c\u8c03\u8bd5\u3002\u5728\u4ee3\u7801\u4e2d\u63d2\u5165<code>import pdb; pdb.set_trace()<\/code>\u8bed\u53e5\u6765\u8bbe\u7f6e\u65ad\u70b9\uff0c\u8fd0\u884c\u4ee3\u7801\u65f6\u4f1a\u6682\u505c\u5728\u65ad\u70b9\u5904\uff0c\u5141\u8bb8\u9010\u6b65\u6267\u884c\u548c\u68c0\u67e5\u53d8\u91cf\u3002\u8bb8\u591aIDE\u63d0\u4f9b\u4e86\u5185\u7f6e\u7684\u8c03\u8bd5\u5668\uff0c\u53ef\u4ee5\u8bbe\u7f6e\u65ad\u70b9\u3001\u67e5\u770b\u53d8\u91cf\u503c\u548c\u9010\u6b65\u6267\u884c\u4ee3\u7801\u3002<\/p>\n<\/p>\n<\/li>\n<\/ol>\n<p><p>\u901a\u8fc7\u7f16\u5199\u6d4b\u8bd5\u7528\u4f8b\u548c\u4f7f\u7528\u8c03\u8bd5\u5de5\u5177\uff0c\u60a8\u53ef\u4ee5\u63d0\u9ad8\u4ee3\u7801\u7684\u8d28\u91cf\u548c\u53ef\u9760\u6027\uff0c\u786e\u4fdd\u9879\u76ee\u7684\u7a33\u5b9a\u6027\u3002<\/p>\n<\/p>\n<p><p>\u516b\u3001\u90e8\u7f72Python\u5e94\u7528<\/p>\n<\/p>\n<p><p>\u5728CentOS\u4e0a\u90e8\u7f72Python\u5e94\u7528\u662f\u5c06\u5f00\u53d1\u5b8c\u6210\u7684\u5e94\u7528\u63a8\u5411\u751f\u4ea7\u73af\u5883\u7684\u91cd\u8981\u6b65\u9aa4\u3002\u90e8\u7f72\u8fc7\u7a0b\u53ef\u80fd\u5305\u62ec\u914d\u7f6e\u670d\u52a1\u5668\u3001\u8bbe\u7f6e\u73af\u5883\u53d8\u91cf\u3001\u542f\u52a8\u5e94\u7528\u670d\u52a1\u7b49\u3002<\/p>\n<\/p>\n<ol>\n<li>\n<p><strong>\u9009\u62e9Web\u670d\u52a1\u5668<\/strong>\uff1a\u9009\u62e9\u5408\u9002\u7684Web\u670d\u52a1\u5668\u6765\u6258\u7ba1Python\u5e94\u7528\uff0c\u5982Apache\u3001Nginx\u7b49\u3002\u5bf9\u4e8ePython Web\u5e94\u7528\uff0c\u53ef\u4ee5\u4f7f\u7528Gunicorn\u6216uWSGI\u4f5c\u4e3a\u5e94\u7528\u670d\u52a1\u5668\uff0c\u4e0eWeb\u670d\u52a1\u5668\u7ed3\u5408\u4f7f\u7528\u4ee5\u63d0\u9ad8\u6027\u80fd\u3002<\/p>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u914d\u7f6e\u73af\u5883<\/strong>\uff1a\u5728\u90e8\u7f72\u73af\u5883\u4e2d\uff0c\u8bbe\u7f6e\u5fc5\u8981\u7684\u73af\u5883\u53d8\u91cf\u548c\u914d\u7f6e\u6587\u4ef6\uff0c\u4ee5\u786e\u4fdd\u5e94\u7528\u6b63\u5e38\u8fd0\u884c\u3002\u521b\u5efa\u548c\u6fc0\u6d3b\u865a\u62df\u73af\u5883\uff0c\u5b89\u88c5\u5e94\u7528\u6240\u9700\u7684\u4f9d\u8d56\u5305\u3002<\/p>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u542f\u52a8\u5e94\u7528\u670d\u52a1<\/strong>\uff1a\u4f7f\u7528\u5e94\u7528\u670d\u52a1\u5668\uff08\u5982Gunicorn\uff09\u542f\u52a8Python\u5e94\u7528\uff0c\u5e76\u914d\u7f6eWeb\u670d\u52a1\u5668\uff08\u5982Nginx\uff09\u6765\u53cd\u5411\u4ee3\u7406\u8bf7\u6c42\u5230\u5e94\u7528\u670d\u52a1\u5668\u3002\u53ef\u4ee5\u4f7f\u7528\u7cfb\u7edf\u670d\u52a1\u7ba1\u7406\u5de5\u5177\uff08\u5982systemd\uff09\u6765\u7ba1\u7406\u5e94\u7528\u7684\u542f\u52a8\u548c\u505c\u6b62\u3002<\/p>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u76d1\u63a7\u548c\u7ef4\u62a4<\/strong>\uff1a\u5728\u5e94\u7528\u90e8\u7f72\u540e\uff0c\u8bbe\u7f6e\u76d1\u63a7\u5de5\u5177\u6765\u8ddf\u8e2a\u5e94\u7528\u7684\u6027\u80fd\u548c\u5065\u5eb7\u72b6\u51b5\u3002\u5b9a\u671f\u66f4\u65b0\u5e94\u7528\u548c\u4f9d\u8d56\u5305\uff0c\u4ee5\u4fee\u590d\u6f0f\u6d1e\u548c\u63d0\u9ad8\u6027\u80fd\u3002<\/p>\n<\/p>\n<\/li>\n<\/ol>\n<p><p>\u901a\u8fc7\u5408\u7406\u7684\u90e8\u7f72\u6d41\u7a0b\u548c\u6301\u7eed\u7684\u76d1\u63a7\uff0c\u60a8\u53ef\u4ee5\u786e\u4fddPython\u5e94\u7528\u5728\u751f\u4ea7\u73af\u5883\u4e2d\u7684\u7a33\u5b9a\u8fd0\u884c\u3002<\/p>\n<\/p>\n<h2><strong>\u76f8\u5173\u95ee\u7b54FAQs\uff1a<\/strong><\/h2>\n<p> <strong>\u5982\u4f55\u5728CentOS\u4e0a\u5b89\u88c5Python\u73af\u5883\uff1f<\/strong><br \/>\u5728CentOS\u4e0a\u5b89\u88c5Python\u975e\u5e38\u7b80\u5355\u3002\u53ef\u4ee5\u901a\u8fc7\u4ee5\u4e0b\u6b65\u9aa4\u6765\u5b8c\u6210\uff1a  <\/p>\n<ol>\n<li>\u6253\u5f00\u7ec8\u7aef\u5e76\u4f7f\u7528<code>yum<\/code>\u5305\u7ba1\u7406\u5668\u6765\u5b89\u88c5Python\u3002\u5e38\u7528\u7684\u547d\u4ee4\u662f<code>sudo yum install python3<\/code>\uff0c\u8fd9\u5c06\u5b89\u88c5Python 3\u7684\u6700\u65b0\u7248\u672c\u3002  <\/li>\n<li>\u5b89\u88c5\u5b8c\u6210\u540e\uff0c\u53ef\u4ee5\u901a\u8fc7\u8f93\u5165<code>python3 --version<\/code>\u6765\u9a8c\u8bc1\u662f\u5426\u5b89\u88c5\u6210\u529f\u4ee5\u53ca\u67e5\u770b\u7248\u672c\u53f7\u3002  <\/li>\n<li>\u5982\u679c\u9700\u8981\u4f7f\u7528pip\uff08Python\u7684\u5305\u7ba1\u7406\u5de5\u5177\uff09\uff0c\u53ef\u4ee5\u901a\u8fc7<code>sudo yum install python3-pip<\/code>\u8fdb\u884c\u5b89\u88c5\u3002\u5b89\u88c5\u540e\uff0c\u4f7f\u7528<code>pip3 --version<\/code>\u6765\u786e\u8ba4\u5b83\u662f\u5426\u6b63\u5e38\u5de5\u4f5c\u3002<\/li>\n<\/ol>\n<p><strong>\u5728CentOS\u4e0a\u5982\u4f55\u521b\u5efa\u548c\u8fd0\u884cPython\u811a\u672c\uff1f<\/strong><br \/>\u521b\u5efa\u548c\u8fd0\u884cPython\u811a\u672c\u7684\u6b65\u9aa4\u5982\u4e0b\uff1a  <\/p>\n<ol>\n<li>\u4f7f\u7528\u6587\u672c\u7f16\u8f91\u5668\uff08\u5982<code>vim<\/code>\u6216<code>nano<\/code>\uff09\u521b\u5efa\u4e00\u4e2a\u65b0\u7684Python\u6587\u4ef6\uff0c\u4f8b\u5982<code>hello.py<\/code>\u3002\u8f93\u5165\u547d\u4ee4<code>vim hello.py<\/code>\u6765\u6253\u5f00\u7f16\u8f91\u5668\u3002  <\/li>\n<li>\u5728\u6587\u4ef6\u4e2d\u7f16\u5199\u4f60\u7684Python\u4ee3\u7801\uff0c\u4f8b\u5982\uff1a\n<pre><code class=\"language-python\">print(&quot;Hello, World!&quot;)\n<\/code><\/pre>\n<\/li>\n<li>\u4fdd\u5b58\u5e76\u9000\u51fa\u7f16\u8f91\u5668\u540e\uff0c\u901a\u8fc7\u547d\u4ee4<code>python3 hello.py<\/code>\u6765\u8fd0\u884c\u811a\u672c\u3002\u5982\u679c\u4e00\u5207\u987a\u5229\uff0c\u4f60\u5c06\u770b\u5230&quot;Hello, World!&quot;\u7684\u8f93\u51fa\u7ed3\u679c\u3002<\/li>\n<\/ol>\n<p><strong>\u5982\u4f55\u5728CentOS\u4e0a\u4f7f\u7528\u865a\u62df\u73af\u5883\u7ba1\u7406Python\u9879\u76ee\uff1f<\/strong><br \/>\u4f7f\u7528\u865a\u62df\u73af\u5883\u53ef\u4ee5\u5e2e\u52a9\u4f60\u5728\u540c\u4e00\u53f0\u673a\u5668\u4e0a\u7ba1\u7406\u591a\u4e2aPython\u9879\u76ee\u7684\u4f9d\u8d56\u3002\u4ee5\u4e0b\u662f\u521b\u5efa\u548c\u4f7f\u7528\u865a\u62df\u73af\u5883\u7684\u6b65\u9aa4\uff1a  <\/p>\n<ol>\n<li>\u9996\u5148\uff0c\u786e\u4fdd\u5df2\u5b89\u88c5<code>python3-venv<\/code>\u5305\uff0c\u53ef\u4ee5\u4f7f\u7528\u547d\u4ee4<code>sudo yum install python3-venv<\/code>\u3002  <\/li>\n<li>\u521b\u5efa\u4e00\u4e2a\u65b0\u7684\u865a\u62df\u73af\u5883\uff0c\u547d\u4ee4\u4e3a<code>python3 -m venv myenv<\/code>\uff0c\u8fd9\u5c06\u521b\u5efa\u4e00\u4e2a\u540d\u4e3a<code>myenv<\/code>\u7684\u6587\u4ef6\u5939\uff0c\u91cc\u9762\u5305\u542b\u72ec\u7acb\u7684Python\u73af\u5883\u3002  <\/li>\n<li>\u6fc0\u6d3b\u865a\u62df\u73af\u5883\uff0c\u8fd0\u884c<code>source myenv\/bin\/activate<\/code>\u3002\u6b64\u65f6\uff0c\u547d\u4ee4\u884c\u63d0\u793a\u7b26\u4f1a\u6539\u53d8\uff0c\u8868\u793a\u4f60\u5df2\u7ecf\u8fdb\u5165\u4e86\u865a\u62df\u73af\u5883\u3002  <\/li>\n<li>\u5728\u865a\u62df\u73af\u5883\u4e2d\u5b89\u88c5\u6240\u9700\u7684\u5e93\uff0c\u4f8b\u5982\u4f7f\u7528<code>pip install requests<\/code>\u3002  <\/li>\n<li>\u5b8c\u6210\u5de5\u4f5c\u540e\uff0c\u53ef\u4ee5\u901a\u8fc7\u8fd0\u884c<code>deactivate<\/code>\u547d\u4ee4\u6765\u9000\u51fa\u865a\u62df\u73af\u5883\u3002<\/li>\n<\/ol>\n","protected":false},"excerpt":{"rendered":"\u5728CentOS\u4e0a\u4f7f\u7528Python\u7f16\u7a0b\uff0c\u9996\u5148\u9700\u8981\u786e\u4fddPython\u73af\u5883\u5df2\u5b89\u88c5\u3001\u914d\u7f6ePython\u865a\u62df\u73af\u5883\u4ee5\u9694\u79bb\u9879\u76ee\u3001 [&hellip;]","protected":false},"author":3,"featured_media":996634,"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\/996625"}],"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=996625"}],"version-history":[{"count":"1","href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/996625\/revisions"}],"predecessor-version":[{"id":996636,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/996625\/revisions\/996636"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media\/996634"}],"wp:attachment":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media?parent=996625"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/categories?post=996625"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/tags?post=996625"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}