{"id":954766,"date":"2024-12-27T02:03:18","date_gmt":"2024-12-26T18:03:18","guid":{"rendered":"https:\/\/docs.pingcode.com\/ask\/ask-ask\/954766.html"},"modified":"2024-12-27T02:03:19","modified_gmt":"2024-12-26T18:03:19","slug":"%e5%a6%82%e4%bd%95%e6%9b%b4%e6%94%b9python%e9%bb%98%e8%ae%a4%e7%bc%96%e7%a0%81","status":"publish","type":"post","link":"https:\/\/docs.pingcode.com\/ask\/954766.html","title":{"rendered":"\u5982\u4f55\u66f4\u6539python\u9ed8\u8ba4\u7f16\u7801"},"content":{"rendered":"<p style=\"text-align:center;\" ><img decoding=\"async\" src=\"https:\/\/cdn-kb.worktile.com\/kb\/wp-content\/uploads\/2024\/04\/25094912\/5f179209-3d12-473c-935a-c64885ab9903.webp\" alt=\"\u5982\u4f55\u66f4\u6539python\u9ed8\u8ba4\u7f16\u7801\" \/><\/p>\n<p><p> <strong>\u66f4\u6539Python\u9ed8\u8ba4\u7f16\u7801\u7684\u65b9\u6cd5\u5305\u62ec\uff1a\u4fee\u6539\u73af\u5883\u53d8\u91cf\u3001\u4f7f\u7528sys\u6a21\u5757\u3001\u8c03\u6574IDE\u8bbe\u7f6e\u3002\u5728\u8fd9\u4e9b\u65b9\u6cd5\u4e2d\uff0c\u4f7f\u7528sys\u6a21\u5757\u662f\u4e34\u65f6\u4e14\u6700\u4e3a\u5e38\u7528\u7684\u65b9\u5f0f\u3002<\/strong><\/p>\n<\/p>\n<p><p>\u5728Python\u4e2d\uff0c\u9ed8\u8ba4\u7684\u5b57\u7b26\u7f16\u7801\u901a\u5e38\u662fUTF-8\uff0c\u4f46\u5728\u67d0\u4e9b\u60c5\u51b5\u4e0b\uff0c\u5c24\u5176\u662f\u5728\u5904\u7406\u975eUTF-8\u7f16\u7801\u7684\u6587\u4ef6\u6216\u6570\u636e\u65f6\uff0c\u53ef\u80fd\u9700\u8981\u66f4\u6539\u9ed8\u8ba4\u7f16\u7801\u3002\u4e0b\u9762\u5c06\u8be6\u7ec6\u4ecb\u7ecd\u5982\u4f55\u4f7f\u7528sys\u6a21\u5757\u6765\u4e34\u65f6\u66f4\u6539\u9ed8\u8ba4\u7f16\u7801\u3002<\/p>\n<\/p>\n<p><p>\u4f7f\u7528sys\u6a21\u5757\u7684setdefaultencoding\u51fd\u6570\u53ef\u4ee5\u8c03\u6574Python\u7684\u9ed8\u8ba4\u7f16\u7801\u3002\u9996\u5148\u9700\u8981\u5bfc\u5165sys\u6a21\u5757\uff0c\u7136\u540e\u901a\u8fc7sys.getdefaultencoding()\u68c0\u67e5\u5f53\u524d\u9ed8\u8ba4\u7f16\u7801\u3002\u7531\u4e8e\u5728Python 3\u4e2dsetdefaultencoding\u51fd\u6570\u5e76\u672a\u76f4\u63a5\u66b4\u9732\uff0c\u53ef\u4ee5\u901a\u8fc7\u91cd\u65b0\u52a0\u8f7dsys\u6a21\u5757\u6765\u5b9e\u73b0\u3002\u4ee5\u4e0b\u662f\u5177\u4f53\u6b65\u9aa4\uff1a<\/p>\n<\/p>\n<ol>\n<li>\n<p><strong>\u5bfc\u5165sys\u6a21\u5757\uff1a<\/strong><\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import sys<\/p>\n<p><\/code><\/pre>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u68c0\u67e5\u5f53\u524d\u9ed8\u8ba4\u7f16\u7801\uff1a<\/strong><\/p>\n<\/p>\n<p><pre><code class=\"language-python\">print(sys.getdefaultencoding())<\/p>\n<p><\/code><\/pre>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u66f4\u6539\u9ed8\u8ba4\u7f16\u7801\uff1a<\/strong><\/p>\n<p>\u9700\u8981\u6ce8\u610f\u7684\u662f\uff0c\u76f4\u63a5\u8c03\u7528setdefaultencoding\u662f\u4e0d\u53ef\u80fd\u7684\uff0c\u56e0\u4e3a\u5b83\u5728Python 3\u4e2d\u5df2\u88ab\u5c01\u88c5\u3002\u6211\u4eec\u53ef\u4ee5\u901a\u8fc7\u4ee5\u4e0b\u65b9\u5f0f\u5b9e\u73b0\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import sys<\/p>\n<p>import importlib<\/p>\n<h2><strong>\u91cd\u65b0\u52a0\u8f7dsys\u6a21\u5757<\/strong><\/h2>\n<p>importlib.reload(sys)<\/p>\n<h2><strong>\u66f4\u6539\u9ed8\u8ba4\u7f16\u7801<\/strong><\/h2>\n<p>sys.setdefaultencoding(&#39;utf-8&#39;)  # \u6216\u8005\u5176\u4ed6\u7f16\u7801\uff0c\u5982&#39;latin-1&#39;<\/p>\n<p><\/code><\/pre>\n<\/p>\n<\/li>\n<\/ol>\n<p><p>\u7136\u800c\uff0c\u9700\u8c28\u614e\u4f7f\u7528\u8fd9\u79cd\u65b9\u6cd5\uff0c\u56e0\u4e3a\u5b83\u53ef\u80fd\u5bfc\u81f4\u7a0b\u5e8f\u7684\u5176\u4ed6\u90e8\u5206\u65e0\u6cd5\u6b63\u5e38\u5904\u7406\u6570\u636e\uff0c\u5c24\u5176\u662f\u5728\u5927\u578b\u9879\u76ee\u4e2d\u3002\u56e0\u6b64\uff0c\u901a\u5e38\u63a8\u8350\u5728\u9700\u8981\u7684\u5730\u65b9\u663e\u5f0f\u5730\u6307\u5b9a\u7f16\u7801\uff0c\u800c\u4e0d\u662f\u5168\u5c40\u66f4\u6539\u9ed8\u8ba4\u7f16\u7801\u3002<\/p>\n<\/p>\n<hr>\n<p><h3>\u4e00\u3001\u4fee\u6539\u73af\u5883\u53d8\u91cf<\/h3>\n<\/p>\n<p><p>\u4fee\u6539\u73af\u5883\u53d8\u91cf\u662f\u66f4\u6539Python\u9ed8\u8ba4\u7f16\u7801\u7684\u53e6\u4e00\u79cd\u65b9\u5f0f\u3002\u53ef\u4ee5\u5728\u64cd\u4f5c\u7cfb\u7edf\u7684\u73af\u5883\u53d8\u91cf\u4e2d\u8bbe\u5b9aPYTHONIOENCODING\u53d8\u91cf\uff0c\u4ee5\u63a7\u5236\u8f93\u5165\u8f93\u51fa\u7684\u9ed8\u8ba4\u7f16\u7801\u3002\u8fd9\u901a\u5e38\u5728\u8de8\u5e73\u53f0\u5f00\u53d1\u4e2d\u6bd4\u8f83\u6709\u7528\u3002<\/p>\n<\/p>\n<p><h4>1. \u5728Windows\u4e2d<\/h4>\n<\/p>\n<p><p>\u5728Windows\u7cfb\u7edf\u4e2d\uff0c\u53ef\u4ee5\u901a\u8fc7\u4ee5\u4e0b\u6b65\u9aa4\u4fee\u6539\u73af\u5883\u53d8\u91cf\uff1a<\/p>\n<\/p>\n<ul>\n<li>\u53f3\u952e\u70b9\u51fb\u201c\u6b64\u7535\u8111\u201d\u6216\u201c\u6211\u7684\u7535\u8111\u201d\uff0c\u9009\u62e9\u201c\u5c5e\u6027\u201d\u3002<\/li>\n<li>\u9009\u62e9\u201c\u9ad8\u7ea7\u7cfb\u7edf\u8bbe\u7f6e\u201d\u3002<\/li>\n<li>\u70b9\u51fb\u201c\u73af\u5883\u53d8\u91cf\u201d\u6309\u94ae\u3002<\/li>\n<li>\u5728\u201c\u7cfb\u7edf\u53d8\u91cf\u201d\u6216\u201c\u7528\u6237\u53d8\u91cf\u201d\u4e2d\u70b9\u51fb\u201c\u65b0\u5efa\u201d\uff0c\u7136\u540e\u8f93\u5165\u53d8\u91cf\u540d\u4e3a<code>PYTHONIOENCODING<\/code>\uff0c\u53d8\u91cf\u503c\u4e3a\u6240\u9700\u7684\u7f16\u7801\uff0c\u5982<code>utf-8<\/code>\u3002<\/li>\n<li>\u786e\u8ba4\u5e76\u4fdd\u5b58\u66f4\u6539\u3002<\/li>\n<\/ul>\n<p><h4>2. \u5728Linux\u6216MacOS\u4e2d<\/h4>\n<\/p>\n<p><p>\u5728Linux\u6216MacOS\u4e2d\uff0c\u53ef\u4ee5\u901a\u8fc7\u4fee\u6539<code>.bashrc<\/code>\u6216<code>.bash_profile<\/code>\u6587\u4ef6\u6765\u8bbe\u5b9a\u73af\u5883\u53d8\u91cf\uff1a<\/p>\n<\/p>\n<ul>\n<li>\n<p>\u6253\u5f00\u7ec8\u7aef\u5e76\u4f7f\u7528\u6587\u672c\u7f16\u8f91\u5668\u6253\u5f00<code>.bashrc<\/code>\u6216<code>.bash_profile<\/code>\u6587\u4ef6\uff0c\u4f8b\u5982\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">nano ~\/.bashrc<\/p>\n<p><\/code><\/pre>\n<\/p>\n<\/li>\n<li>\n<p>\u6dfb\u52a0\u4ee5\u4e0b\u884c\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">export PYTHONIOENCODING=utf-8<\/p>\n<p><\/code><\/pre>\n<\/p>\n<\/li>\n<li>\n<p>\u4fdd\u5b58\u66f4\u6539\u5e76\u6267\u884c\u4ee5\u4e0b\u547d\u4ee4\u4ee5\u4f7f\u66f4\u6539\u751f\u6548\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">source ~\/.bashrc<\/p>\n<p><\/code><\/pre>\n<\/p>\n<\/li>\n<\/ul>\n<p><h3>\u4e8c\u3001\u8c03\u6574IDE\u8bbe\u7f6e<\/h3>\n<\/p>\n<p><p>\u8bb8\u591a\u96c6\u6210\u5f00\u53d1\u73af\u5883\uff08IDE\uff09\u5141\u8bb8\u7528\u6237\u8bbe\u7f6ePython\u9ed8\u8ba4\u7f16\u7801\u3002\u4ee5\u4e0b\u662f\u4e00\u4e9b\u5e38\u89c1IDE\u7684\u8bbe\u7f6e\u65b9\u6cd5\uff1a<\/p>\n<\/p>\n<p><h4>1. PyCharm<\/h4>\n<\/p>\n<p><p>\u5728PyCharm\u4e2d\uff0c\u66f4\u6539\u9ed8\u8ba4\u7f16\u7801\u7684\u65b9\u6cd5\u5982\u4e0b\uff1a<\/p>\n<\/p>\n<ul>\n<li>\u6253\u5f00PyCharm\u5e76\u8fdb\u5165\u201cFile\u201d\u83dc\u5355\uff0c\u9009\u62e9\u201cSettings\u201d\u3002<\/li>\n<li>\u5728\u8bbe\u7f6e\u7a97\u53e3\u4e2d\uff0c\u5bfc\u822a\u5230\u201cEditor\u201d -&gt; \u201cFile Encodings\u201d\u3002<\/li>\n<li>\u5728\u201cGlobal Encoding\u201d\u548c\u201cProject Encoding\u201d\u4e2d\u9009\u62e9\u6240\u9700\u7684\u7f16\u7801\uff0c\u4f8b\u5982<code>UTF-8<\/code>\u3002<\/li>\n<li>\u786e\u8ba4\u5e76\u4fdd\u5b58\u8bbe\u7f6e\u3002<\/li>\n<\/ul>\n<p><h4>2. Visual Studio Code<\/h4>\n<\/p>\n<p><p>\u5728Visual Studio Code\u4e2d\uff0c\u53ef\u4ee5\u901a\u8fc7\u4ee5\u4e0b\u6b65\u9aa4\u66f4\u6539\u9ed8\u8ba4\u7f16\u7801\uff1a<\/p>\n<\/p>\n<ul>\n<li>\u6253\u5f00VS Code\u5e76\u70b9\u51fb\u5de6\u4e0b\u89d2\u7684\u9f7f\u8f6e\u56fe\u6807\uff0c\u9009\u62e9\u201cSettings\u201d\u3002<\/li>\n<li>\u5728\u641c\u7d22\u680f\u4e2d\u8f93\u5165\u201cencoding\u201d\u3002<\/li>\n<li>\u627e\u5230\u201cFiles: Encoding\u201d\u9009\u9879\u5e76\u9009\u62e9\u6240\u9700\u7684\u7f16\u7801\u3002<\/li>\n<li>\u4fdd\u5b58\u8bbe\u7f6e\u3002<\/li>\n<\/ul>\n<p><h4>3. Eclipse<\/h4>\n<\/p>\n<p><p>\u5728Eclipse\u4e2d\uff0c\u66f4\u6539\u9ed8\u8ba4\u7f16\u7801\u7684\u65b9\u6cd5\u5982\u4e0b\uff1a<\/p>\n<\/p>\n<ul>\n<li>\u6253\u5f00Eclipse\u5e76\u8fdb\u5165\u201cWindow\u201d\u83dc\u5355\uff0c\u9009\u62e9\u201cPreferences\u201d\u3002<\/li>\n<li>\u5bfc\u822a\u5230\u201cGeneral\u201d -&gt; \u201cWorkspace\u201d\u3002<\/li>\n<li>\u5728\u201cText file encoding\u201d\u4e2d\u9009\u62e9\u6240\u9700\u7684\u7f16\u7801\u3002<\/li>\n<li>\u786e\u8ba4\u5e76\u4fdd\u5b58\u8bbe\u7f6e\u3002<\/li>\n<\/ul>\n<p><h3>\u4e09\u3001\u4f7f\u7528\u7f16\u7801\u53c2\u6570<\/h3>\n<\/p>\n<p><p>\u5728\u5904\u7406\u6587\u4ef6\u8bfb\u5199\u64cd\u4f5c\u65f6\uff0c\u53ef\u4ee5\u901a\u8fc7\u663e\u5f0f\u6307\u5b9a\u7f16\u7801\u6765\u907f\u514d\u4f9d\u8d56Python\u7684\u9ed8\u8ba4\u7f16\u7801\u3002\u8fd9\u79cd\u65b9\u6cd5\u662f\u6700\u4e3a\u63a8\u8350\u7684\uff0c\u56e0\u4e3a\u5b83\u80fd\u786e\u4fdd\u4ee3\u7801\u7684\u53ef\u79fb\u690d\u6027\u548c\u7a33\u5b9a\u6027\u3002<\/p>\n<\/p>\n<p><h4>1. \u6253\u5f00\u6587\u4ef6\u65f6\u6307\u5b9a\u7f16\u7801<\/h4>\n<\/p>\n<p><p>\u5728Python\u4e2d\uff0c\u4f7f\u7528<code>open()<\/code>\u51fd\u6570\u6253\u5f00\u6587\u4ef6\u65f6\uff0c\u53ef\u4ee5\u901a\u8fc7<code>encoding<\/code>\u53c2\u6570\u6307\u5b9a\u6587\u4ef6\u7684\u7f16\u7801\u3002\u4f8b\u5982\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">with open(&#39;example.txt&#39;, &#39;r&#39;, encoding=&#39;utf-8&#39;) as file:<\/p>\n<p>    content = file.read()<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u901a\u8fc7\u8fd9\u79cd\u65b9\u5f0f\uff0c\u5373\u4f7fPython\u7684\u9ed8\u8ba4\u7f16\u7801\u4e0d\u662fUTF-8\uff0c\u7a0b\u5e8f\u4e5f\u80fd\u6b63\u786e\u8bfb\u53d6\u6587\u4ef6\u5185\u5bb9\u3002<\/p>\n<\/p>\n<p><h4>2. \u4f7f\u7528\u7f16\u7801\u53c2\u6570\u8fdb\u884c\u5b57\u7b26\u4e32\u64cd\u4f5c<\/h4>\n<\/p>\n<p><p>\u5728\u8fdb\u884c\u5b57\u7b26\u4e32\u64cd\u4f5c\u65f6\uff0c\u4e5f\u53ef\u4ee5\u663e\u5f0f\u6307\u5b9a\u7f16\u7801\u3002\u4f8b\u5982\uff0c\u5728\u5c06\u5b57\u7b26\u4e32\u8f6c\u6362\u4e3a\u5b57\u8282\u65f6\uff0c\u53ef\u4ee5\u6307\u5b9a\u7f16\u7801\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">text = &quot;\u4f60\u597d\uff0c\u4e16\u754c&quot;<\/p>\n<p>byte_data = text.encode(&#39;utf-8&#39;)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u540c\u6837\uff0c\u5728\u4ece\u5b57\u8282\u8f6c\u6362\u4e3a\u5b57\u7b26\u4e32\u65f6\uff0c\u53ef\u4ee5\u6307\u5b9a\u7f16\u7801\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">decoded_text = byte_data.decode(&#39;utf-8&#39;)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>\u56db\u3001\u6ce8\u610f\u4e8b\u9879\u548c\u6700\u4f73\u5b9e\u8df5<\/h3>\n<\/p>\n<p><p>\u5728\u66f4\u6539\u6216\u6307\u5b9aPython\u9ed8\u8ba4\u7f16\u7801\u65f6\uff0c\u9700\u8981\u6ce8\u610f\u4ee5\u4e0b\u51e0\u70b9\uff1a<\/p>\n<\/p>\n<p><h4>1. \u786e\u4fdd\u517c\u5bb9\u6027<\/h4>\n<\/p>\n<p><p>\u65e0\u8bba\u662f\u4fee\u6539\u73af\u5883\u53d8\u91cf\u3001\u8c03\u6574IDE\u8bbe\u7f6e\uff0c\u8fd8\u662f\u663e\u5f0f\u6307\u5b9a\u7f16\u7801\uff0c\u90fd\u5e94\u786e\u4fdd\u6240\u7528\u7f16\u7801\u4e0e\u9879\u76ee\u4e2d\u7684\u6570\u636e\u683c\u5f0f\u76f8\u517c\u5bb9\u3002\u5c24\u5176\u662f\u5728\u5904\u7406\u56fd\u9645\u5316\u9879\u76ee\u65f6\uff0cUTF-8\u901a\u5e38\u662f\u6700\u4f73\u9009\u62e9\u3002<\/p>\n<\/p>\n<p><h4>2. \u907f\u514d\u5168\u5c40\u66f4\u6539\u9ed8\u8ba4\u7f16\u7801<\/h4>\n<\/p>\n<p><p>\u5c3d\u7ba1\u901a\u8fc7sys\u6a21\u5757\u53ef\u4ee5\u66f4\u6539Python\u7684\u5168\u5c40\u9ed8\u8ba4\u7f16\u7801\uff0c\u4f46\u8fd9\u79cd\u505a\u6cd5\u53ef\u80fd\u5bfc\u81f4\u7a0b\u5e8f\u4e2d\u5176\u4ed6\u90e8\u5206\u51fa\u73b0\u95ee\u9898\u3002\u56e0\u6b64\uff0c\u901a\u5e38\u5e94\u5728\u9700\u8981\u7684\u5730\u65b9\u663e\u5f0f\u6307\u5b9a\u7f16\u7801\uff0c\u800c\u975e\u4f9d\u8d56\u5168\u5c40\u8bbe\u7f6e\u3002<\/p>\n<\/p>\n<p><h4>3. \u5b9a\u671f\u6d4b\u8bd5<\/h4>\n<\/p>\n<p><p>\u5728\u5f00\u53d1\u8fc7\u7a0b\u4e2d\uff0c\u5c24\u5176\u662f\u5728\u4fee\u6539\u7f16\u7801\u8bbe\u7f6e\u540e\uff0c\u5e94\u8fdb\u884c\u5168\u9762\u6d4b\u8bd5\uff0c\u4ee5\u786e\u4fdd\u7a0b\u5e8f\u5728\u4e0d\u540c\u73af\u5883\u4e0b\u7684\u7a33\u5b9a\u6027\u548c\u4e00\u81f4\u6027\u3002\u5c24\u5176\u662f\u6d89\u53ca\u6587\u4ef6\u8bfb\u5199\u3001\u7f51\u7edc\u4f20\u8f93\u3001\u6570\u636e\u5e93\u64cd\u4f5c\u65f6\uff0c\u66f4\u9700\u4ed4\u7ec6\u68c0\u67e5\u3002<\/p>\n<\/p>\n<p><h4>4. \u6587\u6863\u5316\u7f16\u7801\u9009\u62e9<\/h4>\n<\/p>\n<p><p>\u5728\u9879\u76ee\u6587\u6863\u4e2d\uff0c\u5e94\u660e\u786e\u8bf4\u660e\u7f16\u7801\u9009\u62e9\u53ca\u5176\u539f\u56e0\uff0c\u5c24\u5176\u662f\u5728\u591a\u56e2\u961f\u534f\u4f5c\u6216\u8de8\u56fd\u9879\u76ee\u4e2d\uff0c\u4ee5\u907f\u514d\u56e0\u7f16\u7801\u4e0d\u4e00\u81f4\u5bfc\u81f4\u7684\u95ee\u9898\u3002<\/p>\n<\/p>\n<p><p>\u901a\u8fc7\u4ee5\u4e0a\u65b9\u6cd5\u548c\u6ce8\u610f\u4e8b\u9879\uff0c\u5f00\u53d1\u8005\u53ef\u4ee5\u66f4\u6709\u6548\u5730\u7ba1\u7406Python\u9879\u76ee\u4e2d\u7684\u5b57\u7b26\u7f16\u7801\u95ee\u9898\uff0c\u63d0\u9ad8\u4ee3\u7801\u7684\u7a33\u5b9a\u6027\u548c\u53ef\u79fb\u690d\u6027\u3002<\/p>\n<\/p>\n<h2><strong>\u76f8\u5173\u95ee\u7b54FAQs\uff1a<\/strong><\/h2>\n<p> <strong>\u5982\u4f55\u67e5\u770b\u5f53\u524dPython\u7684\u9ed8\u8ba4\u7f16\u7801\u662f\u4ec0\u4e48\uff1f<\/strong><br \/>\u5728Python\u4e2d\uff0c\u53ef\u4ee5\u901a\u8fc7<code>sys<\/code>\u6a21\u5757\u67e5\u770b\u5f53\u524d\u7684\u9ed8\u8ba4\u7f16\u7801\u3002\u9996\u5148\uff0c\u5bfc\u5165<code>sys<\/code>\u6a21\u5757\uff0c\u7136\u540e\u4f7f\u7528<code>sys.getdefaultencoding()<\/code>\u51fd\u6570\u6765\u83b7\u53d6\u9ed8\u8ba4\u7f16\u7801\u3002\u4f8b\u5982\uff1a  <\/p>\n<pre><code class=\"language-python\">import sys\nprint(sys.getdefaultencoding())\n<\/code><\/pre>\n<p>\u8fd9\u5c06\u8fd4\u56de\u5f53\u524dPython\u73af\u5883\u7684\u9ed8\u8ba4\u7f16\u7801\uff0c\u901a\u5e38\u662f<code>utf-8<\/code>\u3002<\/p>\n<p><strong>\u66f4\u6539Python\u9ed8\u8ba4\u7f16\u7801\u4f1a\u5f71\u54cd\u54ea\u4e9b\u529f\u80fd\uff1f<\/strong><br \/>\u66f4\u6539\u9ed8\u8ba4\u7f16\u7801\u53ef\u80fd\u4f1a\u5f71\u54cd\u6587\u4ef6\u8bfb\u5199\u64cd\u4f5c\u3001\u5b57\u7b26\u4e32\u7f16\u7801\u548c\u89e3\u7801\u7b49\u529f\u80fd\u3002\u5982\u679c\u5728\u5904\u7406\u6587\u672c\u6587\u4ef6\u65f6\u9ed8\u8ba4\u7f16\u7801\u4e0d\u7b26\u5408\u6587\u4ef6\u7684\u5b9e\u9645\u7f16\u7801\uff0c\u53ef\u80fd\u4f1a\u5bfc\u81f4\u4e71\u7801\u6216\u9519\u8bef\u3002\u56e0\u6b64\uff0c\u5728\u66f4\u6539\u9ed8\u8ba4\u7f16\u7801\u65f6\uff0c\u9700\u8981\u786e\u4fdd\u4f60\u7684\u6570\u636e\u548c\u6587\u4ef6\u90fd\u4e0e\u65b0\u7f16\u7801\u517c\u5bb9\u3002<\/p>\n<p><strong>\u5728\u4e0d\u540c\u7684\u64cd\u4f5c\u7cfb\u7edf\u4e2d\u66f4\u6539Python\u9ed8\u8ba4\u7f16\u7801\u7684\u6b65\u9aa4\u662f\u5426\u76f8\u540c\uff1f<\/strong><br \/>\u5728\u4e0d\u540c\u64cd\u4f5c\u7cfb\u7edf\u4e0a\u66f4\u6539Python\u9ed8\u8ba4\u7f16\u7801\u7684\u57fa\u672c\u65b9\u6cd5\u662f\u76f8\u4f3c\u7684\uff0c\u4f46\u53ef\u80fd\u4f1a\u6709\u4e00\u4e9b\u5dee\u5f02\u3002\u4f8b\u5982\uff0c\u5728Windows\u4e0a\uff0c\u53ef\u80fd\u9700\u8981\u901a\u8fc7\u8bbe\u7f6e\u73af\u5883\u53d8\u91cf\u6765\u5f71\u54cd\u9ed8\u8ba4\u7f16\u7801\u3002\u800c\u5728Linux\u6216Mac\u7cfb\u7edf\u4e2d\uff0c\u901a\u5e38\u53ef\u4ee5\u901a\u8fc7\u4fee\u6539<code>sitecustomize.py<\/code>\u6587\u4ef6\u6765\u5b9e\u73b0\u3002\u5728\u5177\u4f53\u5b9e\u65bd\u65f6\uff0c\u5efa\u8bae\u67e5\u9605\u76f8\u5173\u64cd\u4f5c\u7cfb\u7edf\u7684\u6587\u6863\u4ee5\u83b7\u53d6\u66f4\u8be6\u7ec6\u7684\u4fe1\u606f\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"\u66f4\u6539Python\u9ed8\u8ba4\u7f16\u7801\u7684\u65b9\u6cd5\u5305\u62ec\uff1a\u4fee\u6539\u73af\u5883\u53d8\u91cf\u3001\u4f7f\u7528sys\u6a21\u5757\u3001\u8c03\u6574IDE\u8bbe\u7f6e\u3002\u5728\u8fd9\u4e9b\u65b9\u6cd5\u4e2d\uff0c\u4f7f\u7528sys\u6a21\u5757 [&hellip;]","protected":false},"author":3,"featured_media":954767,"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\/954766"}],"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=954766"}],"version-history":[{"count":"1","href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/954766\/revisions"}],"predecessor-version":[{"id":954768,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/954766\/revisions\/954768"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media\/954767"}],"wp:attachment":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media?parent=954766"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/categories?post=954766"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/tags?post=954766"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}