{"id":993067,"date":"2024-12-27T08:42:59","date_gmt":"2024-12-27T00:42:59","guid":{"rendered":"https:\/\/docs.pingcode.com\/ask\/ask-ask\/993067.html"},"modified":"2024-12-27T08:43:02","modified_gmt":"2024-12-27T00:43:02","slug":"python%e5%a6%82%e4%bd%95%e8%87%aa%e5%8a%a8%e5%bc%95%e5%85%a5hsf","status":"publish","type":"post","link":"https:\/\/docs.pingcode.com\/ask\/993067.html","title":{"rendered":"python\u5982\u4f55\u81ea\u52a8\u5f15\u5165hsf"},"content":{"rendered":"<p style=\"text-align:center;\" ><img decoding=\"async\" src=\"https:\/\/cdn-kb.worktile.com\/kb\/wp-content\/uploads\/2024\/04\/25070623\/f40a8b4c-b63c-42fe-9348-31d99f22ba26.webp\" alt=\"python\u5982\u4f55\u81ea\u52a8\u5f15\u5165hsf\" \/><\/p>\n<p><p> <strong>\u5728Python\u4e2d\u81ea\u52a8\u5f15\u5165HSF\uff08Heterogeneous Streaming Framework\uff09\u53ef\u4ee5\u901a\u8fc7\u4f7f\u7528\u73b0\u6709\u7684Python\u5e93\u3001\u7f16\u5199\u81ea\u5b9a\u4e49\u6a21\u5757\u3001\u6216\u8005\u7ed3\u5408\u81ea\u52a8\u5316\u811a\u672c\u6765\u5b9e\u73b0\u3002\u901a\u8fc7\u4f7f\u7528Python\u7684\u5305\u7ba1\u7406\u5668\u3001\u914d\u7f6e\u73af\u5883\u53d8\u91cf\uff0c\u4ee5\u53ca\u7f16\u5199\u521d\u59cb\u5316\u811a\u672c\uff0c\u53ef\u4ee5\u5b9e\u73b0\u81ea\u52a8\u5316\u5f15\u5165\u3002<\/strong><\/p>\n<\/p>\n<p><p>\u8981\u8be6\u7ec6\u63cf\u8ff0\u5176\u4e2d\u7684\u4e00\u79cd\u65b9\u6cd5\uff0c\u6211\u4eec\u53ef\u4ee5\u501f\u52a9Python\u7684\u5305\u7ba1\u7406\u5668\u548c\u865a\u62df\u73af\u5883\u6765\u5b9e\u73b0\u81ea\u52a8\u5316\u3002\u9996\u5148\uff0c\u901a\u8fc7Python\u5305\u7ba1\u7406\u5668\uff08\u5982pip\uff09\u5b89\u88c5\u6240\u9700\u7684HSF\u76f8\u5173\u5e93\u3002\u7136\u540e\uff0c\u521b\u5efa\u4e00\u4e2aPython\u865a\u62df\u73af\u5883\uff0c\u786e\u4fdd\u6240\u6709\u4f9d\u8d56\u5173\u7cfb\u90fd\u5728\u4e00\u4e2a\u72ec\u7acb\u7684\u73af\u5883\u4e2d\u5f97\u5230\u6ee1\u8db3\u3002\u63a5\u4e0b\u6765\uff0c\u53ef\u4ee5\u7f16\u5199\u4e00\u4e2aPython\u811a\u672c\u6216\u8005\u4f7f\u7528\u914d\u7f6e\u6587\u4ef6\u6765\u8bbe\u7f6e\u73af\u5883\u53d8\u91cf\uff0c\u4ee5\u4fbf\u5728\u542f\u52a8\u65f6\u81ea\u52a8\u5f15\u5165HSF\u5e93\u3002\u8fd9\u6837\u4e00\u6765\uff0c\u6bcf\u6b21\u8fd0\u884cPython\u7a0b\u5e8f\u65f6\uff0cHSF\u5e93\u90fd\u4f1a\u88ab\u81ea\u52a8\u52a0\u8f7d\uff0c\u65e0\u9700\u624b\u52a8\u5e72\u9884\u3002<\/p>\n<\/p>\n<hr>\n<p><h3>\u4e00\u3001\u4f7f\u7528PYTHON\u5305\u7ba1\u7406\u5668<\/h3>\n<\/p>\n<p><p>\u5728Python\u4e2d\uff0c\u5305\u7ba1\u7406\u5668\uff08\u5982pip\uff09\u662f\u81ea\u52a8\u5316\u5f15\u5165\u5916\u90e8\u5e93\u7684\u91cd\u8981\u5de5\u5177\u3002\u901a\u8fc7pip\uff0c\u4f60\u53ef\u4ee5\u8f7b\u677e\u5b89\u88c5\u548c\u7ba1\u7406Python\u5e93\u548c\u4f9d\u8d56\u9879\u3002<\/p>\n<\/p>\n<p><h4>\u4f7f\u7528PIP\u5b89\u88c5HSF\u76f8\u5173\u5e93<\/h4>\n<\/p>\n<p><p>\u8981\u4f7f\u7528HSF\u5e93\uff0c\u9996\u5148\u9700\u8981\u786e\u4fdd\u76f8\u5173\u7684\u5e93\u5df2\u7ecf\u5b89\u88c5\u5728\u4f60\u7684\u73af\u5883\u4e2d\u3002\u4f60\u53ef\u4ee5\u901a\u8fc7\u4ee5\u4e0b\u547d\u4ee4\u6765\u5b89\u88c5\u8fd9\u4e9b\u5e93\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">pip install hsf-library<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u786e\u4fdd\u4f60\u5728\u6b63\u786e\u7684Python\u73af\u5883\u4e2d\u8fd0\u884c\u8fd9\u4e2a\u547d\u4ee4\u3002\u5b89\u88c5\u5b8c\u6210\u540e\uff0c\u4f60\u53ef\u4ee5\u5728\u4f60\u7684Python\u811a\u672c\u4e2d\u4f7f\u7528<code>import<\/code>\u8bed\u53e5\u6765\u5f15\u5165HSF\u5e93\u3002<\/p>\n<\/p>\n<p><h4>\u68c0\u67e5\u5b89\u88c5\u662f\u5426\u6210\u529f<\/h4>\n<\/p>\n<p><p>\u5b89\u88c5\u5b8c\u6210\u540e\uff0c\u53ef\u4ee5\u901a\u8fc7\u5728Python\u89e3\u91ca\u5668\u4e2d\u8f93\u5165\u4ee5\u4e0b\u547d\u4ee4\u6765\u9a8c\u8bc1\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import hsf<\/p>\n<p>print(hsf.__version__)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5982\u679c\u6ca1\u6709\u62a5\u9519\u4e14\u6210\u529f\u8f93\u51fa\u7248\u672c\u53f7\uff0c\u8bf4\u660eHSF\u5e93\u5df2\u7ecf\u6b63\u786e\u5b89\u88c5\u5e76\u53ef\u4ee5\u4f7f\u7528\u3002<\/p>\n<\/p>\n<p><h3>\u4e8c\u3001\u4f7f\u7528\u865a\u62df\u73af\u5883<\/h3>\n<\/p>\n<p><p>\u865a\u62df\u73af\u5883\u662fPython\u9879\u76ee\u5f00\u53d1\u4e2d\u7684\u4e00\u4e2a\u91cd\u8981\u5de5\u5177\u3002\u5b83\u53ef\u4ee5\u786e\u4fdd\u9879\u76ee\u7684\u4f9d\u8d56\u5173\u7cfb\u548c\u73af\u5883\u914d\u7f6e\u76f8\u4e92\u72ec\u7acb\uff0c\u4e0d\u4f1a\u4ea7\u751f\u51b2\u7a81\u3002<\/p>\n<\/p>\n<p><h4>\u521b\u5efa\u865a\u62df\u73af\u5883<\/h4>\n<\/p>\n<p><p>\u5728\u9879\u76ee\u76ee\u5f55\u4e0b\uff0c\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u521b\u5efa\u4e00\u4e2a\u65b0\u7684\u865a\u62df\u73af\u5883\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">python -m venv myenv<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u8fd9\u91cc<code>myenv<\/code>\u662f\u865a\u62df\u73af\u5883\u7684\u540d\u5b57\u3002\u4f60\u53ef\u4ee5\u6839\u636e\u9700\u8981\u66f4\u6539\u4e3a\u5176\u4ed6\u540d\u5b57\u3002<\/p>\n<\/p>\n<p><h4>\u6fc0\u6d3b\u865a\u62df\u73af\u5883<\/h4>\n<\/p>\n<p><p>\u5728\u865a\u62df\u73af\u5883\u521b\u5efa\u4e4b\u540e\uff0c\u9700\u8981\u6fc0\u6d3b\u5b83\u4ee5\u786e\u4fdd\u5728\u8fd9\u4e2a\u72ec\u7acb\u7684\u73af\u5883\u4e2d\u5de5\u4f5c\uff1a<\/p>\n<\/p>\n<ul>\n<li>\n<p>\u5728Windows\u4e0a\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">myenv\\Scripts\\activate<\/p>\n<p><\/code><\/pre>\n<\/p>\n<\/li>\n<li>\n<p>\u5728macOS\u548cLinux\u4e0a\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">source myenv\/bin\/activate<\/p>\n<p><\/code><\/pre>\n<\/p>\n<\/li>\n<\/ul>\n<p><h4>\u5b89\u88c5HSF\u5e93\u5230\u865a\u62df\u73af\u5883<\/h4>\n<\/p>\n<p><p>\u6fc0\u6d3b\u865a\u62df\u73af\u5883\u540e\uff0c\u4f7f\u7528pip\u5b89\u88c5HSF\u5e93\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">pip install hsf-library<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u8fd9\u6837\uff0cHSF\u5e93\u548c\u5176\u4ed6\u4f9d\u8d56\u90fd\u4f1a\u5b89\u88c5\u5728\u8fd9\u4e2a\u865a\u62df\u73af\u5883\u4e2d\uff0c\u786e\u4fdd\u4e0e\u5168\u5c40Python\u73af\u5883\u9694\u79bb\u3002<\/p>\n<\/p>\n<p><h3>\u4e09\u3001\u81ea\u52a8\u5316\u811a\u672c\u548c\u914d\u7f6e<\/h3>\n<\/p>\n<p><p>\u4e3a\u4e86\u8fdb\u4e00\u6b65\u81ea\u52a8\u5316HSF\u7684\u5f15\u5165\u8fc7\u7a0b\uff0c\u53ef\u4ee5\u7f16\u5199\u811a\u672c\u6216\u8005\u914d\u7f6e\u73af\u5883\u53d8\u91cf\uff0c\u4f7f\u5f97\u6bcf\u6b21\u542f\u52a8\u9879\u76ee\u65f6\u81ea\u52a8\u52a0\u8f7dHSF\u5e93\u3002<\/p>\n<\/p>\n<p><h4>\u7f16\u5199\u542f\u52a8\u811a\u672c<\/h4>\n<\/p>\n<p><p>\u4f60\u53ef\u4ee5\u7f16\u5199\u4e00\u4e2a\u7b80\u5355\u7684Python\u811a\u672c\u6765\u521d\u59cb\u5316\u5e76\u52a0\u8f7dHSF\u5e93\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import os<\/p>\n<p>import hsf<\/p>\n<p>def initialize_hsf():<\/p>\n<p>    # \u8bbe\u7f6e\u73af\u5883\u53d8\u91cf\uff0c\u6216\u8005\u52a0\u8f7d\u5fc5\u8981\u7684\u914d\u7f6e\u6587\u4ef6<\/p>\n<p>    os.environ[&#39;HSF_CONFIG&#39;] = &#39;\/path\/to\/config&#39;<\/p>\n<p>    # \u521d\u59cb\u5316HSF\u5e93\uff08\u5047\u8bbe\u6709\u521d\u59cb\u5316\u51fd\u6570\uff09<\/p>\n<p>    hsf.initialize()<\/p>\n<p>if __name__ == &quot;__m<a href=\"https:\/\/docs.pingcode.com\/blog\/59162.html\" target=\"_blank\">AI<\/a>n__&quot;:<\/p>\n<p>    initialize_hsf()<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h4>\u4f7f\u7528\u914d\u7f6e\u6587\u4ef6<\/h4>\n<\/p>\n<p><p>\u5982\u679cHSF\u5e93\u652f\u6301\u914d\u7f6e\u6587\u4ef6\uff0c\u53ef\u4ee5\u901a\u8fc7\u5728\u9879\u76ee\u4e2d\u6dfb\u52a0\u914d\u7f6e\u6587\u4ef6\u6765\u81ea\u52a8\u5316\u52a0\u8f7d\u8fc7\u7a0b\u3002\u4f8b\u5982\uff0c\u5728\u9879\u76ee\u6839\u76ee\u5f55\u4e0b\u521b\u5efa\u4e00\u4e2a<code>hsf_config.yaml<\/code>\uff0c\u5e76\u5728\u4ee3\u7801\u4e2d\u8bfb\u53d6\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import hsf<\/p>\n<p>import yaml<\/p>\n<p>def load_config(file_path):<\/p>\n<p>    with open(file_path, &#39;r&#39;) as file:<\/p>\n<p>        return yaml.<a href=\"https:\/\/docs.pingcode.com\/agile\/agile-at-scale\/what-is-safe\" target=\"_blank\">SAFe<\/a>_load(file)<\/p>\n<p>def initialize_hsf():<\/p>\n<p>    config = load_config(&#39;hsf_config.yaml&#39;)<\/p>\n<p>    hsf.initialize(config)<\/p>\n<p>if __name__ == &quot;__main__&quot;:<\/p>\n<p>    initialize_hsf()<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>\u56db\u3001\u6574\u5408\u5230\u5f00\u53d1\u73af\u5883<\/h3>\n<\/p>\n<p><p>\u4e3a\u4e86\u5728\u5f00\u53d1\u73af\u5883\u4e2d\u66f4\u597d\u5730\u7ba1\u7406HSF\u5e93\u7684\u5f15\u5165\uff0c\u53ef\u4ee5\u7ed3\u5408IDE\u7684\u914d\u7f6e\uff0c\u786e\u4fdd\u6bcf\u6b21\u542f\u52a8\u9879\u76ee\u65f6\u90fd\u81ea\u52a8\u52a0\u8f7dHSF\u5e93\u3002<\/p>\n<\/p>\n<p><h4>\u914d\u7f6eIDE<\/h4>\n<\/p>\n<p><p>\u5728\u4f7f\u7528IDE\uff08\u5982PyCharm\u3001VSCode\uff09\u8fdb\u884c\u5f00\u53d1\u65f6\uff0c\u53ef\u4ee5\u5728\u9879\u76ee\u8bbe\u7f6e\u4e2d\u6307\u5b9aPython\u89e3\u91ca\u5668\u4e3a\u865a\u62df\u73af\u5883\u4e2d\u7684\u89e3\u91ca\u5668\uff0c\u786e\u4fdd\u6bcf\u6b21\u8fd0\u884c\u65f6\u90fd\u4f7f\u7528\u6b63\u786e\u7684\u73af\u5883\u3002<\/p>\n<\/p>\n<p><h4>\u4f7f\u7528\u542f\u52a8\u914d\u7f6e<\/h4>\n<\/p>\n<p><p>\u5728IDE\u4e2d\uff0c\u4f60\u53ef\u4ee5\u521b\u5efa\u542f\u52a8\u914d\u7f6e\uff0c\u786e\u4fdd\u9879\u76ee\u5728\u542f\u52a8\u65f6\u81ea\u52a8\u6267\u884c\u521d\u59cb\u5316\u811a\u672c\u3002\u8fd9\u6837\uff0c\u4f60\u5728\u5f00\u53d1\u548c\u8c03\u8bd5\u8fc7\u7a0b\u4e2d\u65e0\u9700\u624b\u52a8\u5f15\u5165HSF\u5e93\u3002<\/p>\n<\/p>\n<p><p>\u901a\u8fc7\u4ee5\u4e0a\u65b9\u6cd5\uff0cPython\u9879\u76ee\u53ef\u4ee5\u5b9e\u73b0\u81ea\u52a8\u5f15\u5165HSF\u5e93\u7684\u529f\u80fd\u3002\u8fd9\u4e0d\u4ec5\u63d0\u9ad8\u4e86\u5f00\u53d1\u6548\u7387\uff0c\u8fd8\u80fd\u786e\u4fdd\u9879\u76ee\u8fd0\u884c\u73af\u5883\u7684\u4e00\u81f4\u6027\u548c\u7a33\u5b9a\u6027\u3002<\/p>\n<\/p>\n<h2><strong>\u76f8\u5173\u95ee\u7b54FAQs\uff1a<\/strong><\/h2>\n<p> <strong>\u5982\u4f55\u5728Python\u4e2d\u81ea\u52a8\u5f15\u5165HSF\u5e93\uff1f<\/strong><br \/>\u5728Python\u4e2d\uff0c\u53ef\u4ee5\u901a\u8fc7\u5728\u811a\u672c\u7684\u5f00\u5934\u4f7f\u7528<code>import<\/code>\u8bed\u53e5\u6765\u81ea\u52a8\u5f15\u5165HSF\u5e93\u3002\u5982\u679cHSF\u5e93\u5df2\u7ecf\u5b89\u88c5\uff0c\u60a8\u53ea\u9700\u5728\u4ee3\u7801\u7684\u9876\u90e8\u6dfb\u52a0<code>import hsf<\/code>\u5373\u53ef\u3002\u5982\u679c\u5c1a\u672a\u5b89\u88c5\uff0c\u8bf7\u4f7f\u7528<code>pip install hsf<\/code>\u8fdb\u884c\u5b89\u88c5\u3002<\/p>\n<p><strong>\u4f7f\u7528HSF\u5e93\u65f6\u5982\u4f55\u5904\u7406\u4f9d\u8d56\u6027\u95ee\u9898\uff1f<\/strong><br \/>\u5f53\u4f7f\u7528HSF\u5e93\u65f6\uff0c\u786e\u4fdd\u6240\u6709\u5fc5\u8981\u7684\u4f9d\u8d56\u9879\u90fd\u5df2\u5b89\u88c5\u3002\u6709\u65f6\uff0cHSF\u53ef\u80fd\u4f9d\u8d56\u4e8e\u5176\u4ed6\u5e93\u3002\u60a8\u53ef\u4ee5\u67e5\u770bHSF\u7684\u6587\u6863\u4ee5\u4e86\u89e3\u6240\u9700\u7684\u4f9d\u8d56\u9879\uff0c\u5e76\u901a\u8fc7<code>pip<\/code>\u547d\u4ee4\u5b89\u88c5\u5b83\u4eec\u3002\u4f8b\u5982\uff0c\u4f7f\u7528<code>pip install -r requirements.txt<\/code>\u547d\u4ee4\u53ef\u4ee5\u5b89\u88c5\u9879\u76ee\u6240\u9700\u7684\u6240\u6709\u4f9d\u8d56\u9879\u3002<\/p>\n<p><strong>\u6709\u6ca1\u6709\u63a8\u8350\u7684\u5de5\u5177\u6216\u65b9\u6cd5\u6765\u7ba1\u7406Python\u73af\u5883\u548c\u5e93\uff1f<\/strong><br \/>\u4e3a\u4e86\u65b9\u4fbf\u7ba1\u7406Python\u73af\u5883\u548c\u5e93\uff0c\u53ef\u4ee5\u4f7f\u7528<code>virtualenv<\/code>\u6216<code>conda<\/code>\u7b49\u5de5\u5177\u3002\u8fd9\u4e9b\u5de5\u5177\u53ef\u4ee5\u521b\u5efa\u72ec\u7acb\u7684\u73af\u5883\uff0c\u786e\u4fdd\u4e0d\u540c\u9879\u76ee\u4e4b\u95f4\u7684\u5e93\u4e0d\u4f1a\u51b2\u7a81\u3002\u5728\u4e00\u4e2a\u65b0\u7684\u73af\u5883\u4e2d\u5b89\u88c5HSF\u5e93\u540e\uff0c\u60a8\u53ef\u4ee5\u8f7b\u677e\u63a7\u5236\u548c\u7ba1\u7406\u9879\u76ee\u7684\u4f9d\u8d56\u6027\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"\u5728Python\u4e2d\u81ea\u52a8\u5f15\u5165HSF\uff08Heterogeneous Streaming Framework\uff09\u53ef\u4ee5\u901a\u8fc7\u4f7f [&hellip;]","protected":false},"author":3,"featured_media":993072,"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\/993067"}],"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=993067"}],"version-history":[{"count":"1","href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/993067\/revisions"}],"predecessor-version":[{"id":993075,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/993067\/revisions\/993075"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media\/993072"}],"wp:attachment":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media?parent=993067"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/categories?post=993067"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/tags?post=993067"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}