{"id":158,"date":"2026-11-09T16:25:28","date_gmt":"2026-11-09T08:25:28","guid":{"rendered":"https:\/\/getdevioapp.xyz\/?p=158"},"modified":"2026-11-12T03:52:45","modified_gmt":"2026-11-11T19:52:45","slug":"mac-fastapi-python-venv-devio","status":"publish","type":"post","link":"https:\/\/getdevioapp.xyz\/index.php\/2026\/11\/09\/mac-fastapi-python-venv-devio\/","title":{"rendered":"Mac \u7528 Devio \u8fd0\u884c FastAPI\uff1aPython \u865a\u62df\u73af\u5883\u3001\u542f\u52a8\u547d\u4ee4\u4e0e\u672c\u5730\u57df\u540d"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">\u5728 Apple Silicon Mac \u4e0a\u7528 Devio \u8fd0\u884c FastAPI\uff0c\u9700\u8981\u51c6\u5907 Python \u89e3\u91ca\u5668\u3001\u9879\u76ee\u4f9d\u8d56\u548c\u542f\u52a8\u53c2\u6570\u3002\u9879\u76ee\u8fdb\u7a0b\u4e0e Nginx \u5206\u5f00\u7ba1\u7406\uff1a\u5148\u8ba9\u9879\u76ee\u81ea\u5df1\u7684\u672c\u673a\u7aef\u53e3\u6b63\u5e38\u54cd\u5e94\uff0c\u518d\u914d\u7f6e\u672c\u5730\u57df\u540d\u8bbf\u95ee\uff0c\u5b9a\u4f4d\u95ee\u9898\u4f1a\u66f4\u6e05\u695a\u3002\u672c\u6587\u6309 Devio \u53d1\u5e03\u6587\u6863\u4e2d\u7684\u64cd\u4f5c\u8def\u5f84\u6574\u7406\uff0c\u4e0d\u4f9d\u8d56\u5168\u5c40\u5b89\u88c5 Python \u5305\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">\u5f00\u59cb\u524d\u51c6\u5907\u4ec0\u4e48<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Devio \u662f\u514d\u8d39\u3001\u65e0\u9700\u6ce8\u518c\u7684 Apple Silicon Mac \u672c\u5730\u5f00\u53d1\u73af\u5883\u7ba1\u7406\u5668\uff0c\u76ee\u524d\u672a\u5f00\u6e90\u3002\u8bf7\u4ece<a href=\"https:\/\/getdevioapp.xyz\/index.php\/download\/\">\u5b98\u65b9\u4e0b\u8f7d\u9875<\/a>\u5b89\u88c5\uff0c\u529f\u80fd\u4ee5\u5f53\u524d\u5e94\u7528\u548c<a href=\"https:\/\/getdevioapp.xyz\/index.php\/releases\/\">\u7248\u672c\u8bf4\u660e<\/a>\u4e3a\u51c6\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u51c6\u5907\u4e00\u4e2a\u53ef\u4fe1\u7684 FastAPI \u9879\u76ee\u3002\u4e0b\u9762\u7684\u542f\u52a8\u793a\u4f8b\u5047\u8bbe\u9879\u76ee\u6839\u76ee\u5f55\u6709 main.py\uff0c\u6587\u4ef6\u91cc\u5b9a\u4e49\u4e86\u540d\u4e3a app \u7684 FastAPI \u5e94\u7528\uff1b\u5982\u679c\u4f60\u7684\u6587\u4ef6\u8def\u5f84\u6216\u5bf9\u8c61\u540d\u79f0\u4e0d\u540c\uff0c\u5fc5\u987b\u66ff\u6362 main:app\u3002\u5b89\u88c5\u4f9d\u8d56\u53ef\u80fd\u6267\u884c\u8f6f\u4ef6\u5305\u63d0\u4f9b\u7684\u4ee3\u7801\uff0c\u8bf7\u5148\u786e\u8ba4\u9879\u76ee\u6765\u6e90\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">1. \u9009\u62e9 Python \u89e3\u91ca\u5668<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">\u6253\u5f00\u201c\u8f6f\u4ef6\u7ba1\u7406 \u2192 \u5f00\u53d1\u5de5\u5177 \u2192 Python\u201d\uff0c\u5b89\u88c5\u6240\u9700\u7248\u672c\uff0c\u6216\u9009\u62e9\u5df2\u7ecf\u68c0\u6d4b\u5230\u7684\u672c\u673a Python\u3002\u968f\u540e\u5728\u201c\u7f51\u7ad9\u201d\u521b\u5efa Python \u9879\u76ee\uff0c\u9009\u62e9\u9879\u76ee\u76ee\u5f55\u3001\u89e3\u91ca\u5668\u3001\u76ee\u6807\u7aef\u53e3\u548c\u542f\u52a8\u547d\u4ee4\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u9879\u76ee\u4e2d\u7684 .python-version \u7528\u4e8e\u5339\u914d\u5df2\u5b89\u88c5\u7248\u672c\u3002\u624b\u52a8\u9009\u62e9\u548c\u5df2\u7ecf\u4fdd\u5b58\u7684\u9879\u76ee\u7248\u672c\u4f1a\u4fdd\u7559\uff0c\u4e0d\u4f1a\u56e0\u4e3a\u7ec8\u7aef\u91cc\u7684 python3 \u53d8\u5316\u5c31\u81ea\u52a8\u5207\u6362\u3002\u9879\u76ee\u9700\u8981\u7684\u7248\u672c\u6ca1\u6709\u5b89\u88c5\u65f6\uff0c\u5148\u8865\u9f50\u5bf9\u5e94\u7248\u672c\uff0c\u4e0d\u8981\u53ea\u4fee\u6539\u7248\u672c\u6587\u4ef6\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">2. \u4e3a\u9879\u76ee\u521b\u5efa\u865a\u62df\u73af\u5883\u5e76\u5b89\u88c5\u4f9d\u8d56<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">\u5728\u9879\u76ee\u201c\u7ba1\u7406\u201d\u4e2d\u521b\u5efa\u72ec\u7acb\u7684 .venv\uff0c\u518d\u5b89\u88c5\u4f9d\u8d56\u3002Devio \u652f\u6301 requirements.txt \u548c\u6807\u51c6 pyproject.toml\u3002Poetry\u3001uv\u3001PDM \u6216 Pipenv \u7ba1\u7406\u7684\u9879\u76ee\uff0c\u5e94\u901a\u8fc7\u5bf9\u5e94\u5de5\u5177\u7ba1\u7406\uff0c\u6216\u5148\u5bfc\u51fa requirements.txt\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u786e\u8ba4\u4f9d\u8d56\u5305\u542b FastAPI \u4ee5\u53ca\u672c\u4f8b\u542f\u52a8\u547d\u4ee4\u4f7f\u7528\u7684 Uvicorn\u3002\u5b89\u88c5\u8f93\u51fa\u53ef\u4ee5\u5728\u201c\u9879\u76ee\u65e5\u5fd7\u201d\u4e2d\u67e5\u770b\uff1b\u770b\u5230\u5b89\u88c5\u9519\u8bef\u65f6\u5148\u89e3\u51b3\u4f9d\u8d56\u95ee\u9898\uff0c\u4e0d\u8981\u53cd\u590d\u70b9\u51fb\u542f\u52a8\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">3. \u586b\u5199\u542f\u52a8\u53c2\u6570<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">\u542f\u52a8\u547d\u4ee4\u586b\u5199\u4ea4\u7ed9\u5df2\u9009\u62e9 Python \u7684\u53c2\u6570\uff1a<code>-m uvicorn main:app --host {host} --port {port}<\/code>\u3002\u4e0d\u9700\u8981\u518d\u628a python3 \u5199\u5230\u8fd9\u6bb5\u53c2\u6570\u524d\u9762\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Devio \u4f1a\u628a {host} \u66ff\u6362\u6210 127.0.0.1\uff0c\u628a {port} \u66ff\u6362\u6210\u4f60\u8bbe\u7f6e\u7684\u76ee\u6807\u7aef\u53e3\u3002\u9879\u76ee\u4ee5\u524d\u53f0\u6a21\u5f0f\u8fd0\u884c\uff0c\u5173\u95ed\u81ea\u52a8\u91cd\u8f7d\uff0c\u4e0d\u6dfb\u52a0 <code>--reload<\/code>\u3002\u82e5\u9879\u76ee\u5165\u53e3\u662f app\/main.py \u4e2d\u7684 app\uff0c\u53ef\u6309\u5b9e\u9645\u6a21\u5757\u5e03\u5c40\u4f7f\u7528 app.main:app\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">4. \u5148\u9a8c\u8bc1\u7aef\u53e3\uff0c\u518d\u4f7f\u7528\u672c\u5730\u57df\u540d<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">\u542f\u52a8\u9879\u76ee\u540e\uff0c\u67e5\u770b\u9879\u76ee\u65e5\u5fd7\u4e2d\u7684\u542f\u52a8\u7ed3\u679c\u3002\u82e5\u76ee\u6807\u7aef\u53e3\u662f 8000\uff0c\u53ef\u5728\u6d4f\u89c8\u5668\u8bbf\u95ee http:\/\/127.0.0.1:8000\/docs\uff1b\u8fd9\u9002\u7528\u4e8e\u6ca1\u6709\u5173\u95ed\u6216\u81ea\u5b9a\u4e49 FastAPI \u6587\u6863\u5730\u5740\u7684\u9879\u76ee\u3002\u6587\u6863\u5730\u5740\u88ab\u4fee\u6539\u65f6\uff0c\u4f7f\u7528\u9879\u76ee\u5b9e\u9645\u5b9a\u4e49\u7684\u63a5\u53e3\u9a8c\u8bc1\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u901a\u8fc7 Devio \u7ad9\u70b9\u57df\u540d\u8bbf\u95ee\u524d\uff0c\u8fd8\u9700\u8981\u5230\u9996\u9875\u624b\u52a8\u542f\u52a8 Nginx\u3002\u542f\u7528\u57df\u540d\u540c\u6b65\u4f1a\u4fee\u6539\u7cfb\u7edf hosts \u6587\u4ef6\u7684 Devio \u53d7\u7ba1\u7406\u533a\u5757\u3002\u76f4\u63a5\u7aef\u53e3\u53ef\u8bbf\u95ee\u3001\u57df\u540d\u4e0d\u53ef\u8bbf\u95ee\u65f6\uff0c\u91cd\u70b9\u68c0\u67e5 Nginx\u3001\u57df\u540d\u914d\u7f6e\u548c\u89e3\u6790\uff0c\u800c\u4e0d\u662f\u91cd\u88c5 Python\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">\u5e38\u89c1\u95ee\u9898\u600e\u4e48\u5904\u7406<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>\u63d0\u793a No module named uvicorn\uff1a<\/strong>\u68c0\u67e5\u4f9d\u8d56\u662f\u5426\u5b89\u88c5\u5230\u4e86\u8fd9\u4e2a\u9879\u76ee\u7ed1\u5b9a\u7684\u89e3\u91ca\u5668\u6216\u865a\u62df\u73af\u5883\uff0c\u800c\u4e0d\u662f\u53e6\u4e00\u4e2a\u7ec8\u7aef\u73af\u5883\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>\u63d0\u793a\u627e\u4e0d\u5230 main \u6216 app\uff1a<\/strong>\u68c0\u67e5\u9879\u76ee\u76ee\u5f55\u3001Python \u6a21\u5757\u8def\u5f84\u4ee5\u53ca\u5e94\u7528\u5bf9\u8c61\u540d\u79f0\uff0c\u6309\u5b9e\u9645\u9879\u76ee\u4fee\u6539 main:app\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>\u7aef\u53e3\u5df2\u88ab\u5360\u7528\uff1a<\/strong>\u5728\u201c\u8bbe\u7f6e \u2192 \u7cfb\u7edf\u8bbe\u7f6e\u201d\u68c0\u6d4b\u7aef\u53e3\uff0c\u786e\u8ba4\u5360\u7528\u6765\u6e90\u540e\u6362\u7528\u7a7a\u95f2\u76ee\u6807\u7aef\u53e3\uff0c\u907f\u514d\u968f\u610f\u7ed3\u675f\u5176\u4ed6\u9879\u76ee\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>\u5347\u7ea7 Python \u540e\u65e0\u6cd5\u542f\u52a8\uff1a<\/strong>\u505c\u6b62\u9879\u76ee\u540e\uff0c\u6309\u9700\u8981\u9009\u62e9\u201c\u91cd\u5efa\u73af\u5883\u201d\u5e76\u91cd\u65b0\u5b89\u88c5\u4f9d\u8d56\u3002\u91cd\u5efa\u4f1a\u91cd\u65b0\u5efa\u7acb\u865a\u62df\u73af\u5883\uff0c\u6210\u529f\u540e\u539f\u73af\u5883\u4e2d\u7684\u4f9d\u8d56\u4f1a\u88ab\u79fb\u9664\uff0c\u9879\u76ee\u6e90\u7801\u4fdd\u7559\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">\u4f55\u65f6\u9700\u8981 Nginx\uff0c\u4f55\u65f6\u4e0d\u9700\u8981<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">\u9a8c\u8bc1 FastAPI \u7684\u672c\u673a\u76d1\u542c\u7aef\u53e3\u548c\u63a5\u53e3\u65f6\uff0c\u5148\u5173\u6ce8\u9879\u76ee\u8fdb\u7a0b\u672c\u8eab\uff1b\u9700\u8981\u901a\u8fc7 Devio \u7684\u7ad9\u70b9\u57df\u540d\u8bbf\u95ee\u65f6\uff0c\u518d\u542f\u52a8 Nginx\u3002Devio \u7ba1\u7406\u7684\u662f\u672c\u5730\u5f00\u53d1\u73af\u5883\uff0c\u8fd9\u5957\u6b65\u9aa4\u4e0d\u7b49\u4e8e\u516c\u7f51\u751f\u4ea7\u90e8\u7f72\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u66f4\u591a\u5e38\u89c1\u95ee\u9898\u89c1<a href=\"https:\/\/getdevioapp.xyz\/#devio-faq\">\u9996\u9875\u5e38\u89c1\u95ee\u9898<\/a>\uff1b\u5176\u4ed6\u6559\u7a0b\u89c1<a href=\"https:\/\/getdevioapp.xyz\/index.php\/blog\/\">\u535a\u5ba2<\/a>\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5728 Apple Silicon Mac \u4e0a\u7528 Devio \u914d\u7f6e FastAPI \u9879\u76ee\uff1a\u9009\u62e9 Python\u3001\u521b\u5efa\u865a\u62df\u73af\u5883\u3001\u5b89\u88c5\u4f9d\u8d56\u3001\u586b\u5199 Uvicorn \u542f\u52a8\u53c2\u6570\uff0c\u5e76\u533a\u5206\u9879\u76ee\u7aef\u53e3\u4e0e Nginx \u672c\u5730\u57df\u540d\u95ee\u9898\u3002<\/p>\n","protected":false},"author":1,"featured_media":207,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[5],"tags":[],"class_list":["post-158","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-5"],"_links":{"self":[{"href":"https:\/\/getdevioapp.xyz\/index.php\/wp-json\/wp\/v2\/posts\/158","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/getdevioapp.xyz\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/getdevioapp.xyz\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/getdevioapp.xyz\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/getdevioapp.xyz\/index.php\/wp-json\/wp\/v2\/comments?post=158"}],"version-history":[{"count":4,"href":"https:\/\/getdevioapp.xyz\/index.php\/wp-json\/wp\/v2\/posts\/158\/revisions"}],"predecessor-version":[{"id":255,"href":"https:\/\/getdevioapp.xyz\/index.php\/wp-json\/wp\/v2\/posts\/158\/revisions\/255"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/getdevioapp.xyz\/index.php\/wp-json\/wp\/v2\/media\/207"}],"wp:attachment":[{"href":"https:\/\/getdevioapp.xyz\/index.php\/wp-json\/wp\/v2\/media?parent=158"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/getdevioapp.xyz\/index.php\/wp-json\/wp\/v2\/categories?post=158"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/getdevioapp.xyz\/index.php\/wp-json\/wp\/v2\/tags?post=158"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}