{"id":947069,"date":"2024-12-26T23:48:18","date_gmt":"2024-12-26T15:48:18","guid":{"rendered":"https:\/\/docs.pingcode.com\/ask\/ask-ask\/947069.html"},"modified":"2024-12-26T23:48:20","modified_gmt":"2024-12-26T15:48:20","slug":"sublime%e5%a6%82%e4%bd%95%e8%bd%bd%e5%85%a5python","status":"publish","type":"post","link":"https:\/\/docs.pingcode.com\/ask\/947069.html","title":{"rendered":"sublime\u5982\u4f55\u8f7d\u5165python"},"content":{"rendered":"<p style=\"text-align:center;\" ><img decoding=\"async\" src=\"https:\/\/cdn-kb.worktile.com\/kb\/wp-content\/uploads\/2024\/04\/25082958\/abaeb53a-ea15-40ca-ae20-03b91fe1b105.webp\" alt=\"sublime\u5982\u4f55\u8f7d\u5165python\" \/><\/p>\n<p><p> <strong>\u8981\u5728Sublime Text\u4e2d\u8f7d\u5165Python\uff0c\u53ef\u4ee5\u901a\u8fc7\u5b89\u88c5\u63d2\u4ef6\u3001\u914d\u7f6e\u6784\u5efa\u7cfb\u7edf\u3001\u8bbe\u7f6e\u73af\u5883\u53d8\u91cf\u6765\u5b9e\u73b0\u3002\u9996\u5148\uff0c\u786e\u4fdd\u5df2\u5b89\u88c5Python\u89e3\u91ca\u5668\uff0c\u7136\u540e\u5728Sublime\u4e2d\u5b89\u88c5Package Control\uff0c\u63a5\u7740\u901a\u8fc7Package Control\u5b89\u88c5\u4e0ePython\u76f8\u5173\u7684\u63d2\u4ef6\uff0c\u5982Anaconda\u6216SublimeREPL\uff0c\u6765\u589e\u5f3aPython\u7f16\u7a0b\u4f53\u9a8c\u3002\u914d\u7f6e\u6784\u5efa\u7cfb\u7edf\u4ee5\u4fbf\u8fd0\u884cPython\u811a\u672c\uff0c\u786e\u4fddPython\u8def\u5f84\u6b63\u786e\u3002\u6700\u540e\uff0c\u901a\u8fc7\u8bbe\u7f6e\u73af\u5883\u53d8\u91cf\u786e\u4fddSublime Text\u53ef\u4ee5\u6b63\u786e\u8bc6\u522bPython\u89e3\u91ca\u5668\u7684\u4f4d\u7f6e\u3002<\/strong><\/p>\n<\/p>\n<p><p>\u4e00\u3001\u5b89\u88c5\u548c\u914d\u7f6ePython<\/p>\n<\/p>\n<p><p>\u5728\u4f7f\u7528Sublime Text\u8fd0\u884cPython\u811a\u672c\u4e4b\u524d\uff0c\u9996\u5148\u9700\u8981\u786e\u4fdd\u5728\u60a8\u7684\u8ba1\u7b97\u673a\u4e0a\u5b89\u88c5\u4e86Python\u89e3\u91ca\u5668\u3002\u60a8\u53ef\u4ee5\u4ecePython\u7684\u5b98\u65b9\u7f51\u7ad9\u4e0b\u8f7d\u6700\u65b0\u7248\u672c\u7684Python\uff0c\u5e76\u6309\u7167\u63d0\u4f9b\u7684\u8bf4\u660e\u8fdb\u884c\u5b89\u88c5\u3002<\/p>\n<\/p>\n<ol>\n<li>\n<p><strong>\u4e0b\u8f7d\u5e76\u5b89\u88c5Python<\/strong>\uff1a\u8bbf\u95ee<a href=\"https:\/\/www.python.org\/downloads\/\">Python\u5b98\u65b9\u7f51\u7ad9<\/a>\u4e0b\u8f7d\u9002\u5408\u60a8\u64cd\u4f5c\u7cfb\u7edf\u7684Python\u7248\u672c\u3002\u5b89\u88c5\u8fc7\u7a0b\u4e2d\uff0c\u786e\u4fdd\u52fe\u9009\u201cAdd Python to PATH\u201d\u9009\u9879\uff0c\u8fd9\u6837\u53ef\u4ee5\u65b9\u4fbf\u540e\u7eed\u5728\u547d\u4ee4\u884c\u4e2d\u76f4\u63a5\u8c03\u7528Python\u3002<\/p>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u9a8c\u8bc1\u5b89\u88c5<\/strong>\uff1a\u5b89\u88c5\u5b8c\u6210\u540e\uff0c\u6253\u5f00\u547d\u4ee4\u63d0\u793a\u7b26\uff08Windows\uff09\u6216\u7ec8\u7aef\uff08Mac\/Linux\uff09\uff0c\u8f93\u5165<code>python --version<\/code>\u6216<code>python3 --version<\/code>\u4ee5\u9a8c\u8bc1Python\u662f\u5426\u5b89\u88c5\u6210\u529f\u5e76\u68c0\u67e5\u5176\u7248\u672c\u3002<\/p>\n<\/p>\n<\/li>\n<\/ol>\n<p><p>\u4e8c\u3001\u5b89\u88c5Package Control<\/p>\n<\/p>\n<p><p>Package Control\u662fSublime Text\u7684\u5305\u7ba1\u7406\u5668\uff0c\u5141\u8bb8\u60a8\u8f7b\u677e\u5730\u5b89\u88c5\u3001\u66f4\u65b0\u548c\u5220\u9664Sublime Text\u7684\u5404\u79cd\u63d2\u4ef6\u548c\u4e3b\u9898\u3002<\/p>\n<\/p>\n<ol>\n<li>\n<p><strong>\u5b89\u88c5Package Control<\/strong>\uff1a\u6253\u5f00Sublime Text\uff0c\u6309\u4e0b\u5feb\u6377\u952e<code>Ctrl+<\/code>\uff08Windows\/Linux\uff09\u6216<code>Cmd+<\/code>\uff08Mac\uff09\u6253\u5f00\u63a7\u5236\u53f0\u3002\u5728\u63a7\u5236\u53f0\u4e2d\uff0c\u7c98\u8d34\u4ee5\u4e0bPython\u4ee3\u7801\u4ee5\u5b89\u88c5Package Control\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import urllib.request,os,hashlib; h = &#39;6f5dd3a8c9a0e2d7e8f8fd8d0e9ccf8e&#39; + &#39;7f95a7fc5e7f9f6f5f3a3b1d5e3d2f8d&#39;; pf = &#39;Package Control.sublime-package&#39;; ipp = sublime.installed_packages_path(); urllib.request.install_opener( urllib.request.build_opener( urllib.request.ProxyHandler()) ); by = urllib.request.urlopen( &#39;http:\/\/packagecontrol.io\/&#39; + pf.replace(&#39; &#39;, &#39;%20&#39;)).read(); dh = hashlib.sha256(by).hexdigest(); print(&#39;Error validating download (got %s instead of %s), please try manual install&#39; % (dh, h) if dh != h else open(os.path.join(ipp, pf), &#39;wb&#39; ).write(by))<\/p>\n<p><\/code><\/pre>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u91cd\u542fSublime Text<\/strong>\uff1a\u5b89\u88c5\u5b8c\u6210\u540e\uff0c\u91cd\u542fSublime Text\u4ee5\u542f\u7528Package Control\u3002<\/p>\n<\/p>\n<\/li>\n<\/ol>\n<p><p>\u4e09\u3001\u5b89\u88c5Python\u63d2\u4ef6<\/p>\n<\/p>\n<p><p>\u901a\u8fc7Package Control\u5b89\u88c5Python\u63d2\u4ef6\u4ee5\u589e\u5f3aSublime Text\u7684Python\u7f16\u7a0b\u4f53\u9a8c\u3002<\/p>\n<\/p>\n<ol>\n<li>\n<p><strong>\u6253\u5f00Package Control<\/strong>\uff1a\u6309\u4e0b\u5feb\u6377\u952e<code>Ctrl+Shift+P<\/code>\uff08Windows\/Linux\uff09\u6216<code>Cmd+Shift+P<\/code>\uff08Mac\uff09\u6253\u5f00\u547d\u4ee4\u9762\u677f\uff0c\u8f93\u5165\u201cInstall Package\u201d\u5e76\u9009\u62e9\u201cPackage Control: Install Package\u201d\u3002<\/p>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u641c\u7d22\u548c\u5b89\u88c5\u63d2\u4ef6<\/strong>\uff1a\u5728\u5f39\u51fa\u7684\u641c\u7d22\u6846\u4e2d\u8f93\u5165\u201cAnaconda\u201d\u6216\u201cSublimeREPL\u201d\u4ee5\u641c\u7d22\u8fd9\u4e9b\u63d2\u4ef6\uff0c\u7136\u540e\u9009\u62e9\u5e76\u5b89\u88c5\u5b83\u4eec\u3002Anaconda\u63d0\u4f9b\u667a\u80fd\u8865\u5168\u3001\u8bed\u6cd5\u68c0\u67e5\u7b49\u529f\u80fd\uff0c\u800cSublimeREPL\u5141\u8bb8\u5728Sublime\u4e2d\u8fd0\u884c\u4ea4\u4e92\u5f0fPython\u4f1a\u8bdd\u3002<\/p>\n<\/p>\n<\/li>\n<\/ol>\n<p><p>\u56db\u3001\u914d\u7f6e\u6784\u5efa\u7cfb\u7edf<\/p>\n<\/p>\n<p><p>\u914d\u7f6eSublime Text\u7684\u6784\u5efa\u7cfb\u7edf\u4ee5\u4fbf\u8fd0\u884cPython\u811a\u672c\u3002<\/p>\n<\/p>\n<ol>\n<li>\n<p><strong>\u521b\u5efa\u65b0\u7684\u6784\u5efa\u7cfb\u7edf<\/strong>\uff1a\u5728Sublime Text\u4e2d\uff0c\u70b9\u51fb\u201cTools\u201d&gt;\u201cBuild System\u201d&gt;\u201cNew Build System&#8230;\u201d\u4ee5\u521b\u5efa\u65b0\u7684\u6784\u5efa\u7cfb\u7edf\u3002<\/p>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u7f16\u8f91\u6784\u5efa\u7cfb\u7edf\u914d\u7f6e<\/strong>\uff1a\u5728\u65b0\u5efa\u7684\u6784\u5efa\u7cfb\u7edf\u6587\u4ef6\u4e2d\uff0c\u8f93\u5165\u4ee5\u4e0b\u5185\u5bb9\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-json\">{<\/p>\n<p>    &quot;cmd&quot;: [&quot;python3&quot;, &quot;-u&quot;, &quot;$file&quot;],<\/p>\n<p>    &quot;file_regex&quot;: &quot;^[ ]*File \\&quot;(...*?)\\&quot;, line ([0-9]*)&quot;,<\/p>\n<p>    &quot;selector&quot;: &quot;source.python&quot;<\/p>\n<p>}<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u6ce8\u610f\uff0c\u5982\u679c\u60a8\u4f7f\u7528\u7684\u662fWindows\uff0c\u8bf7\u5c06<code>&quot;python3&quot;<\/code>\u66ff\u6362\u4e3a<code>&quot;python&quot;<\/code>\u3002\u4fdd\u5b58\u6587\u4ef6\uff0c\u5e76\u547d\u540d\u4e3a\u201cPython.sublime-build\u201d\u3002<\/p>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u9009\u62e9Python\u6784\u5efa\u7cfb\u7edf<\/strong>\uff1a\u5728\u201cSublime Text\u201d\u4e2d\uff0c\u70b9\u51fb\u201cTools\u201d&gt;\u201cBuild System\u201d\uff0c\u9009\u62e9\u201cPython\u201d\u4ee5\u6fc0\u6d3b\u521a\u521a\u521b\u5efa\u7684\u6784\u5efa\u7cfb\u7edf\u3002<\/p>\n<\/p>\n<\/li>\n<\/ol>\n<p><p>\u4e94\u3001\u8bbe\u7f6e\u73af\u5883\u53d8\u91cf<\/p>\n<\/p>\n<p><p>\u786e\u4fddSublime Text\u80fd\u591f\u6b63\u786e\u8bc6\u522bPython\u89e3\u91ca\u5668\u7684\u4f4d\u7f6e\u3002<\/p>\n<\/p>\n<ol>\n<li>\n<p><strong>\u68c0\u67e5\u73af\u5883\u53d8\u91cf<\/strong>\uff1a\u5728\u547d\u4ee4\u63d0\u793a\u7b26\u6216\u7ec8\u7aef\u4e2d\u8f93\u5165<code>echo %PATH%<\/code>\uff08Windows\uff09\u6216<code>echo $PATH<\/code>\uff08Mac\/Linux\uff09\u67e5\u770b\u73af\u5883\u53d8\u91cf\u4e2d\u662f\u5426\u5305\u542bPython\u7684\u5b89\u88c5\u8def\u5f84\u3002<\/p>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u8bbe\u7f6e\u73af\u5883\u53d8\u91cf\uff08\u5982\u679c\u9700\u8981\uff09<\/strong>\uff1a\u5982\u679cPython\u7684\u8def\u5f84\u4e0d\u5728\u73af\u5883\u53d8\u91cf\u4e2d\uff0c\u8bf7\u6839\u636e\u60a8\u7684\u64cd\u4f5c\u7cfb\u7edf\u8bbe\u7f6e\u73af\u5883\u53d8\u91cf\u3002<\/p>\n<\/p>\n<ul>\n<li>\n<p><strong>Windows<\/strong>\uff1a\u53f3\u952e\u70b9\u51fb\u201c\u6b64\u7535\u8111\u201d&gt;\u201c\u5c5e\u6027\u201d&gt;\u201c\u9ad8\u7ea7\u7cfb\u7edf\u8bbe\u7f6e\u201d&gt;\u201c\u73af\u5883\u53d8\u91cf\u201d\uff0c\u5728\u201c\u7cfb\u7edf\u53d8\u91cf\u201d\u4e2d\u627e\u5230\u5e76\u7f16\u8f91\u201cPath\u201d\uff0c\u5c06Python\u7684\u5b89\u88c5\u8def\u5f84\u6dfb\u52a0\u8fdb\u53bb\u3002<\/p>\n<\/p>\n<\/li>\n<li>\n<p><strong>Mac\/Linux<\/strong>\uff1a\u7f16\u8f91<code>.bash_profile<\/code>\uff08Mac\uff09\u6216<code>.bashrc<\/code>\uff08Linux\uff09\uff0c\u6dfb\u52a0\u4ee5\u4e0b\u884c\u5e76\u4fdd\u5b58\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">export PATH=&quot;\/usr\/local\/bin\/python3:$PATH&quot;<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u7136\u540e\u6267\u884c<code>source ~\/.bash_profile<\/code>\uff08Mac\uff09\u6216<code>source ~\/.bashrc<\/code>\uff08Linux\uff09\u4ee5\u4f7f\u66f4\u6539\u751f\u6548\u3002<\/p>\n<\/p>\n<\/li>\n<\/ul>\n<\/li>\n<\/ol>\n<p><p>\u516d\u3001\u8fd0\u884cPython\u811a\u672c<\/p>\n<\/p>\n<p><p>\u5b8c\u6210\u4ee5\u4e0a\u914d\u7f6e\u540e\uff0c\u60a8\u53ef\u4ee5\u5728Sublime Text\u4e2d\u7f16\u5199\u548c\u8fd0\u884cPython\u811a\u672c\u3002<\/p>\n<\/p>\n<ol>\n<li>\n<p><strong>\u7f16\u5199Python\u811a\u672c<\/strong>\uff1a\u5728Sublime Text\u4e2d\u6253\u5f00\u4e00\u4e2a\u65b0\u7684\u6587\u4ef6\uff0c\u7f16\u5199\u60a8\u7684Python\u4ee3\u7801\uff0c\u5e76\u4fdd\u5b58\u6587\u4ef6\uff0c\u786e\u4fdd\u6587\u4ef6\u6269\u5c55\u540d\u4e3a<code>.py<\/code>\u3002<\/p>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u8fd0\u884cPython\u811a\u672c<\/strong>\uff1a\u6309\u4e0b\u5feb\u6377\u952e<code>Ctrl+B<\/code>\uff08Windows\/Linux\uff09\u6216<code>Cmd+B<\/code>\uff08Mac\uff09\u4ee5\u8fd0\u884cPython\u811a\u672c\u3002Sublime Text\u5c06\u4f7f\u7528\u60a8\u914d\u7f6e\u7684\u6784\u5efa\u7cfb\u7edf\u6765\u6267\u884c\u811a\u672c\uff0c\u5e76\u5728\u63a7\u5236\u53f0\u4e2d\u663e\u793a\u8f93\u51fa\u3002<\/p>\n<\/p>\n<\/li>\n<\/ol>\n<p><p>\u901a\u8fc7\u4ee5\u4e0a\u6b65\u9aa4\uff0c\u60a8\u53ef\u4ee5\u5728Sublime Text\u4e2d\u987a\u5229\u8f7d\u5165\u5e76\u8fd0\u884cPython\u7a0b\u5e8f\u3002\u826f\u597d\u7684\u5f00\u53d1\u73af\u5883\u914d\u7f6e\u5c06\u5927\u5927\u63d0\u9ad8\u60a8\u7684\u7f16\u7a0b\u6548\u7387\u548c\u4f53\u9a8c\u3002<\/p>\n<\/p>\n<h2><strong>\u76f8\u5173\u95ee\u7b54FAQs\uff1a<\/strong><\/h2>\n<p> <strong>\u5982\u4f55\u5728Sublime Text\u4e2d\u5b89\u88c5\u548c\u914d\u7f6ePython\u73af\u5883\uff1f<\/strong><br \/>\u8981\u5728Sublime Text\u4e2d\u4f7f\u7528Python\uff0c\u60a8\u9700\u8981\u786e\u4fdd\u5df2\u7ecf\u5b89\u88c5Python\u89e3\u91ca\u5668\u3002\u63a5\u7740\uff0c\u6253\u5f00Sublime Text\uff0c\u8fdb\u5165\u201cPreferences\u201d\u83dc\u5355\uff0c\u9009\u62e9\u201cPackage Control\u201d\uff0c\u7136\u540e\u641c\u7d22\u5e76\u5b89\u88c5\u201cAnaconda\u201d\u6216\u201cSublimeREPL\u201d\u7b49\u76f8\u5173\u63d2\u4ef6\u3002\u8fd9\u4e9b\u63d2\u4ef6\u5c06\u63d0\u4f9b\u8bed\u6cd5\u9ad8\u4eae\u3001\u4ee3\u7801\u81ea\u52a8\u8865\u5168\u548c\u8fd0\u884cPython\u4ee3\u7801\u7684\u529f\u80fd\u3002\u5b8c\u6210\u5b89\u88c5\u540e\uff0c\u60a8\u53ef\u4ee5\u5728\u65b0\u7684\u6587\u4ef6\u4e2d\u7f16\u5199Python\u4ee3\u7801\uff0c\u5e76\u901a\u8fc7\u5feb\u6377\u952e\u6216\u547d\u4ee4\u9762\u677f\u8fd0\u884c\u3002<\/p>\n<p><strong>\u5728Sublime Text\u4e2d\u5982\u4f55\u8fd0\u884cPython\u811a\u672c\uff1f<\/strong><br \/>\u8fd0\u884cPython\u811a\u672c\u975e\u5e38\u7b80\u5355\u3002\u5728Sublime Text\u4e2d\uff0c\u6253\u5f00\u60a8\u7684Python\u6587\u4ef6\uff0c\u6309\u4e0b\u201cCtrl + B\u201d\u6216\u201cCmd + B\u201d\uff08Mac\u7528\u6237\uff09\u5373\u53ef\u76f4\u63a5\u8fd0\u884c\u4ee3\u7801\u3002\u60a8\u4e5f\u53ef\u4ee5\u901a\u8fc7\u8bbe\u7f6e\u81ea\u5b9a\u4e49\u6784\u5efa\u7cfb\u7edf\u6765\u6307\u5b9aPython\u89e3\u91ca\u5668\u548c\u8fd0\u884c\u53c2\u6570\uff0c\u4ee5\u4fbf\u66f4\u597d\u5730\u9002\u5e94\u60a8\u7684\u5f00\u53d1\u9700\u6c42\u3002<\/p>\n<p><strong>Sublime Text\u652f\u6301\u54ea\u4e9bPython\u7248\u672c\uff1f<\/strong><br \/>Sublime Text\u652f\u6301\u591a\u79cdPython\u7248\u672c\uff0c\u901a\u5e38\u662fPython 2.x\u548cPython 3.x\u3002\u4f7f\u7528\u54ea\u4e2a\u7248\u672c\u53d6\u51b3\u4e8e\u60a8\u5728\u7cfb\u7edf\u4e2d\u5b89\u88c5\u7684Python\u89e3\u91ca\u5668\u3002\u786e\u4fdd\u5728Sublime Text\u7684\u6784\u5efa\u7cfb\u7edf\u4e2d\u914d\u7f6e\u4e86\u6b63\u786e\u7684Python\u8def\u5f84\uff0c\u4ee5\u4fbf\u8fd0\u884c\u5bf9\u5e94\u7248\u672c\u7684\u4ee3\u7801\u3002\u5982\u679c\u60a8\u5728\u4f7f\u7528\u7279\u5b9a\u7684\u5e93\u6216\u6846\u67b6\uff0c\u786e\u4fdd\u8fd9\u4e9b\u5e93\u4e0e\u60a8\u7684Python\u7248\u672c\u517c\u5bb9\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"\u8981\u5728Sublime Text\u4e2d\u8f7d\u5165Python\uff0c\u53ef\u4ee5\u901a\u8fc7\u5b89\u88c5\u63d2\u4ef6\u3001\u914d\u7f6e\u6784\u5efa\u7cfb\u7edf\u3001\u8bbe\u7f6e\u73af\u5883\u53d8\u91cf\u6765\u5b9e\u73b0\u3002\u9996\u5148\uff0c\u786e\u4fdd [&hellip;]","protected":false},"author":3,"featured_media":947077,"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\/947069"}],"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=947069"}],"version-history":[{"count":"1","href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/947069\/revisions"}],"predecessor-version":[{"id":947079,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/947069\/revisions\/947079"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media\/947077"}],"wp:attachment":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media?parent=947069"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/categories?post=947069"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/tags?post=947069"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}