{"id":6327,"date":"2021-03-11T04:10:07","date_gmt":"2021-03-10T20:10:07","guid":{"rendered":"https:\/\/vip.fxxkpython.com\/?p=6327"},"modified":"2021-03-11T04:10:09","modified_gmt":"2021-03-10T20:10:09","slug":"%e4%bd%a0%e8%83%bd%e4%bd%93%e4%bc%9a%e9%82%a3%e7%a7%8d%e5%86%99-python-%e6%97%b6%e4%b8%8d%e7%94%a8-import-%e7%9a%84%e5%b9%b8%e7%a6%8f%e5%90%97%ef%bc%9f","status":"publish","type":"post","link":"https:\/\/vip.fxxkpython.com\/?p=6327","title":{"rendered":"\u4f60\u80fd\u4f53\u4f1a\u90a3\u79cd\u5199 Python \u65f6\u4e0d\u7528 import \u7684\u5e78\u798f\u5417\uff1f"},"content":{"rendered":"\n<p>\u5728\u5199 Python \u7a0b\u5e8f\u7684\u65f6\u5019\uff0c\u6211\u4eec\u9700\u8981\u4f9d\u8d56\u4e00\u4e9b\u5e93\uff0c\u6240\u4ee5\u4e00\u5f00\u59cb\u6211\u4eec\u603b\u662f\uff1a<\/p>\n\n\n\n<p>import xxx as xxx<\/p>\n\n\n\n<p> from xxx import xxx<\/p>\n\n\n\n<p>\u6211\u4eec\u6709\u65f6\u5019\u5199\u7740\u5199\u7740\u53d1\u73b0\u9700\u8981\u5f15\u5165\u65b0\u7684\u5e93\uff0c\u5c31\u53c8\u5f97\u56de\u5230\u524d\u9762\uff0c\u518d import \u4e00\u6ce2\uff0c\u5982\u679c\u4f60\u7528\u7684\u662f\u7c7b\u4f3c jupyter \u7684\u7f16\u8f91\u5668\uff0c\u4f60\u6dfb\u52a0\u5b8c import \u8bed\u53e5\u4e4b\u540e\u8fd8\u5f97\u518d\u8fd0\u884c\u4e00\u4e0b\u4ee3\u7801\u5757\u3002\u200b<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/pic1.zhimg.com\/80\/v2-624c94e502d3738e8954ddff84cd199d_1440w.jpg\" alt=\"\"\/><\/figure>\n\n\n\n<p>\u8fd9\u4e9b\u64cd\u4f5c\u5f80\u5f80\u90fd\u662f\u91cd\u590d\u6027\u7684\uff0c\u6bd4\u5982\u6211\u4eec\u73a9\u6570\u636e\u53ef\u89c6\u5316\u7684\u65f6\u5019\uff0c\u603b\u4f1a\u8fd9\u6837\u53bb import \u76f8\u5173\u7684\u5e93\uff1a<\/p>\n\n\n\n<p>import pandas as pd <\/p>\n\n\n\n<p>import numpy as np <\/p>\n\n\n\n<p><\/p>\n\n\n\n<p>import seaborn as sns &#8230;<\/p>\n\n\n\n<p>\u8fd9\u65f6\u5019\u6709\u4eba\u5c31\u60f3\u5230\uff0c\u54c7\u9760\uff0c\u771f\u9ebb\u70e6\uff0c\u80fd\u4e0d\u80fd\u4e0d\u8981\u6bcf\u6b21\u90fd\u81ea\u5df1\u5bfc\u5165\u8fd9\u4e9b\u5e93\u554a\uff1f\u4f60\u5df2\u7ecf\u662f\u4e2a\u6210\u5e74\u4eba\u4e86\uff0c\u80fd\u4e0d\u80fd\u5728\u6211\u5199\u4ee3\u7801\u8c03\u7528\u5230\u76f8\u5173\u5e93\u7684\u65f6\u5019\uff0c\u4f60\u7ed9\u8001\u5b50\u81ea\u52a8\u5bfc\u5165\u554a\uff1f\u522b\u62a5\u9519\u554a\uff01<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/pic1.zhimg.com\/80\/v2-de0085136993a3ea8f3eba886c1d5563_1440w.jpg\" alt=\"\"\/><\/figure>\n\n\n\n<p>\u50cf\u8fd9\u6837\uff1a<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/pic2.zhimg.com\/80\/v2-cb50365758e9f5fb87235f36915fc7e0_1440w.gif\" alt=\"\"\/><\/figure>\n\n\n\n<p>\u53ef\u4ee5\u770b\u5230\uff0c\u5728\u8fd9\u91cc\u4e0d\u7528\u4e8b\u5148 import \uff0c\u800c\u662f\u5f53\u4f7f\u7528\u5230\u76f8\u5173\u5e93\u7684\u65f6\u5019\uff0c\u81ea\u52a8\u5728\u7b2c\u4e00\u884c\u5e2e\u6211\u4eec import\uff0c\u5e78\u798f\u554a\uff01<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/pic2.zhimg.com\/80\/v2-b82d68567104a1a5e69de6f4df57b761_1440w.jpg\" alt=\"\"\/><\/figure>\n\n\n\n<p>\u600e\u4e48\u5f04\u7684\u54a7\uff1f\u63a5<\/p>\n\n\n\n<p>\u4e0b\u6765\u5c0f\u5e05b\u8981\u7ed9\u4f60\u5206\u4eab\u7684\u662f\u2014\u2014Pyforest\uff0c\u4e00\u4e2a\u53ef\u4ee5\u81ea\u52a8\u5e2e\u4f60 import \u7684\u5e93\u3002\u8fd9\u4e2a\u5e93\u628a\u4e00\u4e9b\u6d41\u884c\u7684\u6570\u636e\u5206\u6790\u9700\u8981\u7684 \u300cimport \u8bed\u53e5\u300d\u90fd\u5c01\u88c5\u8d77\u6765\u4e86\u3002<\/p>\n\n\n\n<p>\u5b83\u5177\u6709\u300c\u61d2\u52a0\u8f7d\u300d\u7684\u529f\u80fd\uff0c\u4e5f\u5c31\u662f\u8bf4\uff0c\u5f53\u4f60\u5b89\u88c5\u5b8c\u4e4b\u540e\uff0c\u4f60\u5728\u4ee3\u7801\u4e2d\u4f7f\u7528\u5230\u76f8\u5173\u7684\u5e93\u7684\u65f6\u5019\uff0c\u5b83\u5c31\u4f1a\u5e2e\u4f60\u81ea\u52a8 import\u3002\u800c\u90a3\u4e9b\u5c01\u88c5\u597d\u4e86\u7684 import \u8bed\u53e5\uff0c\u5728\u4f60\u6ca1\u6709\u4f7f\u7528\u5230\u65f6\u662f\u4e0d\u4f1a\u5e2e\u4f60\u4e00\u80a1\u8111 import \u8fdb\u6765\u7684\u3002<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/pic1.zhimg.com\/80\/v2-43cd3b4ba03c4af045e7896411dc50d5_1440w.jpg\" alt=\"\"\/><\/figure>\n\n\n\n<p>\u4f60\u53ef\u4ee5\u901a\u8fc7 pip \u5b89\u88c5\u4e00\u6ce2\uff1a<\/p>\n\n\n\n<p>python pip install &#8211;upgrade pyforest<\/p>\n\n\n\n<p>\u5b89\u88c5\u5b8c\u6210\u540e\uff0c\u4f60\u7684 IPython \u542f\u52a8\u914d\u7f6e\u4f1a\u9ed8\u8ba4\u6dfb\u52a0 pyforest_autoimport.py\uff0c\u8fd9\u6837\u6211\u4eec\u5728\u4f7f\u7528 IPython \u6216\u8005 Jupyter \u7684\u65f6\u5019\uff0c\u53ef\u4ee5\u76f4\u63a5\u4f7f\u7528\u5b83\u7684\u529f\u80fd\uff0c\u4f60\u5728\u5199\u4ee3\u7801\u65f6\u8fde\u5b83\u672c\u8eab\u90fd\u4e0d\u9700\u8981 import\uff1aimport pyforest\u6bd4\u5982\u5f53\u4f60\u5b89\u88c5\u5b8c\u4e4b\u540e\uff0c\u4f60\u53ef\u4ee5\u76f4\u63a5\u6253\u5f00 IPython\uff0c\u5728\u4e0d\u7528\u5199 import \u8bed\u53e5\u7684\u60c5\u51b5\u4e0b\uff0c\u76f4\u63a5\u4f7f\u7528\u76f8\u5173\u7684\u5e93\uff1a<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/pic4.zhimg.com\/80\/v2-cb3246aec60ec9251511b3a4db70eb9d_1440w.png\" alt=\"\"\/><\/figure>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/pic2.zhimg.com\/80\/v2-4b0fef378f6cdad0bb6dfd60f7205dbb_1440w.png\" alt=\"\"\/><\/figure>\n\n\n\n<p>\u4f60\u53ef\u4ee5\u770b\u5230\uff0c\u6211\u8fd9\u91cc\u7684\u64cd\u4f5c\u662f\u76f4\u63a5\u4f7f\u7528\u5e93\u7684\u7b80\u79f0\uff0c\u8fd9\u662f\u56e0\u4e3a\u4eba\u5bb6\u5728\u5199 LazyImport \u7684\u65f6\u5019\uff0c\u5df2\u7ecf\u6309\u6211\u4eec\u5199\u4ee3\u7801\u7684\u4e60\u60ef\u5b89\u6392\u597d\u4e86\uff1a<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/pic2.zhimg.com\/80\/v2-50ed854ee51cbed3b18ff18981493bea_1440w.png\" alt=\"\"\/><\/figure>\n\n\n\n<p>\u600e\u4e48\u6837\uff1f<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/pic2.zhimg.com\/80\/v2-795fa0974efa4ed3cac836d573724835_1440w.jpg\" alt=\"\"\/><\/figure>\n\n\n\n<p>\u5f53\u7136\uff0c\u8fd9\u91cc\u9762\u5c01\u88c5\u7684 import \u8bed\u53e5\u66f4\u591a\u662f\u505a\u6570\u636e\u53ef\u89c6\u5316\u76f8\u5173\u7684\uff0c\u90a3\u4e48\u5982\u679c\u4f60\u81ea\u5df1\u8fd8\u60f3\u6dfb\u52a0\u4e00\u4e9b\u522b\u7684 import \u8bed\u53e5\u8fdb\u53bb\uff0c\u548b\u6574\u5462\uff1f\u5f88\u7b80\u5355\uff0c\u8fdb\u5165\u5230\u4f60\u5b89\u88c5\u7684 pyforest \u4e2d\uff0c\u5728 user_imports.py \u4e2d\u6dfb\u52a0\u5373\u53ef\uff0c\u4e00\u822c\u8def\u5f84\u5982\u4e0b\uff1a<\/p>\n\n\n\n<p>~\/.pyforest\/user_imports.py<\/p>\n\n\n\n<p>\u6bd4\u5982\uff0c\u6211\u5728\u8fd9\u91cc\u6dfb\u52a0\u4e00\u4e2a import requests \u7684\u8bed\u53e5\uff1a<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/pic2.zhimg.com\/80\/v2-b0ce784addedc881b81885a7da5ca174_1440w.png\" alt=\"\"\/><\/figure>\n\n\n\n<p>\u63a5\u7740\u6211\u5c31\u53ef\u4ee5\u5728\u4e0d\u7528\u5bfc\u5165 requests \u7684\u60c5\u51b5\u4e0b\uff0c\u76f4\u63a5\u8bf7\u6c42\u4e86\uff1a<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/pic4.zhimg.com\/80\/v2-7948cebd30c8fed001141cc327352dfb_1440w.png\" alt=\"\"\/><\/figure>\n\n\n\n<p>\u4f60\u5b8c\u5168\u53ef\u4ee5\u6839\u636e\u4f60\u81ea\u5df1\u7684\u4e60\u60ef\uff0c\u5728 user_imports.py \u6dfb\u52a0 import \u8bed\u53e5\u3002\u5988\u5988\u518d\u4e5f\u4e0d\u7528\u62c5\u5fc3\uff0c\u6bcf\u6b21\u4f9d\u8d56\u5e93\u7684\u65f6\u5019\u90fd\u9700\u8981\u5199 import \u4e86\u3002<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/pic1.zhimg.com\/80\/v2-365f66abd6a89d9a569d8ddea0071a96_1440w.gif\" alt=\"\"\/><\/figure>\n\n\n\n<p>\u8fd9\u4e2a\u5e93\u6bd4\u8f83\u9002\u5408\u5728Jupyter Notebook, Jupyter Lab \u6216\u8005 IPython \u4e2d\u4f7f\u7528\uff0c\u5982\u679c\u4f60\u60f3\u5728\u522b\u7684\u5730\u65b9\u4e5f\u4f7f\u7528\u5b83\uff0c\u53ef\u4ee5\u5148\u5bfc\u5165 Pyforest\uff0c\u63a5\u7740\u5c31\u53ef\u4ee5\u4f7f\u7528\u4f60\u5df2\u7ecf\u5c01\u88c5\u597d\u7684 import \u8bed\u53e5\uff0c\u50cf\u8fd9\u6837\uff1a<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/pic2.zhimg.com\/80\/v2-9c4ccd20f3f555384aaa0b876d9e6258_1440w.png\" alt=\"\"\/><\/figure>\n\n\n\n<p>OK\uff0c\u4ee5\u4e0a\u5c31\u662f\u5c0f\u5e05b\u4eca\u5929\u7ed9\u4f60\u5e26\u6765\u7684\u5206\u4eab\uff0c\u5982\u679c\u4f60\u4e4b\u524d\u6ca1\u4e86\u89e3\u8fc7\u8fd9\u4e2a\uff0c\u4e0d\u59a8\u53bb\u8bd5\u8bd5\uff0c\u5b83\u4f1a\u8ba9\u4f60\u5fc3\u60c5\u53d8\u597d\u7684\u5462\uff0c\u5e0c\u671b\u5bf9\u4f60\u6709\u5e2e\u52a9\u3002<strong>\u66f4\u591a\u597d\u73a9\u7684\u5185\u5bb9\uff0c\u70b9\u51fb\u5173\u6ce8\u4e00\u6ce2\uff1a\u5b66\u4e60python\u7684\u6b63\u786e\u59ff\u52bf<\/strong><\/p>\n\n\n\n<p><br><strong>\u66f4\u591a\u79c1\u5bc6\u7684\u5185\u5bb9\uff0c\u4e86\u89e3\u4e00\u6ce2\uff1a<\/strong><\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/pic2.zhimg.com\/80\/v2-b78af880ed9d71ba3a6d46d15e7500ae_1440w.jpg\" alt=\"\"\/><\/figure>\n\n\n\n<p>\u6211\u4eec\u4e0b\u56de\u89c1\uff0c<strong>peace\uff01<\/strong><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5728\u5199 Python \u7a0b\u5e8f\u7684\u65f6\u5019\uff0c\u6211\u4eec\u9700\u8981\u4f9d\u8d56\u4e00\u4e9b\u5e93\uff0c\u6240\u4ee5\u4e00\u5f00\u59cb\u6211\u4eec\u603b\u662f\uff1a import xxx as xxx from xxx import xxx \u6211\u4eec\u6709\u65f6\u5019\u5199\u7740\u5199\u7740\u53d1\u73b0\u9700\u8981\u5f15\u5165\u65b0\u7684\u5e93\uff0c\u5c31\u53c8\u5f97\u56de\u5230\u524d\u9762\uff0c\u518d import \u4e00\u6ce2\uff0c\u5982\u679c\u4f60\u7528\u7684\u662f\u7c7b\u4f3c ju&hellip;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[303],"tags":[540,541,539],"_links":{"self":[{"href":"https:\/\/vip.fxxkpython.com\/index.php?rest_route=\/wp\/v2\/posts\/6327"}],"collection":[{"href":"https:\/\/vip.fxxkpython.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/vip.fxxkpython.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/vip.fxxkpython.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/vip.fxxkpython.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=6327"}],"version-history":[{"count":1,"href":"https:\/\/vip.fxxkpython.com\/index.php?rest_route=\/wp\/v2\/posts\/6327\/revisions"}],"predecessor-version":[{"id":6328,"href":"https:\/\/vip.fxxkpython.com\/index.php?rest_route=\/wp\/v2\/posts\/6327\/revisions\/6328"}],"wp:attachment":[{"href":"https:\/\/vip.fxxkpython.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=6327"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/vip.fxxkpython.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=6327"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/vip.fxxkpython.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=6327"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}