{"id":953853,"date":"2024-12-27T01:48:43","date_gmt":"2024-12-26T17:48:43","guid":{"rendered":"https:\/\/docs.pingcode.com\/ask\/ask-ask\/953853.html"},"modified":"2024-12-27T01:48:45","modified_gmt":"2024-12-26T17:48:45","slug":"xshell%e5%a6%82%e4%bd%95%e8%bf%90%e8%a1%8cpython%e8%84%9a%e6%9c%ac","status":"publish","type":"post","link":"https:\/\/docs.pingcode.com\/ask\/953853.html","title":{"rendered":"xshell\u5982\u4f55\u8fd0\u884cpython\u811a\u672c"},"content":{"rendered":"<p style=\"text-align:center;\" ><img decoding=\"async\" src=\"https:\/\/cdn-kb.worktile.com\/kb\/wp-content\/uploads\/2024\/04\/25094239\/a50746de-0d43-4cbb-a111-cca37bfbedd2.webp\" alt=\"xshell\u5982\u4f55\u8fd0\u884cpython\u811a\u672c\" \/><\/p>\n<p><p> <strong>\u5728Xshell\u4e2d\u8fd0\u884cPython\u811a\u672c\uff0c\u53ef\u4ee5\u901a\u8fc7\u4ee5\u4e0b\u6b65\u9aa4\u5b9e\u73b0\uff1a\u8fde\u63a5\u5230\u670d\u52a1\u5668\u3001\u5bfc\u822a\u5230\u811a\u672c\u76ee\u5f55\u3001\u4f7f\u7528Python\u547d\u4ee4\u8fd0\u884c\u811a\u672c\u3002<\/strong>\u4e0b\u9762\u5c06\u8be6\u7ec6\u63cf\u8ff0\u5982\u4f55\u5728Xshell\u4e2d\u8fd0\u884cPython\u811a\u672c\u7684\u6bcf\u4e00\u6b65\u9aa4\u3002<\/p>\n<\/p>\n<p><p>\u4e00\u3001\u8fde\u63a5\u5230\u670d\u52a1\u5668<\/p>\n<\/p>\n<ol>\n<li>\n<p><strong>\u5b89\u88c5\u5e76\u6253\u5f00Xshell<\/strong><br \/>\u9996\u5148\uff0c\u786e\u4fdd\u4f60\u7684\u8ba1\u7b97\u673a\u4e0a\u5b89\u88c5\u4e86Xshell\u3002\u5982\u679c\u6ca1\u6709\uff0c\u53ef\u4ee5\u4ece\u5b98\u65b9\u6e20\u9053\u4e0b\u8f7d\u5e76\u5b89\u88c5\u3002\u542f\u52a8Xshell\u540e\uff0c\u4f60\u5c06\u770b\u5230\u4e00\u4e2a\u53ef\u4ee5\u7528\u4e8e\u7ba1\u7406\u591a\u4e2a\u4f1a\u8bdd\u7684\u754c\u9762\u3002<\/p>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u521b\u5efa\u65b0\u4f1a\u8bdd<\/strong><br \/>\u5728Xshell\u4e2d\uff0c\u70b9\u51fb\u201c\u65b0\u5efa\u201d\u6309\u94ae\uff0c\u521b\u5efa\u4e00\u4e2a\u65b0\u7684\u4f1a\u8bdd\u3002\u4f60\u9700\u8981\u8f93\u5165\u8fdc\u7a0b\u670d\u52a1\u5668\u7684IP\u5730\u5740\u6216\u4e3b\u673a\u540d\uff0c\u4ee5\u53ca\u767b\u5f55\u6240\u9700\u7684\u7528\u6237\u540d\u548c\u5bc6\u7801\u3002\u6ce8\u610f\uff0c\u8981\u786e\u4fdd\u8fdc\u7a0b\u670d\u52a1\u5668\u4e0a\u5df2\u7ecf\u5b89\u88c5\u4e86Python\u73af\u5883\u3002<\/p>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u8fde\u63a5\u5230\u670d\u52a1\u5668<\/strong><br \/>\u4fdd\u5b58\u4f1a\u8bdd\u540e\uff0c\u53cc\u51fb\u4f1a\u8bdd\u540d\u79f0\u6216\u70b9\u51fb\u201c\u8fde\u63a5\u201d\u6309\u94ae\uff0cXshell\u5c06\u5c1d\u8bd5\u8fde\u63a5\u5230\u6307\u5b9a\u7684\u670d\u52a1\u5668\u3002\u5728\u8fde\u63a5\u6210\u529f\u540e\uff0c\u4f60\u5c06\u770b\u5230\u670d\u52a1\u5668\u7684\u547d\u4ee4\u884c\u754c\u9762\u3002<\/p>\n<\/p>\n<\/li>\n<\/ol>\n<p><p>\u4e8c\u3001\u5bfc\u822a\u5230\u811a\u672c\u76ee\u5f55<\/p>\n<\/p>\n<ol>\n<li>\n<p><strong>\u67e5\u770b\u5f53\u524d\u76ee\u5f55<\/strong><br \/>\u767b\u5f55\u670d\u52a1\u5668\u540e\uff0c\u9996\u5148\u4f7f\u7528<code>pwd<\/code>\u547d\u4ee4\u67e5\u770b\u5f53\u524d\u6240\u5728\u76ee\u5f55\u8def\u5f84\u3002\u8fd9\u5c06\u5e2e\u52a9\u4f60\u786e\u8ba4\u4f60\u7684\u4f4d\u7f6e\uff0c\u4ee5\u4fbf\u66f4\u597d\u5730\u5bfc\u822a\u5230Python\u811a\u672c\u6240\u5728\u7684\u76ee\u5f55\u3002<\/p>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u4f7f\u7528cd\u547d\u4ee4\u5bfc\u822a\u76ee\u5f55<\/strong><br \/>\u5982\u679c\u4f60\u7684Python\u811a\u672c\u5b58\u653e\u5728\u5176\u4ed6\u76ee\u5f55\u4e2d\uff0c\u53ef\u4ee5\u4f7f\u7528<code>cd<\/code>\u547d\u4ee4\u5bfc\u822a\u5230\u8be5\u76ee\u5f55\u3002\u4f8b\u5982\uff0c\u5982\u679c\u4f60\u7684\u811a\u672c\u4f4d\u4e8e<code>\/home\/user\/scripts\/<\/code>\uff0c\u53ef\u4ee5\u8f93\u5165<code>cd \/home\/user\/scripts\/<\/code>\u6765\u5207\u6362\u5230\u8be5\u76ee\u5f55\u3002<\/p>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u5217\u51fa\u76ee\u5f55\u5185\u5bb9<\/strong><br \/>\u4e3a\u4e86\u786e\u8ba4\u811a\u672c\u6587\u4ef6\u662f\u5426\u5b58\u5728\u4e8e\u5f53\u524d\u76ee\u5f55\u4e2d\uff0c\u53ef\u4ee5\u4f7f\u7528<code>ls<\/code>\u547d\u4ee4\u5217\u51fa\u76ee\u5f55\u4e2d\u7684\u6240\u6709\u6587\u4ef6\u548c\u6587\u4ef6\u5939\u3002\u8fd9\u6709\u52a9\u4e8e\u786e\u4fdd\u4f60\u6ca1\u6709\u5728\u9519\u8bef\u7684\u76ee\u5f55\u4e2d\u8fd0\u884c\u811a\u672c\u3002<\/p>\n<\/p>\n<\/li>\n<\/ol>\n<p><p>\u4e09\u3001\u4f7f\u7528Python\u547d\u4ee4\u8fd0\u884c\u811a\u672c<\/p>\n<\/p>\n<ol>\n<li>\n<p><strong>\u68c0\u67e5Python\u7248\u672c<\/strong><br \/>\u5728\u8fd0\u884c\u811a\u672c\u4e4b\u524d\uff0c\u5efa\u8bae\u4f7f\u7528<code>python --version<\/code>\u6216<code>python3 --version<\/code>\u547d\u4ee4\u68c0\u67e5\u670d\u52a1\u5668\u4e0a\u5b89\u88c5\u7684Python\u7248\u672c\uff0c\u4ee5\u786e\u4fdd\u5176\u4e0e\u811a\u672c\u7684\u9700\u6c42\u517c\u5bb9\u3002<\/p>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u8fd0\u884cPython\u811a\u672c<\/strong><br \/>\u5728\u786e\u8ba4Python\u7248\u672c\u548c\u811a\u672c\u8def\u5f84\u540e\uff0c\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u8fd0\u884cPython\u811a\u672c\uff1a<\/p>\n<\/p>\n<ul>\n<li>\u5982\u679c\u4f7f\u7528Python 2\uff0c\u8f93\u5165\uff1a<code>python script_name.py<\/code><\/li>\n<li>\u5982\u679c\u4f7f\u7528Python 3\uff0c\u8f93\u5165\uff1a<code>python3 script_name.py<\/code><\/p>\n<p>\u5c06<code>script_name.py<\/code>\u66ff\u6362\u4e3a\u4f60\u7684Python\u811a\u672c\u7684\u5b9e\u9645\u540d\u79f0\u3002<\/li>\n<\/p>\n<\/ul>\n<\/li>\n<li>\n<p><strong>\u76d1\u63a7\u811a\u672c\u8f93\u51fa<\/strong><br \/>\u811a\u672c\u8fd0\u884c\u540e\uff0cXshell\u5c06\u663e\u793a\u811a\u672c\u7684\u8f93\u51fa\u7ed3\u679c\u3002\u4f60\u53ef\u4ee5\u5728\u6b64\u67e5\u770b\u4efb\u4f55\u6253\u5370\u4fe1\u606f\u6216\u9519\u8bef\u65e5\u5fd7\uff0c\u4ee5\u786e\u8ba4\u811a\u672c\u662f\u5426\u6b63\u786e\u6267\u884c\u3002\u5982\u679c\u6709\u9519\u8bef\u4fe1\u606f\uff0c\u53ef\u80fd\u9700\u8981\u6839\u636e\u9519\u8bef\u65e5\u5fd7\u8c03\u6574\u811a\u672c\u4ee3\u7801\u3002<\/p>\n<\/p>\n<\/li>\n<\/ol>\n<p><p>\u56db\u3001\u5904\u7406\u5e38\u89c1\u95ee\u9898<\/p>\n<\/p>\n<ol>\n<li>\n<p><strong>Python\u672a\u5b89\u88c5\u6216\u8def\u5f84\u95ee\u9898<\/strong><br \/>\u5982\u679c\u8fd0\u884c\u811a\u672c\u65f6\u51fa\u73b0\u201ccommand not found\u201d\u9519\u8bef\uff0c\u53ef\u80fd\u662f\u56e0\u4e3aPython\u672a\u5b89\u88c5\u6216\u73af\u5883\u53d8\u91cf\u672a\u6b63\u786e\u914d\u7f6e\u3002\u53ef\u4ee5\u901a\u8fc7<code>sudo apt-get install python<\/code>\u6216<code>sudo apt-get install python3<\/code>\u547d\u4ee4\u6765\u5b89\u88c5Python\u3002<\/p>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u811a\u672c\u6743\u9650\u95ee\u9898<\/strong><br \/>\u5982\u679c\u9047\u5230\u201cPermission denied\u201d\u9519\u8bef\uff0c\u53ef\u80fd\u662f\u56e0\u4e3a\u811a\u672c\u6ca1\u6709\u6267\u884c\u6743\u9650\u3002\u53ef\u4ee5\u4f7f\u7528<code>chmod +x script_name.py<\/code>\u547d\u4ee4\u4e3a\u811a\u672c\u6dfb\u52a0\u6267\u884c\u6743\u9650\u3002<\/p>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u4f9d\u8d56\u5e93\u672a\u5b89\u88c5<\/strong><br \/>\u811a\u672c\u8fd0\u884c\u65f6\u53ef\u80fd\u4f1a\u4f9d\u8d56\u67d0\u4e9bPython\u5e93\u3002\u5982\u679c\u8fd9\u4e9b\u5e93\u672a\u5b89\u88c5\uff0c\u4f1a\u5bfc\u81f4\u9519\u8bef\u3002\u53ef\u4ee5\u4f7f\u7528<code>pip install package_name<\/code>\u6216<code>pip3 install package_name<\/code>\u547d\u4ee4\u5b89\u88c5\u6240\u9700\u7684\u5e93\u3002<\/p>\n<\/p>\n<\/li>\n<\/ol>\n<p><p>\u4e94\u3001\u4f18\u5316\u4e0e\u81ea\u52a8\u5316<\/p>\n<\/p>\n<ol>\n<li>\n<p><strong>\u4f7f\u7528\u865a\u62df\u73af\u5883<\/strong><br \/>\u4e3a\u4e86\u907f\u514d\u4f9d\u8d56\u51b2\u7a81\uff0c\u5efa\u8bae\u5728\u8fd0\u884cPython\u811a\u672c\u524d\u521b\u5efa\u4e00\u4e2a\u865a\u62df\u73af\u5883\u3002\u53ef\u4ee5\u4f7f\u7528<code>python3 -m venv myenv<\/code>\u547d\u4ee4\u521b\u5efa\u865a\u62df\u73af\u5883\uff0c\u7136\u540e\u901a\u8fc7<code>source myenv\/bin\/activate<\/code>\u6fc0\u6d3b\u5b83\u3002<\/p>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u81ea\u52a8\u5316\u811a\u672c\u8fd0\u884c<\/strong><br \/>\u5982\u679c\u9700\u8981\u5b9a\u671f\u8fd0\u884cPython\u811a\u672c\uff0c\u53ef\u4ee5\u5c06\u5176\u6dfb\u52a0\u5230Linux\u7684crontab\u4e2d\uff0c\u8bbe\u7f6e\u81ea\u52a8\u6267\u884c\u65f6\u95f4\u3002\u8fd9\u53ef\u4ee5\u901a\u8fc7\u8f93\u5165<code>crontab -e<\/code>\u7f16\u8f91\u8ba1\u5212\u4efb\u52a1\u6765\u5b9e\u73b0\u3002<\/p>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u4f7f\u7528\u811a\u672c\u53c2\u6570<\/strong><br \/>\u4e3a\u4e86\u63d0\u9ad8\u811a\u672c\u7684\u7075\u6d3b\u6027\uff0c\u53ef\u4ee5\u8bbe\u8ba1\u811a\u672c\u63a5\u53d7\u547d\u4ee4\u884c\u53c2\u6570\u3002\u8fd9\u6837\u53ef\u4ee5\u5728\u8fd0\u884c\u65f6\u6839\u636e\u9700\u8981\u4f20\u9012\u4e0d\u540c\u7684\u53c2\u6570\uff0c\u63a7\u5236\u811a\u672c\u7684\u884c\u4e3a\u3002<\/p>\n<\/p>\n<\/li>\n<\/ol>\n<p><p>\u901a\u8fc7\u4ee5\u4e0a\u6b65\u9aa4\uff0c\u4f60\u53ef\u4ee5\u5728Xshell\u4e2d\u987a\u5229\u8fd0\u884cPython\u811a\u672c\uff0c\u5e76\u5904\u7406\u53ef\u80fd\u9047\u5230\u7684\u5404\u79cd\u95ee\u9898\u3002\u6b64\u5916\uff0c\u7ed3\u5408\u4f7f\u7528\u865a\u62df\u73af\u5883\u548c\u81ea\u52a8\u5316\u5de5\u5177\uff0c\u53ef\u4ee5\u663e\u8457\u63d0\u5347\u811a\u672c\u6267\u884c\u7684\u6548\u7387\u548c\u53ef\u7ef4\u62a4\u6027\u3002<\/p>\n<\/p>\n<h2><strong>\u76f8\u5173\u95ee\u7b54FAQs\uff1a<\/strong><\/h2>\n<p> <strong>Xshell\u652f\u6301\u54ea\u4e9bPython\u7248\u672c\uff1f<\/strong><br \/>Xshell\u672c\u8eab\u5e76\u4e0d\u9650\u5236Python\u7248\u672c\u7684\u4f7f\u7528\uff0c\u60a8\u53ef\u4ee5\u5728Xshell\u4e2d\u8fd0\u884c\u4efb\u4f55\u5df2\u5b89\u88c5\u5728\u8fdc\u7a0b\u670d\u52a1\u5668\u4e0a\u7684Python\u7248\u672c\u3002\u786e\u4fdd\u670d\u52a1\u5668\u4e0a\u5df2\u5b89\u88c5\u6240\u9700\u7684Python\u7248\u672c\uff0c\u5e76\u5728Xshell\u4e2d\u4f7f\u7528\u76f8\u5e94\u7684\u547d\u4ee4\u8c03\u7528\u3002<\/p>\n<p><strong>\u5982\u4f55\u5728Xshell\u4e2d\u4e0a\u4f20Python\u811a\u672c\u5230\u670d\u52a1\u5668\uff1f<\/strong><br \/>\u5728Xshell\u4e2d\uff0c\u60a8\u53ef\u4ee5\u4f7f\u7528\u5185\u7f6e\u7684SFTP\u529f\u80fd\u5c06\u672c\u5730\u7684Python\u811a\u672c\u4e0a\u4f20\u5230\u8fdc\u7a0b\u670d\u52a1\u5668\u3002\u8fde\u63a5\u5230\u670d\u52a1\u5668\u540e\uff0c\u70b9\u51fb\u5de5\u5177\u680f\u4e0a\u7684\u201c\u6587\u4ef6\u4f20\u8f93\u201d\u56fe\u6807\uff0c\u9009\u62e9\u60a8\u8981\u4e0a\u4f20\u7684\u6587\u4ef6\uff0c\u62d6\u653e\u5230\u76ee\u6807\u76ee\u5f55\u4e2d\u5373\u53ef\u5b8c\u6210\u4e0a\u4f20\u3002<\/p>\n<p><strong>\u5728Xshell\u4e2d\u8fd0\u884cPython\u811a\u672c\u65f6\uff0c\u5982\u4f55\u5904\u7406\u6743\u9650\u95ee\u9898\uff1f<\/strong><br \/>\u5982\u679c\u5728Xshell\u4e2d\u8fd0\u884cPython\u811a\u672c\u65f6\u9047\u5230\u6743\u9650\u95ee\u9898\uff0c\u53ef\u4ee5\u4f7f\u7528<code>chmod<\/code>\u547d\u4ee4\u4fee\u6539\u6587\u4ef6\u6743\u9650\u3002\u4f8b\u5982\uff0c\u4f7f\u7528<code>chmod +x your_script.py<\/code>\u547d\u4ee4\u4e3a\u811a\u672c\u6dfb\u52a0\u6267\u884c\u6743\u9650\u3002\u786e\u4fdd\u60a8\u5728\u8fd0\u884c\u811a\u672c\u65f6\u62e5\u6709\u8db3\u591f\u7684\u6743\u9650\uff0c\u6216\u8005\u4f7f\u7528<code>sudo<\/code>\u547d\u4ee4\u4ee5\u7ba1\u7406\u5458\u8eab\u4efd\u6267\u884c\u811a\u672c\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"\u5728Xshell\u4e2d\u8fd0\u884cPython\u811a\u672c\uff0c\u53ef\u4ee5\u901a\u8fc7\u4ee5\u4e0b\u6b65\u9aa4\u5b9e\u73b0\uff1a\u8fde\u63a5\u5230\u670d\u52a1\u5668\u3001\u5bfc\u822a\u5230\u811a\u672c\u76ee\u5f55\u3001\u4f7f\u7528Python\u547d\u4ee4 [&hellip;]","protected":false},"author":3,"featured_media":953863,"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\/953853"}],"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=953853"}],"version-history":[{"count":"1","href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/953853\/revisions"}],"predecessor-version":[{"id":953865,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/953853\/revisions\/953865"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media\/953863"}],"wp:attachment":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media?parent=953853"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/categories?post=953853"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/tags?post=953853"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}