{"id":29563,"date":"2025-03-29T14:16:12","date_gmt":"2025-03-29T06:16:12","guid":{"rendered":"https:\/\/www.aisharenet.com\/?p=29563"},"modified":"2025-03-30T00:05:01","modified_gmt":"2025-03-29T16:05:01","slug":"uvminglingxiangjie","status":"publish","type":"post","link":"https:\/\/www.kdjingpai.com\/ja\/uvminglingxiangjie\/","title":{"rendered":"uv\u5e38\u7528\u547d\u4ee4\u5927\u5168"},"content":{"rendered":"<p><code>Python<\/code>\u00a0\u751f\u6001\u5411\u6765\u4e0d\u7f3a\u5305\u7ba1\u7406\u548c\u73af\u5883\u7ba1\u7406\u5de5\u5177\uff0c\u4ece\u7ecf\u5178\u7684\u00a0<code>pip<\/code>\u3001<code>virtualenv<\/code>\u00a0\u5230\u00a0<code>pip-tools<\/code>\u3001<code>conda<\/code>\uff0c\u518d\u5230\u73b0\u4ee3\u5316\u7684\u00a0<code>Poetry<\/code>\u3001<code>PDM<\/code>\u00a0\u7b49\u7b49\u3002\u6bcf\u79cd\u5de5\u5177\u90fd\u6709\u5176\u64c5\u957f\u7684\u9886\u57df\uff0c\u4f46\u4e5f\u5e38\u5e38\u8ba9\u5f00\u53d1\u8005\u7684\u5de5\u5177\u94fe\u53d8\u5f97\u96f6\u6563\u548c\u590d\u6742\u3002<\/p>\n<p>\u73b0\u5728\uff0c\u6765\u81ea\u00a0<code>Astral<\/code>\u00a0\u516c\u53f8\uff08\u77e5\u540d\u00a0<code>Python<\/code>\u00a0Linter\u00a0<code>Ruff<\/code>\u00a0\u7684\u7f14\u9020\u8005\uff09\u7684\u00a0<code>uv<\/code>\u00a0\u6a2a\u7a7a\u51fa\u4e16\uff0c\u5e26\u6765\u4e86\u65b0\u7684\u53ef\u80fd\u6027\u3002\u8fd9\u6b3e\u4f7f\u7528\u00a0<code>Rust<\/code>\u00a0\u8bed\u8a00\u7f16\u5199\u7684\u5de5\u5177\uff0c\u7acb\u5fd7\u6210\u4e3a\u4e00\u4e2a\u00a0<strong>\u901f\u5ea6\u98de\u5feb\u3001\u529f\u80fd\u7edf\u4e00\u4e14\u5bf9\u5f00\u53d1\u8005\u53cb\u597d\u7684\u00a0<code>Python<\/code>\u00a0\u5305\u548c\u9879\u76ee\u7ba1\u7406\u5668<\/strong>\u3002\u5b83\u7684\u76ee\u6807\u5f88\u660e\u786e\uff1a\u501f\u9274\u00a0<code>Rust<\/code>\u00a0\u751f\u6001\u4e2d\u00a0<code>Cargo<\/code>\u00a0\u7684\u6210\u529f\u7ecf\u9a8c\uff0c\u63d0\u4f9b\u4e00\u7ad9\u5f0f\u7684\u89e3\u51b3\u65b9\u6848\u3002<code>uv<\/code>\u00a0\u4e0d\u4ec5\u4ec5\u662f\u5feb\uff0c\u5b83\u8fd8\u5c06\u73af\u5883\u7ba1\u7406\u3001\u5305\u5b89\u88c5\u3001\u4f9d\u8d56\u89e3\u6790\u3001\u9879\u76ee\u7ba1\u7406\u7b49\u529f\u80fd\u6574\u5408\u5230\u4e86\u4e00\u8d77\u3002<\/p>\n<h3>\u4e3a\u4f55\u5173\u6ce8 UV\uff1f<\/h3>\n<p>\u4e0e\u73b0\u6709\u5de5\u5177\u76f8\u6bd4\uff0c<code>uv<\/code>\u00a0\u63d0\u4f9b\u4e86\u4e00\u4e2a\u66f4\u73b0\u4ee3\u3001\u9ad8\u6548\u7684\u9009\u62e9\uff0c\u5176\u6838\u5fc3\u4eae\u70b9\u5728\u4e8e\uff1a<\/p>\n<ol>\n<li><strong>\u663e\u8457\u7684\u901f\u5ea6\u63d0\u5347<\/strong>\uff1a\u57fa\u4e8e\u00a0<code>Rust<\/code>\u00a0\u7684\u7f16\u8bd1\u65f6\u4f18\u5316\u548c\u9ad8\u6548\u7684\u5e76\u53d1\u5904\u7406\u80fd\u529b\uff0c<code>uv<\/code>\u00a0\u5728\u4f9d\u8d56\u89e3\u6790\u3001\u5305\u5b89\u88c5\u7b49\u5e38\u89c1\u64cd\u4f5c\u4e0a\uff0c\u5176\u901f\u5ea6\u76f8\u6bd4\u4f20\u7edf\u5de5\u5177\u5982\u00a0<code>pip<\/code>\u00a0\u6216\u00a0<code>Poetry<\/code>\uff0c\u5f80\u5f80\u80fd\u5feb\u4e0a\u51e0\u4e2a\u6570\u91cf\u7ea7\u3002\u5185\u7f6e\u7684\u9ad8\u6548\u5168\u5c40\u7f13\u5b58\u673a\u5236\uff0c\u4e5f\u8ba9\u91cd\u590d\u64cd\u4f5c\u51e0\u4e4e\u77ac\u65f6\u5b8c\u6210\u3002\u8fd9\u80cc\u540e\u662f\u00a0<code>Rust<\/code>\u00a0\u8bed\u8a00\u7279\u6027\uff08\u5982\u5185\u5b58\u5b89\u5168\u5e26\u6765\u7684\u65e0\u754f\u5e76\u53d1\uff09\u548c\u9ad8\u8d28\u91cf\u5e95\u5c42\u5e93\uff08\u5982\u00a0<code>Tokio<\/code>\u3001<code>Reqwest<\/code>\uff09\u7684\u529f\u52b3\u3002<\/li>\n<li><strong>\u5168\u9762\u7684\u529f\u80fd\u96c6\u6210<\/strong>\uff1a<code>uv<\/code>\u00a0\u610f\u56fe\u6210\u4e3a\u5f00\u53d1\u8005\u624b\u4e2d\u7684\u201c\u745e\u58eb\u519b\u5200\u201d\uff0c\u8986\u76d6\u4ece\u521b\u5efa\u548c\u7ba1\u7406\u865a\u62df\u73af\u5883\u3001\u5b89\u88c5\u548c\u9501\u5b9a\u4f9d\u8d56\uff08\u539f\u751f\u652f\u6301\u00a0<code>pyproject.toml<\/code>\uff0c\u517c\u5bb9\u00a0<code>requirements.txt<\/code>\uff09\uff0c\u5230\u8fd0\u884c\u811a\u672c\u3001\u7ba1\u7406\u5168\u5c40\u5de5\u5177\uff0c\u4e43\u81f3\u5b89\u88c5\u7279\u5b9a\u00a0<code>Python<\/code>\u00a0\u7248\u672c\u7684\u5b8c\u6574\u5f00\u53d1\u6d41\u7a0b\u3002<\/li>\n<li><strong>\u73b0\u4ee3\u5316\u7684\u9879\u76ee\u7ba1\u7406<\/strong>\uff1a\u539f\u751f\u652f\u6301\u00a0<code>pyproject.toml<\/code>\u00a0(PEP 517\/518\/621 \u6807\u51c6)\uff0c\u8fd9\u662f\u73b0\u4ee3\u00a0<code>Python<\/code>\u00a0\u9879\u76ee\u4e8b\u5b9e\u4e0a\u7684\u6807\u51c6\u914d\u7f6e\u6587\u4ef6\u3002<code>uv<\/code>\u00a0\u80fd\u6e05\u6670\u5730\u5904\u7406\u4f9d\u8d56\u5206\u7ec4\uff08\u4f8b\u5982\u5f00\u53d1\u4f9d\u8d56\uff09\uff0c\u5e76\u751f\u6210\u8de8\u5e73\u53f0\u7684\u00a0<code>uv.lock<\/code>\u00a0\u9501\u5b9a\u6587\u4ef6\u3002\u8fd9\u4e2a\u9501\u5b9a\u6587\u4ef6\u7cbe\u786e\u8bb0\u5f55\u4e86\u6240\u6709\u76f4\u63a5\u548c\u95f4\u63a5\u4f9d\u8d56\u7684\u5177\u4f53\u7248\u672c\u548c\u6765\u6e90\uff0c\u786e\u4fdd\u5728\u4efb\u4f55\u673a\u5668\u3001\u4efb\u4f55\u65f6\u95f4\u90fd\u80fd\u91cd\u5efa\u5b8c\u5168\u4e00\u81f4\u7684\u73af\u5883\uff0c\u5b9e\u73b0\u771f\u6b63\u7684\u786e\u5b9a\u6027\u6784\u5efa\u3002<\/li>\n<li><strong>\u826f\u597d\u7684\u517c\u5bb9\u6027<\/strong>\uff1a<code>uv<\/code>\u00a0\u63d0\u4f9b\u4e86\u4e0e\u00a0<code>pip<\/code>\u00a0\u9ad8\u5ea6\u517c\u5bb9\u7684\u547d\u4ee4\u63a5\u53e3 (<code>uv pip ...<\/code>)\uff0c\u5e76\u4e14\u80fd\u591f\u7406\u89e3\u00a0<code>requirements.txt<\/code>\u00a0\u6587\u4ef6\u683c\u5f0f\uff0c\u8fd9\u4f7f\u5f97\u5c06\u73b0\u6709\u9879\u76ee\u8fc1\u79fb\u5230\u00a0<code>uv<\/code>\u00a0\u7684\u8fc7\u7a0b\u76f8\u5bf9\u5e73\u6ed1\u3002<\/li>\n<li><strong>\u6d3b\u8dc3\u7684\u5f00\u53d1\u4e0e\u672a\u6765<\/strong>\uff1a\u7531\u00a0<code>Astral<\/code>\u00a0\u56e2\u961f\u79ef\u6781\u7ef4\u62a4\u5e76\u5feb\u901f\u8fed\u4ee3\uff0c\u91c7\u7528\u00a0<code>MIT<\/code>\u00a0\u5f00\u6e90\u8bb8\u53ef\u3002\u793e\u533a\u5173\u6ce8\u5ea6\u9ad8\uff0c\u53d1\u5c55\u6f5c\u529b\u5de8\u5927\uff0c\u672a\u6765\u53ef\u671f\u3002<\/li>\n<\/ol>\n<p>\u4f7f\u7528\u00a0<code>uv<\/code>\uff0c\u5f00\u53d1\u8005\u6709\u671b\u4f53\u9a8c\u5230\u7c7b\u4f3c\u00a0<code>Node.js<\/code>\u00a0(\u00a0<code>npm<\/code>\u00a0\/\u00a0<code>yarn<\/code>\u00a0\/\u00a0<code>pnpm<\/code>\u00a0) \u6216\u00a0<code>Rust<\/code>\u00a0(\u00a0<code>Cargo<\/code>\u00a0) \u90a3\u6837\u6d41\u7545\u7edf\u4e00\u7684\u4f9d\u8d56\u7ba1\u7406\u5de5\u4f5c\u6d41\u3002<\/p>\n<h3>\u5b89\u88c5 UV<\/h3>\n<p>\u5b89\u88c5\u00a0<code>uv<\/code>\u00a0\u975e\u5e38\u7b80\u5355\u3002\u5b98\u65b9\u63a8\u8350\u4f7f\u7528\u5176\u63d0\u4f9b\u7684\u5b89\u88c5\u811a\u672c\uff0c\u56e0\u4e3a\u5b83\u4e0d\u4f9d\u8d56\u4e8e\u7cfb\u7edf\u4e0a\u5df2\u6709\u7684\u00a0<code>Python<\/code>\u00a0\u73af\u5883\u3002\u5f53\u7136\uff0c\u901a\u8fc7\u00a0<code>pip<\/code>\u00a0\u6216\u7cfb\u7edf\u5305\u7ba1\u7406\u5668\u4e5f\u662f\u53ef\u884c\u7684\u9009\u62e9\u3002<\/p>\n<ul>\n<li><strong>\u63a8\u8350\u65b9\u5f0f (\u8de8\u5e73\u53f0\u811a\u672c)<\/strong>\uff1a\n<pre><code># macOS \/ Linux (bash, zsh, etc.)\r\ncurl -LsSf https:\/\/astral.sh\/uv\/install.sh | sh\r\n# Windows (PowerShell)\r\npowershell -ExecutionPolicy ByPass -c \"irm https:\/\/astral.sh\/uv\/install.ps1 | iex\"\r\n<\/code><\/pre>\n<p><strong>\u6ce8\u610f<\/strong>\uff1a\u5b98\u65b9\u811a\u672c\u9ed8\u8ba4\u4f1a\u5c06\u00a0<code>uv<\/code>\u00a0\u5b89\u88c5\u5230\u7528\u6237\u76ee\u5f55\u4e0b\u7684\u7279\u5b9a\u4f4d\u7f6e\uff08\u4f8b\u5982\u00a0<code>Linux<\/code>\u00a0\/\u00a0<code>macOS<\/code>\u00a0\u7684\u00a0<code>~\/.uv\/bin<\/code>\u00a0\u6216\u00a0<code>Windows<\/code>\u00a0\u7684\u00a0<code>%LOCALAPPDATA%\\uv\\bin<\/code>\uff09\uff0c\u8fd9\u901a\u5e38\u4f4d\u4e8e\u7cfb\u7edf\u76d8\uff08\u5982\u00a0<code>C:<\/code>\u00a0\u76d8\uff09\u3002<\/li>\n<li><strong>\u4f7f\u7528 pip (\u9700\u8981\u73b0\u6709 Python \u73af\u5883)<\/strong>\uff1a\n<pre><code>pip install uv\r\n# \u6216\u63a8\u8350\u4f7f\u7528 pipx \u8fdb\u884c\u9694\u79bb\u5b89\u88c5\r\n# pipx install uv\r\n<\/code><\/pre>\n<p>\u5982\u679c\u4f60\u7684\u00a0<code>Python<\/code>\u00a0\u73af\u5883\u6216\u00a0<code>pipx<\/code>\u00a0\u73af\u5883\u672c\u8eab\u4e0d\u5728\u7cfb\u7edf\u76d8\uff0c\u901a\u8fc7\u8fd9\u79cd\u65b9\u5f0f\u5b89\u88c5\u7684\u00a0<code>uv<\/code>\u00a0\u901a\u5e38\u4e5f\u4f1a\u8ddf\u968f\u5b83\u4eec\u7684\u4f4d\u7f6e\u3002\u4f60\u53ef\u4ee5\u901a\u8fc7\u8bbe\u7f6e\u00a0<code>PIPX_HOME<\/code>\u00a0\u73af\u5883\u53d8\u91cf\u6765\u63a7\u5236\u00a0<code>pipx<\/code>\u00a0\u7684\u5b89\u88c5\u8def\u5f84\u3002<\/li>\n<li><strong>\u4f7f\u7528\u7cfb\u7edf\u5305\u7ba1\u7406\u5668 (\u793a\u4f8b)<\/strong>\uff1a\n<pre><code># macOS (Homebrew)\r\nbrew install uv\r\n# Windows (Scoop)\r\n# \u53ef\u4ee5\u5148\u5c06 Scoop \u672c\u8eab\u5b89\u88c5\u5230\u975e\u7cfb\u7edf\u76d8\uff0c\u7136\u540e\u7528\u5b83\u5b89\u88c5 uv\r\nscoop install uv\r\n# Arch Linux\r\npacman -S uv\r\n<\/code><\/pre>\n<p>\u5982\u679c\u50cf\u00a0<code>Scoop<\/code>\u00a0\u8fd9\u6837\u7684\u5305\u7ba1\u7406\u5668\u672c\u8eab\u88ab\u914d\u7f6e\u5728\u975e\u7cfb\u7edf\u76d8\uff0c\u90a3\u4e48\u5b83\u5b89\u88c5\u7684\u5e94\u7528\uff08\u5305\u62ec\u00a0<code>uv<\/code>\uff09\u901a\u5e38\u4e5f\u4f1a\u5b89\u88c5\u5728\u540c\u4e00\u9a71\u52a8\u5668\u3002<\/li>\n<li><strong>\u4f7f\u7528 Cargo (\u9700\u8981 Rust \u73af\u5883)<\/strong>\uff1a\n<pre><code>cargo install uv --locked --git https:\/\/github.com\/astral-sh\/uv\r\n<\/code><\/pre>\n<p><code>uv<\/code>\u00a0\u4f1a\u88ab\u5b89\u88c5\u5230\u00a0<code>Cargo<\/code>\u00a0\u7684\u00a0<code>bin<\/code>\u00a0\u76ee\u5f55\u3002\u53ef\u4ee5\u901a\u8fc7\u8bbe\u7f6e\u00a0<code>CARGO_HOME<\/code>\u00a0\u73af\u5883\u53d8\u91cf\u5c06\u6574\u4e2a\u00a0<code>.cargo<\/code>\u00a0\u76ee\u5f55\uff08\u5305\u542b\u4e0b\u8f7d\u7684\u00a0<code>crates<\/code>\u00a0\u548c\u7f16\u8bd1\u4ea7\u7269\uff09\u8fc1\u79fb\u5230\u975e\u7cfb\u7edf\u76d8\u3002<\/li>\n<\/ul>\n<p>\u5b89\u88c5\u5b8c\u6210\u540e\uff0c\u8fd0\u884c\u00a0<code>uv --version<\/code>\u00a0\u6216\u00a0<code>uv help<\/code>\u00a0\u6765\u9a8c\u8bc1\u5b89\u88c5\u662f\u5426\u6210\u529f\u3002<\/p>\n<h3>\u914d\u7f6e UV \u6570\u636e\u5b58\u50a8\u4f4d\u7f6e (\u8fdb\u9636)<\/h3>\n<p>\u9ed8\u8ba4\u60c5\u51b5\u4e0b\uff0c<code>uv<\/code>\u00a0\u4f1a\u5c06\u5176\u7f13\u5b58\u3001\u4e0b\u8f7d\u7684\u00a0<code>Python<\/code>\u00a0\u7248\u672c\u4ee5\u53ca\u901a\u8fc7\u00a0<code>uv tool install<\/code>\u00a0\u5b89\u88c5\u7684\u5168\u5c40\u5de5\u5177\u5b58\u50a8\u5728\u7528\u6237\u76ee\u5f55\u4e0b\u7684\u9ed8\u8ba4\u4f4d\u7f6e\uff08\u901a\u5e38\u4f4d\u4e8e\u7cfb\u7edf\u76d8\uff09\u3002\u5982\u679c\u4f60\u5e0c\u671b\u5c06\u8fd9\u4e9b\u6570\u636e\u5b58\u653e\u5230\u5176\u4ed6\u9a71\u52a8\u5668\uff08\u4f8b\u5982\u00a0<code>D:<\/code>\u00a0\u76d8\uff09\u4ee5\u8282\u7701\u7cfb\u7edf\u76d8\u7a7a\u95f4\u6216\u51cf\u5c11\u00a0<code>SSD<\/code>\u00a0\u5199\u5165\uff0c\u53ef\u4ee5\u901a\u8fc7\u8bbe\u7f6e<strong>\u73af\u5883\u53d8\u91cf<\/strong>\u6765\u5b9e\u73b0\u3002<\/p>\n<p>\u4ee5\u4e0b\u662f\u51e0\u4e2a\u5173\u952e\u7684\u73af\u5883\u53d8\u91cf\uff1a<\/p>\n<ul>\n<li><strong><code>UV_CACHE_DIR<\/code><\/strong>: \u63a7\u5236\u00a0<code>uv<\/code>\u00a0\u7f13\u5b58\u76ee\u5f55\u7684\u4f4d\u7f6e\u3002\u7f13\u5b58\u5305\u62ec\u4e0b\u8f7d\u7684\u5305\u6587\u4ef6\u3001\u6784\u5efa\u7684\u00a0<code>wheel<\/code>\u00a0\u7b49\uff0c\u53ef\u80fd\u5360\u7528\u8f83\u5927\u7a7a\u95f4\u3002<\/li>\n<li><strong><code>UV_PYTHON_INSTALL_DIR<\/code><\/strong>: \u63a7\u5236\u901a\u8fc7\u00a0<code>uv python install<\/code>\u00a0\u4e0b\u8f7d\u548c\u7ba1\u7406\u7684\u00a0<code>Python<\/code>\u00a0\u89e3\u91ca\u5668\u7684\u5b89\u88c5\u4f4d\u7f6e\u3002<\/li>\n<li><strong><code>UV_TOOL_INSTALL_DIR<\/code><\/strong>: \u63a7\u5236\u901a\u8fc7\u00a0<code>uv tool install<\/code>\u00a0\u5b89\u88c5\u7684\u5168\u5c40\u00a0<code>Python<\/code>\u00a0\u5de5\u5177\u53ca\u5176\u9694\u79bb\u73af\u5883\u7684\u5b58\u50a8\u4f4d\u7f6e\u3002<\/li>\n<\/ul>\n<p><strong>\u5982\u4f55\u8bbe\u7f6e\u73af\u5883\u53d8\u91cf (\u793a\u4f8b)<\/strong>:<\/p>\n<p>\u5047\u8bbe\u76ee\u6807\u662f\u5c06\u6240\u6709\u00a0<code>uv<\/code>\u00a0\u6570\u636e\u5b58\u50a8\u5230\u00a0<code>D:\\uvdata<\/code>\u00a0\u76ee\u5f55\u4e0b\u3002<\/p>\n<ul>\n<li><strong>Windows (PowerShell &#8211; \u4e34\u65f6\u8bbe\u7f6e\uff0c\u4ec5\u5f53\u524d\u4f1a\u8bdd\u6709\u6548)<\/strong>:\n<pre><code>$env:UV_CACHE_DIR = \"D:\\uvdata\\cache\"\r\n$env:UV_PYTHON_INSTALL_DIR = \"D:\\uvdata\\python\"\r\n$env:UV_TOOL_INSTALL_DIR = \"D:\\uvdata\\tools\"\r\n# \u4e4b\u540e\u5728\u6b64\u4f1a\u8bdd\u4e2d\u8fd0\u884c uv \u547d\u4ee4\uff0c\u6570\u636e\u5c06\u5199\u5165\u65b0\u4f4d\u7f6e\r\nuv pip install requests\r\n<\/code><\/pre>\n<\/li>\n<li><strong>Windows (\u7cfb\u7edf\u73af\u5883\u53d8\u91cf &#8211; \u6c38\u4e45\u8bbe\u7f6e)<\/strong>:\n<ol>\n<li>\u5728\u00a0<code>Windows<\/code>\u00a0\u641c\u7d22\u680f\u67e5\u627e\u201c\u73af\u5883\u53d8\u91cf\u201d\u3002<\/li>\n<li>\u70b9\u51fb\u201c\u7f16\u8f91\u7cfb\u7edf\u73af\u5883\u53d8\u91cf\u201d\u3002<\/li>\n<li>\u5728\u201c\u7cfb\u7edf\u5c5e\u6027\u201d\u5bf9\u8bdd\u6846\u4e2d\uff0c\u70b9\u51fb\u201c\u73af\u5883\u53d8\u91cf&#8230;\u201d\u6309\u94ae\u3002<\/li>\n<li>\u5728\u201c\u7528\u6237\u53d8\u91cf\u201d\u6216\u201c\u7cfb\u7edf\u53d8\u91cf\u201d\u533a\u57df\uff08\u63a8\u8350\u201c\u7528\u6237\u53d8\u91cf\u201d\uff0c\u9664\u975e\u9700\u8981\u4e3a\u6240\u6709\u7528\u6237\u8bbe\u7f6e\uff09\uff0c\u70b9\u51fb\u201c\u65b0\u5efa&#8230;\u201d\u3002<\/li>\n<li>\u8f93\u5165\u53d8\u91cf\u540d\uff08\u5982\u00a0<code>UV_CACHE_DIR<\/code>\uff09\u548c\u53d8\u91cf\u503c\uff08\u5982\u00a0<code>D:\\uvdata\\cache<\/code>\uff09\u3002<\/li>\n<li>\u4e3a\u5176\u4ed6\u4e24\u4e2a\u53d8\u91cf\u91cd\u590d\u6b64\u64cd\u4f5c\u3002<\/li>\n<li>\u70b9\u51fb\u201c\u786e\u5b9a\u201d\u5173\u95ed\u6240\u6709\u5bf9\u8bdd\u6846\u3002<\/li>\n<li><strong>\u5173\u952e<\/strong>: \u9700\u8981<strong>\u91cd\u65b0\u6253\u5f00<\/strong>\u00a0<code>PowerShell<\/code>\u00a0\u6216\u547d\u4ee4\u63d0\u793a\u7b26\u7a97\u53e3\uff0c\u65b0\u7684\u73af\u5883\u53d8\u91cf\u624d\u4f1a\u751f\u6548\u3002<\/li>\n<\/ol>\n<\/li>\n<li><strong>Linux \/ macOS (bash\/zsh &#8211; \u4e34\u65f6\u8bbe\u7f6e)<\/strong>:\n<pre><code>export UV_CACHE_DIR=\"\/path\/to\/non_system_drive\/uvdata\/cache\"\r\nexport UV_PYTHON_INSTALL_DIR=\"\/path\/to\/non_system_drive\/uvdata\/python\"\r\nexport UV_TOOL_INSTALL_DIR=\"\/path\/to\/non_system_drive\/uvdata\/tools\"\r\n# \u4e4b\u540e\u5728\u6b64\u4f1a\u8bdd\u4e2d\u8fd0\u884c uv \u547d\u4ee4\r\nuv pip install requests\r\n<\/code><\/pre>\n<\/li>\n<li><strong>Linux \/ macOS (\u6c38\u4e45\u8bbe\u7f6e)<\/strong>:<br \/>\n\u5c06\u4e0a\u9762\u7684\u00a0<code>export<\/code>\u00a0\u547d\u4ee4\u6dfb\u52a0\u5230\u4f60\u7684 Shell \u914d\u7f6e\u6587\u4ef6\uff08\u4f8b\u5982\u00a0<code>~\/.bashrc<\/code>,\u00a0<code>~\/.zshrc<\/code>,\u00a0<code>~\/.profile<\/code>\uff09\u4e2d\uff0c\u7136\u540e\u6267\u884c\u00a0<code>source ~\/.your_config_file<\/code>\u00a0\u6216\u91cd\u542f\u7ec8\u7aef\u4f7f\u914d\u7f6e\u751f\u6548\u3002<\/li>\n<\/ul>\n<p><strong>\u91cd\u8981\u63d0\u793a<\/strong>:<\/p>\n<ul>\n<li>\u8bbe\u7f6e\u8fd9\u4e9b\u73af\u5883\u53d8\u91cf\u540e\uff0c<code>uv<\/code>\u00a0\u4f1a\u81ea\u52a8\u4f7f\u7528\u6307\u5b9a\u7684\u8def\u5f84\u3002\u8bf7\u786e\u4fdd\u8fd9\u4e9b\u76ee\u5f55\u5b58\u5728\u4e14\u00a0<code>uv<\/code>\u00a0\u62e5\u6709\u5199\u5165\u6743\u9650\u3002<\/li>\n<li><strong>\u865a\u62df\u73af\u5883 (<code>.venv<\/code>) \u7684\u4f4d\u7f6e<\/strong>:\u00a0<code>uv venv<\/code>\u00a0\u9ed8\u8ba4\u5728\u4f60\u7684<strong>\u9879\u76ee\u6839\u76ee\u5f55<\/strong>\u4e0b\u521b\u5efa\u00a0<code>.venv<\/code>\u00a0\u6587\u4ef6\u5939\u3002\u56e0\u6b64\uff0c<strong>\u53ea\u8981\u4f60\u7684\u9879\u76ee\u672c\u8eab\u4f4d\u4e8e\u975e\u7cfb\u7edf\u76d8\uff08\u6bd4\u5982\u00a0<code>D:\\myproject<\/code>\uff09\uff0c\u90a3\u4e48\u00a0<code>.venv<\/code>\u00a0\u81ea\u7136\u4e5f\u4f1a\u5728\u8be5\u76d8<\/strong>\u3002\u901a\u5e38\u65e0\u9700\u4e3a\u00a0<code>.venv<\/code>\u00a0\u5355\u72ec\u914d\u7f6e\u8def\u5f84\u6765\u907f\u5f00\u7cfb\u7edf\u76d8\u3002\u5f53\u7136\uff0c\u4f60\u4e5f\u53ef\u4ee5\u901a\u8fc7\u00a0<code>uv venv \/path\/to\/custom\/env<\/code>\u00a0\u663e\u5f0f\u6307\u5b9a\u865a\u62df\u73af\u5883\u7684\u521b\u5efa\u4f4d\u7f6e\uff0c\u4f46\u8fd9\u66f4\u591a\u662f\u4e3a\u4e86\u81ea\u5b9a\u4e49\u73af\u5883\u8def\u5f84\uff0c\u800c\u975e\u89e3\u51b3\u7cfb\u7edf\u76d8\u5b58\u50a8\u95ee\u9898\u3002<\/li>\n<\/ul>\n<p>\u901a\u8fc7\u5408\u7406\u914d\u7f6e\u8fd9\u4e9b\u73af\u5883\u53d8\u91cf\uff0c\u53ef\u4ee5\u6709\u6548\u7ba1\u7406\u00a0<code>uv<\/code>\u00a0\u4ea7\u751f\u7684\u6570\u636e\uff0c\u5c06\u5176\u5f15\u5bfc\u5230\u7a7a\u95f4\u66f4\u5145\u88d5\u6216\u66f4\u5408\u9002\u7684\u5b58\u50a8\u4f4d\u7f6e\u3002<\/p>\n<h3>UV \u6838\u5fc3\u6982\u5ff5<\/h3>\n<p>\u5728\u4f7f\u7528\u00a0<code>uv<\/code>\u00a0\u7ba1\u7406\u9879\u76ee\u65f6\uff0c\u7406\u89e3\u4ee5\u4e0b\u51e0\u4e2a\u6838\u5fc3\u6982\u5ff5\u975e\u5e38\u91cd\u8981\uff1a<\/p>\n<ul>\n<li><strong><code>pyproject.toml<\/code><\/strong>\uff1a\u73b0\u4ee3\u00a0<code>Python<\/code>\u00a0\u9879\u76ee\u7684\u6807\u51c6\u914d\u7f6e\u6587\u4ef6 (\u57fa\u4e8e PEP 517\/518\/621)\u3002<code>uv<\/code>\u00a0\u5229\u7528\u5b83\u6765\u5b9a\u4e49\u9879\u76ee\u5143\u6570\u636e\uff08\u540d\u79f0\u3001\u7248\u672c\u3001\u63cf\u8ff0\u7b49\uff09\u3001\u6240\u9700\u7684\u00a0<code>Python<\/code>\u00a0\u7248\u672c (<code>requires-python<\/code>) \u4ee5\u53ca\u9879\u76ee\u7684\u4e3b\u8981\u4f9d\u8d56 (<code>dependencies<\/code>) \u548c\u53ef\u9009\u4f9d\u8d56\u7ec4\uff08\u4f8b\u5982\u00a0<code>dev-dependencies<\/code>\uff09\u3002\u5b83\u662f\u9879\u76ee\u914d\u7f6e\u7684\u201c\u5355\u4e00\u4e8b\u5b9e\u6765\u6e90\u201d\u3002<\/li>\n<li><strong><code>uv.lock<\/code><\/strong>\uff1a\u7531\u00a0<code>uv<\/code>\u00a0\u81ea\u52a8\u751f\u6210\u548c\u7ba1\u7406\u7684\u9501\u5b9a\u6587\u4ef6\u3002\u5b83\u7cbe\u786e\u8bb0\u5f55\u4e86\u9879\u76ee\u6240\u6709\u4f9d\u8d56\uff08\u5305\u62ec\u95f4\u63a5\u4f9d\u8d56\uff09\u7684\u5177\u4f53\u7248\u672c\u53f7\u548c\u6765\u6e90\u54c8\u5e0c\u503c\u3002\u5176\u6838\u5fc3\u4ef7\u503c\u5728\u4e8e\u786e\u4fdd<strong>\u73af\u5883\u7684\u53ef\u590d\u73b0\u6027<\/strong>\uff1a\u65e0\u8bba\u4f55\u65f6\u4f55\u5730\uff0c\u53ea\u8981\u57fa\u4e8e\u540c\u4e00\u4e2a\u00a0<code>uv.lock<\/code>\u00a0\u6587\u4ef6\u5b89\u88c5\u4f9d\u8d56\uff0c\u5c31\u80fd\u5f97\u5230\u5b8c\u5168\u76f8\u540c\u7684\u5305\u7ec4\u5408\u3002<strong>\u8fd9\u4e2a\u6587\u4ef6\u4e0d\u5e94\u8be5\u624b\u52a8\u7f16\u8f91<\/strong>\u3002<\/li>\n<li><strong>\u865a\u62df\u73af\u5883 (<code>.venv<\/code>)<\/strong>\uff1a<code>uv<\/code>\u00a0\u6781\u529b\u63a8\u8350\u5e76\u7b80\u5316\u4e86\u865a\u62df\u73af\u5883\u7684\u4f7f\u7528\u3002\u5b83\u9ed8\u8ba4\u5728\u9879\u76ee\u6839\u76ee\u5f55\u4e0b\u521b\u5efa\u540d\u4e3a\u00a0<code>.venv<\/code>\u00a0\u7684\u9694\u79bb\u73af\u5883\u6765\u5b58\u653e\u9879\u76ee\u4f9d\u8d56\u3002\u5927\u591a\u6570\u00a0<code>uv<\/code>\u00a0\u547d\u4ee4\uff08\u5982\u00a0<code>add<\/code>,\u00a0<code><a href=\"https:\/\/www.kdjingpai.com\/sync\/\">sync<\/a><\/code>,\u00a0<code>run<\/code>\uff09\u90fd\u80fd\u81ea\u52a8\u68c0\u6d4b\u5e76\u5728\u6b64\u73af\u5883\u4e2d\u6267\u884c\u64cd\u4f5c\uff0c\u907f\u514d\u4e86\u5168\u5c40\u00a0<code>Python<\/code>\u00a0\u73af\u5883\u7684\u6c61\u67d3\u3002<\/li>\n<\/ul>\n<h3>\u4f7f\u7528 UV \u7ba1\u7406 Python \u9879\u76ee<\/h3>\n<p>\u4e0b\u9762\u901a\u8fc7\u4e00\u4e2a\u5b8c\u6574\u6d41\u7a0b\uff0c\u6f14\u793a\u5982\u4f55\u4f7f\u7528\u00a0<code>uv<\/code>\u00a0\u6765\u521b\u5efa\u548c\u7ba1\u7406\u4e00\u4e2a\u00a0<code>Python<\/code>\u00a0\u9879\u76ee\u3002<\/p>\n<h4>\u521d\u59cb\u5316\u9879\u76ee (<code>uv init<\/code>)<\/h4>\n<p>\u4f7f\u7528\u00a0<code>uv init<\/code>\u00a0\u547d\u4ee4\u53ef\u4ee5\u5feb\u901f\u642d\u5efa\u4e00\u4e2a\u65b0\u9879\u76ee\u7684\u57fa\u672c\u7ed3\u6784\u3002<\/p>\n<pre><code># \u786e\u4fdd\u5728\u671f\u671b\u7684\u9a71\u52a8\u5668\u4e0a\u64cd\u4f5c\uff0c\u4f8b\u5982\u5728 D: \u76d8\r\n# D:\r\n# mkdir my_uv_project\r\n# cd my_uv_project\r\n# \u521d\u59cb\u5316\u540d\u4e3a my_uv_project \u7684\u9879\u76ee\r\nuv init my_uv_project\r\ncd my_uv_project\r\n<\/code><\/pre>\n<p>\u6267\u884c\u540e\uff0c<code>uv<\/code>\u00a0\u4f1a\u5728\u00a0<code>my_uv_project<\/code>\u00a0\u76ee\u5f55\u4e0b\u751f\u6210\uff1a<\/p>\n<ul>\n<li><code>.git\/<\/code>\u00a0\u548c\u00a0<code>.gitignore<\/code>\uff1a\u81ea\u52a8\u521d\u59cb\u5316\u00a0<code>Git<\/code>\u00a0\u4ed3\u5e93\uff0c\u5e76\u63d0\u4f9b\u4e00\u4e2a\u5e38\u7528\u7684\u00a0<code>Python<\/code>\u00a0\u9879\u76ee\u00a0<code>.gitignore<\/code>\u00a0\u6587\u4ef6\u3002<\/li>\n<li><code>.python-version<\/code>\uff1a\u8bb0\u5f55\u9879\u76ee\u5efa\u8bae\u6216\u8981\u6c42\u7684\u00a0<code>Python<\/code>\u00a0\u7248\u672c\uff08\u4f8b\u5982\u00a0<code>3.12<\/code>\uff09\u3002<code>uv<\/code>\u00a0\u4f1a\u53c2\u8003\u6b64\u6587\u4ef6\u6765\u9009\u62e9\u6216\u5b89\u88c5\u5408\u9002\u7684\u00a0<code>Python<\/code>\u00a0\u89e3\u91ca\u5668\u3002<\/li>\n<li><code>pyproject.toml<\/code>\uff1a\u9879\u76ee\u7684\u6838\u5fc3\u914d\u7f6e\u6587\u4ef6\uff0c\u5305\u542b\u9879\u76ee\u540d\u3001\u7248\u672c\u3001\u63cf\u8ff0\u3001<code>Python<\/code>\u00a0\u7248\u672c\u8981\u6c42\u548c\u7a7a\u7684\u00a0<code>dependencies<\/code>\u00a0\u5217\u8868\u3002<\/li>\n<li><code>README.md<\/code>\uff1a\u4e00\u4e2a\u7a7a\u7684\u00a0<code>README<\/code>\u00a0\u6587\u4ef6\u3002<\/li>\n<li><code>src\/my_uv_project\/__init__.py<\/code>: \u4e00\u4e2a\u57fa\u672c\u7684\u6e90\u4ee3\u7801\u7ed3\u6784\uff08\u5982\u679c\u4f7f\u7528\u00a0<code>src<\/code>\u00a0\u5e03\u5c40\uff09\u3002\u6216\u8005\u4e00\u4e2a\u7b80\u5355\u7684\u00a0<code>hello.py<\/code>\u00a0\u793a\u4f8b\u6587\u4ef6\u3002<\/li>\n<\/ul>\n<pre><code># pyproject.toml \u793a\u4f8b\u5185\u5bb9 (\u53ef\u80fd\u7565\u6709\u4e0d\u540c)\r\n[project]\r\nname = \"my-uv-project\"\r\nversion = \"0.1.0\"\r\ndescription = \"Add your description here\"\r\nreadme = \"README.md\"\r\nrequires-python = \"&gt;=3.12\" # \u6839\u636e\u7cfb\u7edf\u60c5\u51b5\u6216\u6307\u5b9a\u7248\u672c\u751f\u6210\r\ndependencies = []\r\n[build-system]\r\nrequires = [\"hatchling\"]\r\nbuild-backend = \"hatchling.build\"\r\n# uv \u53ef\u80fd\u8fd8\u4f1a\u6dfb\u52a0 tool.uv \u76f8\u5173\u914d\u7f6e\r\n<\/code><\/pre>\n<h4>\u521b\u5efa\u4e0e\u540c\u6b65\u73af\u5883 (<code>uv venv<\/code>,\u00a0<code>uv sync<\/code>)<\/h4>\n<p>\u9879\u76ee\u521d\u59cb\u5316\u540e\uff0c\u9700\u8981\u521b\u5efa\u865a\u62df\u73af\u5883\u5e76\u540c\u6b65\u4f9d\u8d56\u72b6\u6001\uff08\u5373\u4f7f\u662f\u7a7a\u4f9d\u8d56\uff0c\u9996\u6b21\u540c\u6b65\u4e5f\u4f1a\u751f\u6210\u00a0<code>uv.lock<\/code>\uff09\u3002<\/p>\n<ol>\n<li><strong>\u521b\u5efa\u865a\u62df\u73af\u5883 (<code>uv venv<\/code>)<\/strong>\uff1a<br \/>\n\u867d\u7136\u00a0<code>uv sync<\/code>\u00a0\u7b49\u547d\u4ee4\u5728\u9700\u8981\u65f6\u4f1a\u81ea\u52a8\u521b\u5efa\u00a0<code>.venv<\/code>\uff0c\u4f46\u4e5f\u53ef\u4ee5\u663e\u5f0f\u521b\u5efa\uff1a<\/p>\n<pre><code># \u521b\u5efa\u9ed8\u8ba4\u7684 .venv \u73af\u5883 (uv \u4f1a\u6839\u636e .python-version \u6216\u7cfb\u7edf\u67e5\u627e\u5408\u9002\u7684 Python)\r\n# \u8fd9\u4e2a .venv \u4f1a\u5728\u5f53\u524d\u9879\u76ee\u76ee\u5f55\u4e0b\u521b\u5efa\r\nuv venv\r\n# \u521b\u5efa\u65f6\u6307\u5b9a Python \u7248\u672c\r\nuv venv --python 3.11\r\n# \u6307\u5b9a\u81ea\u5b9a\u4e49\u73af\u5883\u540d\u79f0 (\u4e0d\u5e38\u7528\uff0c\u56e0\u4e3a uv \u751f\u6001\u9ed8\u8ba4\u4e0e .venv \u914d\u5408)\r\nuv venv my_custom_env\r\n<\/code><\/pre>\n<p>\u5982\u679c\u9700\u8981\u624b\u52a8\u64cd\u4f5c\u73af\u5883\uff08\u4f8b\u5982\u4f7f\u7528\u975e\u00a0<code>uv<\/code>\u00a0\u7ba1\u7406\u7684\u5de5\u5177\uff09\uff0c\u5219\u9700\u8981\u6fc0\u6d3b\u5b83\uff1a<\/p>\n<pre><code># Linux\/macOS\r\nsource .venv\/bin\/activate\r\n# Windows (PowerShell)\r\n.venv\\Scripts\\Activate.ps1\r\n# Windows (CMD)\r\n.venv\\Scripts\\activate.bat\r\n<\/code><\/pre>\n<p><strong>\u518d\u6b21\u5f3a\u8c03<\/strong>\uff1a\u5bf9\u4e8e\u7edd\u5927\u591a\u6570\u00a0<code>uv<\/code>\u00a0\u547d\u4ee4 (<code>add<\/code>,\u00a0<code>remove<\/code>,\u00a0<code>sync<\/code>,\u00a0<code>run<\/code>\u00a0\u7b49)\uff0c<strong>\u901a\u5e38\u4e0d\u9700\u8981\u624b\u52a8\u6fc0\u6d3b\u73af\u5883<\/strong>\uff0c<code>uv<\/code>\u00a0\u4f1a\u81ea\u52a8\u67e5\u627e\u5e76\u4f7f\u7528\u00a0<code>.venv<\/code>\u3002<\/li>\n<li><strong>\u540c\u6b65\u73af\u5883 (<code>uv sync<\/code>)<\/strong>\uff1a<br \/>\n\u8fd9\u662f\u6838\u5fc3\u547d\u4ee4\u4e4b\u4e00\uff0c\u7528\u4e8e\u786e\u4fdd\u865a\u62df\u73af\u5883\u7684\u72b6\u6001\u4e0e\u00a0<code>pyproject.toml<\/code>\uff08\u901a\u8fc7\u00a0<code>uv.lock<\/code>\u00a0\u6587\u4ef6\uff09\u6216\u00a0<code>requirements.txt<\/code>\u00a0\u6587\u4ef6\u7cbe\u786e\u4e00\u81f4\u3002\u9996\u6b21\u8fd0\u884c\u65f6\uff0c\u5b83\u4f1a\uff1a<\/p>\n<ul>\n<li>\u8bfb\u53d6\u00a0<code>pyproject.toml<\/code>\u00a0\u7684\u4f9d\u8d56\u5b9a\u4e49\u3002<\/li>\n<li>\u6267\u884c\u4f9d\u8d56\u89e3\u6790\u3002<\/li>\n<li>\u751f\u6210\u00a0<code>uv.lock<\/code>\u00a0\u6587\u4ef6\u3002<\/li>\n<li>\u5728\u00a0<code>.venv<\/code>\u00a0\u4e2d\u5b89\u88c5\u6240\u6709\u5fc5\u9700\u7684\u5305\uff08\u521d\u59cb\u9636\u6bb5\u53ef\u80fd\u53ea\u6709\u9879\u76ee\u672c\u8eab\u4f5c\u4e3a\u53ef\u7f16\u8f91\u5305\uff09\u3002<\/li>\n<\/ul>\n<pre><code># \u5728\u9879\u76ee\u6839\u76ee\u5f55\u8fd0\u884c\r\nuv sync\r\n<\/code><\/pre>\n<p>\u6267\u884c\u540e\uff0c\u4f60\u4f1a\u770b\u5230\u00a0<code>.venv<\/code>\u00a0\u76ee\u5f55\u88ab\u521b\u5efa\u6216\u66f4\u65b0\uff0c\u5e76\u4e14\u751f\u6210\u4e86\u4e00\u4e2a\u00a0<code>uv.lock<\/code>\u00a0\u6587\u4ef6\u3002<\/li>\n<\/ol>\n<h4>\u7ba1\u7406\u4f9d\u8d56 (<code>uv add<\/code>,\u00a0<code>uv remove<\/code>,\u00a0<code>uv lock<\/code>)<\/h4>\n<p>\u8fd9\u662f\u00a0<code>uv<\/code>\u00a0\u6700\u5e38\u7528\u7684\u529f\u80fd\uff0c\u63a8\u8350\u4f7f\u7528\u57fa\u4e8e\u00a0<code>pyproject.toml<\/code>\u00a0\u7684\u5de5\u4f5c\u6d41\u3002<\/p>\n<ul>\n<li><strong>\u6dfb\u52a0\u4f9d\u8d56 (<code>uv add<\/code>)<\/strong>:<br \/>\n\u5c06\u5305\u6dfb\u52a0\u5230\u00a0<code>pyproject.toml<\/code>\u00a0\u7684\u00a0<code>[project.dependencies]<\/code>\u00a0\u90e8\u5206\uff0c\u5e76\u81ea\u52a8\u5b89\u88c5\u6216\u66f4\u65b0\u5230\u00a0<code>.venv<\/code>\u00a0\u73af\u5883\u4e2d\u3002\u540c\u65f6\u00a0<code>uv.lock<\/code>\u00a0\u4e5f\u4f1a\u88ab\u66f4\u65b0\u3002<\/p>\n<pre><code># \u6dfb\u52a0\u6700\u65b0\u7a33\u5b9a\u7248\u7684 pandas\r\nuv add pandas\r\n# \u6dfb\u52a0 requests\uff0c\u5e76\u6307\u5b9a\u7248\u672c\u7ea6\u675f\r\nuv add \"requests&gt;=2.20,&lt;3.0\"\r\n# \u6dfb\u52a0\u5f00\u53d1\u4f9d\u8d56 (\u5982\u6d4b\u8bd5\u6846\u67b6 pytest)\uff0c\u4f1a\u5199\u5165 [tool.uv.dev-dependencies]\r\nuv add pytest --dev\r\nuv add ruff --dev\r\n# \u4ece Git \u4ed3\u5e93\u6dfb\u52a0\u4f9d\u8d56\r\nuv add git+https:\/\/github.com\/psf\/requests.git\r\n# \u6dfb\u52a0\u672c\u5730\u8def\u5f84\u7684\u5305 (\u4ee5\u53ef\u7f16\u8f91\u6a21\u5f0f\u5b89\u88c5)\r\nuv add -e ..\/my_local_library\r\n<\/code><\/pre>\n<\/li>\n<li><strong>\u79fb\u9664\u4f9d\u8d56 (<code>uv remove<\/code>)<\/strong>:<br \/>\n\u4ece\u00a0<code>pyproject.toml<\/code>\u00a0\u4e2d\u79fb\u9664\u6307\u5b9a\u7684\u5305\uff0c\u5e76\u4ece\u00a0<code>.venv<\/code>\u00a0\u73af\u5883\u4e2d\u5378\u8f7d\u5b83\u4ee5\u53ca\u4e0d\u518d\u88ab\u9700\u8981\u7684\u4e0b\u6e38\u4f9d\u8d56\u3002<\/p>\n<pre><code># \u79fb\u9664 pandas\r\nuv remove pandas\r\n# \u79fb\u9664\u5f00\u53d1\u4f9d\u8d56 pytest\r\nuv remove pytest --dev\r\n<\/code><\/pre>\n<\/li>\n<li><strong>\u66f4\u65b0\u4f9d\u8d56<\/strong>:\n<ul>\n<li>\u5c06\u6240\u6709\u4f9d\u8d56\u66f4\u65b0\u5230\u00a0<code>pyproject.toml<\/code>\u00a0\u4e2d\u7ea6\u675f\u5141\u8bb8\u7684\u6700\u65b0\u7248\u672c\uff0c\u5e76\u91cd\u65b0\u751f\u6210\u00a0<code>uv.lock<\/code>\uff1a\n<pre><code># 1. \u66f4\u65b0 lock \u6587\u4ef6\r\nuv lock --upgrade\r\n# 2. \u5e94\u7528 lock \u6587\u4ef6\u66f4\u65b0\u5230\u73af\u5883\r\nuv sync\r\n<\/code><\/pre>\n<\/li>\n<li>\u53ea\u66f4\u65b0\u7279\u5b9a\u7684\u5305\u5230\u6700\u65b0\u7248\u672c\uff1a\n<pre><code># \u65b9\u6cd5\u4e00\uff1a\u6307\u5b9a\u5305\u66f4\u65b0 lock \u6587\u4ef6\uff0c\u7136\u540e\u540c\u6b65\r\nuv lock --upgrade-package requests\r\nuv sync\r\n# \u65b9\u6cd5\u4e8c\uff1a\u76f4\u63a5 'add' \u6700\u65b0\u7248 (\u4e5f\u4f1a\u66f4\u65b0 lock \u548c\u73af\u5883)\r\nuv add requests@latest\r\n<\/code><\/pre>\n<\/li>\n<\/ul>\n<\/li>\n<li><strong>\u624b\u52a8\u7f16\u8f91\u00a0<code>pyproject.toml<\/code>\u00a0\u540e<\/strong>:<br \/>\n\u5982\u679c\u4f60\u76f4\u63a5\u4fee\u6539\u4e86\u00a0<code>pyproject.toml<\/code>\u00a0\u6587\u4ef6\u4e2d\u7684\u4f9d\u8d56\u5217\u8868\uff0c\u9700\u8981\u6267\u884c\u4ee5\u4e0b\u4e24\u6b65\u6765\u4f7f\u66f4\u6539\u751f\u6548\uff1a<\/p>\n<ol>\n<li><code>uv lock<\/code>\u00a0: \u6839\u636e\u00a0<code>pyproject.toml<\/code>\u00a0\u7684\u65b0\u5185\u5bb9\u91cd\u65b0\u8ba1\u7b97\u4f9d\u8d56\u5e76\u66f4\u65b0\u00a0<code>uv.lock<\/code>\u00a0\u6587\u4ef6\u3002<\/li>\n<li><code>uv sync<\/code>\u00a0: \u5c06\u00a0<code>uv.lock<\/code>\u00a0\u6587\u4ef6\u4e2d\u7684\u72b6\u6001\u540c\u6b65\u5230\u00a0<code>.venv<\/code>\u00a0\u865a\u62df\u73af\u5883\u3002<\/li>\n<\/ol>\n<\/li>\n<\/ul>\n<h4>\u8fd0\u884c\u4ee3\u7801\u4e0e\u547d\u4ee4 (<code>uv run<\/code>)<\/h4>\n<p><code>uv run<\/code>\u00a0\u662f\u00a0<code>uv<\/code>\u00a0\u63d0\u4f9b\u7684\u4e00\u4e2a\u6781\u4e3a\u4fbf\u6377\u7684\u529f\u80fd\u3002\u5b83\u5141\u8bb8\u4f60\u5728\u00a0<code>uv<\/code>\u00a0\u7ba1\u7406\u7684\u865a\u62df\u73af\u5883\u4e0a\u4e0b\u6587\u4e2d\u6267\u884c\u00a0<code>Python<\/code>\u00a0\u811a\u672c\u6216\u4efb\u4f55\u547d\u4ee4\uff0c<strong>\u800c\u65e0\u9700\u9884\u5148\u624b\u52a8\u6fc0\u6d3b\u8be5\u73af\u5883<\/strong>\u3002\u8fd9\u662f\u00a0<code>uv<\/code>\u00a0\u7b80\u5316\u5de5\u4f5c\u6d41\u7a0b\u7684\u5173\u952e\u7279\u6027\u4e4b\u4e00\uff0c\u975e\u5e38\u503c\u5f97\u638c\u63e1\u3002<\/p>\n<p><strong>\u5de5\u4f5c\u539f\u7406<\/strong>:<\/p>\n<p>\u5f53\u4f60\u6267\u884c\u00a0<code>uv run &lt;command&gt; [args...]<\/code>\u00a0\u65f6\uff1a<\/p>\n<ol>\n<li><strong>\u81ea\u52a8\u53d1\u73b0\u73af\u5883<\/strong>\uff1a<code>uv<\/code>\u00a0\u4f1a\u81ea\u52a8\u67e5\u627e\u5f53\u524d\u76ee\u5f55\u53ca\u7236\u76ee\u5f55\u4e2d\u7684\u00a0<code>.venv<\/code>\u00a0\u865a\u62df\u73af\u5883\u3002<\/li>\n<li><strong>\u5185\u90e8\u914d\u7f6e\u73af\u5883\u6267\u884c<\/strong>:\n<ul>\n<li>\u5bf9\u4e8e\u00a0<code>uv run python your_script.py<\/code>\u00a0\u8fd9\u6837\u7684\u547d\u4ee4\uff0c<code>uv<\/code>\u00a0\u4f1a\u76f4\u63a5\u8c03\u7528\u00a0<code>.venv<\/code>\u00a0\u76ee\u5f55\u4e0b\u7684\u00a0<code>Python<\/code>\u00a0\u89e3\u91ca\u5668 (<code>.venv\/bin\/python<\/code>\u00a0\u6216\u00a0<code>.venv\/Scripts\/python.exe<\/code>) \u6765\u8fd0\u884c\u811a\u672c\u3002<\/li>\n<li>\u5bf9\u4e8e\u00a0<code>uv run pytest tests\/<\/code>\u00a0\u6216\u00a0<code>uv run ruff format .<\/code>\u00a0\u8fd9\u6837\u7684\u547d\u4ee4\uff0c<code>uv<\/code>\u00a0\u4f1a<strong>\u5728\u6267\u884c\u8be5\u547d\u4ee4\u7684\u5b50\u8fdb\u7a0b\u5185\u90e8<\/strong>\uff0c\u4e34\u65f6\u5c06\u00a0<code>.venv\/bin<\/code>\u00a0(\u6216\u00a0<code>.venv\/Scripts<\/code>) \u76ee\u5f55\u6dfb\u52a0\u5230\u7cfb\u7edf\u00a0<code>PATH<\/code>\u00a0\u73af\u5883\u53d8\u91cf\u7684\u6700\u524d\u9762\u3002\u8fd9\u6837\uff0c\u5373\u4f7f\u4f60\u6ca1\u6709\u6fc0\u6d3b\u73af\u5883\uff0c\u64cd\u4f5c\u7cfb\u7edf\u4e5f\u80fd\u627e\u5230\u5e76\u6267\u884c\u5b89\u88c5\u5728\u865a\u62df\u73af\u5883\u4e2d\u7684\u547d\u4ee4\u884c\u5de5\u5177\uff08\u5982\u00a0<code>pytest<\/code>,\u00a0<code>ruff<\/code>\uff09\u3002<\/li>\n<\/ul>\n<\/li>\n<\/ol>\n<p><strong>\u5982\u4f55\u8fd0\u884c Python \u6587\u4ef6\uff1f<\/strong><\/p>\n<p>\u8981\u8fd0\u884c\u9879\u76ee\u4e2d\u7684\u00a0<code>Python<\/code>\u00a0\u6587\u4ef6\uff08\u4f8b\u5982\u00a0<code>src\/my_package\/main.py<\/code>\u00a0\u6216\u6839\u76ee\u5f55\u7684\u00a0<code>app.py<\/code>\uff09\uff0c\u63a8\u8350\u8fd9\u6837\u505a\uff1a<\/p>\n<pre><code>uv run python src\/my_package\/main.py\r\n# \u6216\u8005\r\nuv run python app.py\r\n<\/code><\/pre>\n<p><strong>\u4f18\u52bf<\/strong>:<\/p>\n<ul>\n<li><strong>\u65e0\u9700\u624b\u52a8\u6fc0\u6d3b<\/strong>\uff1a\u7701\u53bb\u4e86\u8f93\u5165\u00a0<code>source .venv\/bin\/activate<\/code>\u00a0\u6216\u00a0<code>.venv\\Scripts\\Activate.ps1<\/code>\u00a0\u7684\u9ebb\u70e6\uff0c\u6781\u5927\u7b80\u5316\u4e86\u65e5\u5e38\u5f00\u53d1\u548c\u811a\u672c\u6267\u884c\u3002<\/li>\n<li><strong>\u73af\u5883\u4e00\u81f4\u6027\u4fdd\u8bc1<\/strong>\uff1a\u786e\u4fdd\u4f60\u7684\u4ee3\u7801\u548c\u5de5\u5177\u603b\u662f\u5728\u9879\u76ee\u914d\u7f6e\u7684\u6b63\u786e\u865a\u62df\u73af\u5883\u4e2d\u8fd0\u884c\u3002<\/li>\n<li><strong>\u7b80\u5316 CI\/CD \u811a\u672c<\/strong>\uff1a\u5728\u81ea\u52a8\u5316\u6d41\u7a0b\uff08\u5982\u00a0<code>GitHub Actions<\/code>,\u00a0<code>GitLab CI<\/code>\uff09\u4e2d\uff0c\u53ef\u4ee5\u76f4\u63a5\u4f7f\u7528\u00a0<code>uv run<\/code>\u00a0\u6267\u884c\u6d4b\u8bd5\u3001\u6784\u5efa\u3001\u90e8\u7f72\u7b49\u4efb\u52a1\uff0c\u65e0\u9700\u5904\u7406\u590d\u6742\u7684\u73af\u5883\u6fc0\u6d3b\u903b\u8f91\u3002<\/li>\n<\/ul>\n<p><strong>\u66f4\u591a\u00a0<code>uv run<\/code>\u00a0\u793a\u4f8b<\/strong>:<\/p>\n<pre><code># \u8fd0\u884c\u5b89\u88c5\u5728\u73af\u5883\u4e2d\u7684 pytest \u6d4b\u8bd5\r\nuv run pytest tests\/\r\n# \u8fd0\u884c\u5b89\u88c5\u5728\u73af\u5883\u4e2d\u7684 ruff \u4ee3\u7801\u683c\u5f0f\u5316\r\nuv run ruff format .\r\n# \u8fd0\u884c\u4efb\u610f\u7cfb\u7edf\u547d\u4ee4\uff0cuv \u4f1a\u786e\u4fdd .venv\/bin \u5728 PATH \u4e2d\r\nuv run alembic upgrade head\r\n# \u5411\u811a\u672c\u4f20\u9012\u53c2\u6570\r\nuv run python your_script.py --input data.csv --output results.json\r\n<\/code><\/pre>\n<p><strong>\u4f55\u65f6\u4ecd\u9700\u624b\u52a8\u6fc0\u6d3b\uff1f<\/strong><\/p>\n<p>\u624b\u52a8\u6fc0\u6d3b (<code>source activate<\/code>\u00a0\u6216\u7c7b\u4f3c\u547d\u4ee4) \u7684\u573a\u666f\u5927\u5927\u51cf\u5c11\u4e86\u3002\u53ef\u80fd\u4e3b\u8981\u662f\u5728\u540c\u4e00\u4e2a Shell \u4f1a\u8bdd\u4e2d\uff0c\u4f60\u9700\u8981\uff1a<\/p>\n<ul>\n<li>\u9891\u7e41\u5730\u4ea4\u4e92\u5f0f\u8fd0\u884c\u591a\u4e2a\u4f9d\u8d56\u4e8e\u865a\u62df\u73af\u5883\u7684\u547d\u4ee4\uff08\u4f8b\u5982\uff0c\u76f4\u63a5\u8f93\u5165\u00a0<code>python<\/code>\u00a0\u8fdb\u5165\u89e3\u91ca\u5668\uff0c\u7136\u540e\u662f\u00a0<code>pytest<\/code>\uff0c\u518d\u662f\u00a0<code>ruff<\/code>\uff09\u3002<\/li>\n<li>\u4f7f\u7528\u67d0\u4e9b\u4f9d\u8d56\u4e8e\u6fc0\u6d3b\u811a\u672c\u8bbe\u7f6e\u7684\u7279\u5b9a\u73af\u5883\u53d8\u91cf\uff08\u9664\u4e86\u00a0<code>PATH<\/code>\u00a0\u4e4b\u5916\uff09\u7684\u975e\u00a0<code>Python<\/code>\u00a0\u5de5\u5177\u3002<\/li>\n<\/ul>\n<p>\u4f46\u5bf9\u4e8e\u5927\u591a\u6570\u65e5\u5e38\u5f00\u53d1\u4efb\u52a1\uff0c<code>uv run<\/code>\u00a0\u63d0\u4f9b\u7684\u81ea\u52a8\u73af\u5883\u7ba1\u7406\u66f4\u52a0\u65b9\u4fbf\u9ad8\u6548\u3002<\/p>\n<h4>\u4f7f\u7528\u00a0<code>requirements.txt<\/code>\u00a0(\u517c\u5bb9\u5de5\u4f5c\u6d41)<\/h4>\n<p>\u867d\u7136\u00a0<code>uv<\/code>\u00a0\u63a8\u8350\u4f7f\u7528\u00a0<code>pyproject.toml<\/code>\uff0c\u4f46\u5b83\u4e5f\u5b8c\u5168\u652f\u6301\u4f20\u7edf\u7684\u00a0<code>requirements.txt<\/code>\u00a0\u5de5\u4f5c\u6d41\uff0c\u5e76\u63d0\u4f9b\u4e86\u00a0<code>pip<\/code>\u00a0\u517c\u5bb9\u7684\u547d\u4ee4\u63a5\u53e3\uff0c\u800c\u4e14\u901f\u5ea6\u66f4\u5feb\u3002<\/p>\n<ul>\n<li><strong>\u5b89\u88c5\u4f9d\u8d56 (<code>uv pip install<\/code>)<\/strong>:\n<pre><code># \u5b89\u88c5\u5355\u4e2a\u5305\r\nuv pip install flask\r\n# \u4ece requirements \u6587\u4ef6\u5b89\u88c5\r\nuv pip install -r requirements.txt\r\n# \u53ef\u4ee5\u540c\u65f6\u6307\u5b9a\u591a\u4e2a\u6587\u4ef6\r\nuv pip install -r requirements.txt -r requirements-dev.txt\r\n# \u5b89\u88c5\u5f53\u524d\u9879\u76ee (\u4ee5\u53ef\u7f16\u8f91\u6a21\u5f0f)\r\nuv pip install -e .\r\n<\/code><\/pre>\n<\/li>\n<li><strong>\u5378\u8f7d\u4f9d\u8d56 (<code>uv pip uninstall<\/code>)<\/strong>:\n<pre><code>uv pip uninstall flask\r\n# \u4ece\u6587\u4ef6\u6279\u91cf\u5378\u8f7d\r\nuv pip uninstall -r requirements-to-remove.txt\r\n<\/code><\/pre>\n<\/li>\n<li><strong>\u751f\u6210\u4f9d\u8d56\u5217\u8868 (<code>uv pip freeze<\/code>)<\/strong>:\n<pre><code># \u8f93\u51fa\u5f53\u524d\u73af\u5883\u5b89\u88c5\u7684\u6240\u6709\u5305 (\u7c7b\u4f3c pip freeze)\r\nuv pip freeze &gt; requirements.lock.txt # \u5e38\u7528\u4e8e\u751f\u6210\u9501\u5b9a\u6587\u4ef6\r\n<\/code><\/pre>\n<\/li>\n<li><strong>\u7f16\u8bd1\u4f9d\u8d56 (<code>uv pip compile<\/code>)<\/strong>\u00a0(\u63a8\u8350\u7684\u00a0<code>requirements<\/code>\u00a0<a href=\"https:\/\/www.kdjingpai.com\/workflow\/\">\u5de5\u4f5c\u6d41<\/a>):<br \/>\n\u8fd9\u79cd\u65b9\u5f0f\u7c7b\u4f3c\u00a0<code>pip-tools<\/code>\u3002\u4f60\u7ef4\u62a4\u4e00\u4e2a\u00a0<code>requirements.in<\/code>\u00a0\u6587\u4ef6\uff08\u53ea\u5305\u542b\u76f4\u63a5\u4f9d\u8d56\uff09\uff0c\u7136\u540e\u7528\u00a0<code>uv<\/code>\u00a0\u751f\u6210\u5305\u542b\u6240\u6709\u95f4\u63a5\u4f9d\u8d56\u548c\u7cbe\u786e\u7248\u672c\u7684\u00a0<code>requirements.txt<\/code>\u00a0\u9501\u5b9a\u6587\u4ef6\u3002<\/p>\n<pre><code># requirements.in \u5185\u5bb9\u793a\u4f8b:\r\n# flask\r\n# requests&gt;=2.25\r\n# \u751f\u6210 requirements.txt\r\nuv pip compile requirements.in -o requirements.txt\r\n# \u4e3a\u5f00\u53d1\u73af\u5883\u7f16\u8bd1 (\u5047\u8bbe\u6709 requirements-dev.in)\r\n# uv pip compile requirements-dev.in -o requirements-dev.txt\r\n<\/code><\/pre>\n<\/li>\n<li><strong>\u540c\u6b65\u73af\u5883 (<code>uv pip sync<\/code>)<\/strong>:<br \/>\n\u6839\u636e\u4e00\u4e2a\u6216\u591a\u4e2a\u00a0<code>requirements.txt<\/code>\u00a0\u6587\u4ef6\u7684\u5185\u5bb9\uff0c\u7cbe\u786e\u540c\u6b65\u865a\u62df\u73af\u5883\uff1a\u5b89\u88c5\u7f3a\u5931\u7684\u5305\uff0c\u79fb\u9664\u591a\u4f59\u7684\u5305\u3002<\/p>\n<pre><code># \u540c\u6b65\u4e3b\u4f9d\u8d56\u548c\u5f00\u53d1\u4f9d\u8d56\r\nuv pip sync requirements.txt requirements-dev.txt\r\n<\/code><\/pre>\n<\/li>\n<li><strong>\u67e5\u770b\u5df2\u5b89\u88c5\u5305 (<code>uv pip list<\/code>,\u00a0<code>uv pip show<\/code>,\u00a0<code>uv pip tree<\/code>)<\/strong>:\n<pre><code>uv pip list          # \u5217\u51fa\u5df2\u5b89\u88c5\u7684\u5305\u548c\u7248\u672c\r\nuv pip show flask    # \u663e\u793a flask \u5305\u7684\u8be6\u7ec6\u4fe1\u606f\r\nuv pip tree          # \u4ee5\u6811\u72b6\u7ed3\u6784\u663e\u793a\u4f9d\u8d56\u5173\u7cfb\r\n<\/code><\/pre>\n<\/li>\n<\/ul>\n<h4>\u7ba1\u7406 Python \u7248\u672c (<code>uv python<\/code>)<\/h4>\n<p><code>uv<\/code>\u00a0\u5185\u5efa\u4e86\u4e0b\u8f7d\u3001\u7ba1\u7406\u548c\u9009\u7528\u00a0<code>Python<\/code>\u00a0\u7248\u672c\u7684\u529f\u80fd\uff0c\u7c7b\u4f3c\u4e8e\u00a0<code>pyenv<\/code>\u3002\uff08\u8bb0\u5f97\u53ef\u4ee5\u901a\u8fc7\u00a0<code>UV_PYTHON_INSTALL_DIR<\/code>\u00a0\u73af\u5883\u53d8\u91cf\u914d\u7f6e\u8fd9\u4e9b\u00a0<code>Python<\/code>\u00a0\u7684\u5b89\u88c5\u4f4d\u7f6e\uff09<\/p>\n<ul>\n<li><strong>\u5217\u51fa\u53ef\u7528\u548c\u5df2\u5b89\u88c5\u7248\u672c (<code>uv python list<\/code>)<\/strong>:\n<pre><code># \u5217\u51fa\u5df2\u5b89\u88c5\u548c\u5f53\u524d\u4f7f\u7528\u7684\u7248\u672c\r\nuv python list\r\n# \u663e\u793a\u6240\u6709\u53ef\u4f9b\u4e0b\u8f7d\u7684\u8865\u4e01\u7248\u672c\r\n# uv python list --all-versions\r\n# \u53ea\u663e\u793a\u5df2\u5b89\u88c5\u7684\u7248\u672c\r\nuv python list --only-installed\r\n<\/code><\/pre>\n<\/li>\n<li><strong>\u5b89\u88c5 Python \u7248\u672c (<code>uv python install<\/code>)<\/strong>:\n<pre><code># \u5b89\u88c5\u6700\u65b0\u7684\u7a33\u5b9a\u7248 (\u5982\u679c\u5c1a\u672a\u5b89\u88c5)\r\nuv python install\r\n# \u5b89\u88c5\u7279\u5b9a\u7248\u672c\r\nuv python install 3.11.5\r\n# \u5b89\u88c5 3.10 \u7cfb\u5217\u7684\u6700\u65b0\u53ef\u7528\u7248\r\nuv python install 3.10\r\n<\/code><\/pre>\n<p><code>uv<\/code>\u00a0\u4f1a\u5c06\u4e0b\u8f7d\u7684\u00a0<code>Python<\/code>\u00a0\u5b89\u88c5\u5230\u5176\u7ba1\u7406\u7684\u76ee\u5f55\u4e2d (<code>uv python dir<\/code>\u00a0\u53ef\u67e5\u770b\u8be5\u8def\u5f84\uff0c\u53d7\u00a0<code>UV_PYTHON_INSTALL_DIR<\/code>\u00a0\u5f71\u54cd)\u3002<\/li>\n<li><strong>\u5378\u8f7d Python \u7248\u672c (<code>uv python uninstall<\/code>)<\/strong>:\n<pre><code>uv python uninstall 3.10.8\r\n# \u5378\u8f7d 3.11 \u7cfb\u5217\u6240\u6709\u5df2\u5b89\u88c5\u7248\u672c\r\nuv python uninstall 3.11\r\n<\/code><\/pre>\n<\/li>\n<li><strong>\u56fa\u5b9a\u9879\u76ee Python \u7248\u672c (<code>uv python pin<\/code>)<\/strong>:<br \/>\n\u5728\u5f53\u524d\u76ee\u5f55\u521b\u5efa\u6216\u66f4\u65b0\u00a0<code>.python-version<\/code>\u00a0\u6587\u4ef6\uff0c\u58f0\u660e\u9879\u76ee\u5e94\u4f7f\u7528\u7684\u00a0<code>Python<\/code>\u00a0\u7248\u672c\u3002<\/p>\n<pre><code>uv python pin 3.11\r\n<\/code><\/pre>\n<p>\u4e4b\u540e\u00a0<code>uv venv<\/code>,\u00a0<code>uv run<\/code>,\u00a0<code>uv sync<\/code>\u00a0\u7b49\u547d\u4ee4\u4f1a\u4f18\u5148\u67e5\u627e\u5e76\u4f7f\u7528\u8fd9\u4e2a\u7248\u672c\u3002<\/li>\n<li><strong>\u67e5\u627e Python \u89e3\u91ca\u5668 (<code>uv python find<\/code>)<\/strong>:\n<pre><code># \u67e5\u627e\u5339\u914d 3.12 \u7684 Python \u89e3\u91ca\u5668\u8def\u5f84\r\nuv python find 3.12\r\n<\/code><\/pre>\n<\/li>\n<\/ul>\n<h4>\u7ba1\u7406\u5168\u5c40\u5de5\u5177 (<code>uv tool<\/code>)<\/h4>\n<p><code>uv<\/code>\u00a0\u53ef\u4ee5\u50cf\u00a0<code>pipx<\/code>\u00a0\u4e00\u6837\uff0c\u5b89\u88c5\u548c\u8fd0\u884c\u5168\u5c40\u00a0<code>Python CLI<\/code>\u00a0\u5de5\u5177\uff0c\u5e76\u5c06\u6bcf\u4e2a\u5de5\u5177\u9694\u79bb\u5728\u72ec\u7acb\u7684\u73af\u5883\u4e2d\uff0c\u907f\u514d\u4f9d\u8d56\u51b2\u7a81\u3002\uff08\u540c\u6837\uff0c\u5de5\u5177\u7684\u5b58\u50a8\u4f4d\u7f6e\u53ef\u901a\u8fc7\u00a0<code>UV_TOOL_INSTALL_DIR<\/code>\u00a0\u73af\u5883\u53d8\u91cf\u914d\u7f6e\uff09<\/p>\n<ul>\n<li><strong>\u8fd0\u884c\u5de5\u5177 (\u4e34\u65f6\u6267\u884c,\u00a0<code>uv tool run<\/code>\u00a0\u6216\u00a0<code>uvx<\/code>)<\/strong>:<br \/>\n\u4e34\u65f6\u4e0b\u8f7d\uff08\u5982\u679c\u9700\u8981\uff09\u5e76\u6267\u884c\u5de5\u5177\uff0c\u6267\u884c\u5b8c\u6bd5\u540e\u4e0d\u4fdd\u7559\u3002\u8fd9\u5bf9\u4e8e\u4e00\u6b21\u6027\u4f7f\u7528\u7684\u5de5\u5177\u975e\u5e38\u65b9\u4fbf\u3002<code>uvx<\/code>\u00a0\u662f\u00a0<code>uv tool run<\/code>\u00a0\u7684\u7b80\u5199\u5f62\u5f0f\u3002<\/p>\n<pre><code># \u8fd0\u884c ruff \u68c0\u67e5\u5f53\u524d\u76ee\u5f55\uff0c\u4e34\u65f6\u4e0b\u8f7d ruff\r\nuv tool run ruff check .\r\n# \u4f7f\u7528\u7b80\u5199 uvx\r\nuvx ruff check .\r\n# \u5982\u679c\u547d\u4ee4\u540d (http) \u548c\u5305\u540d (httpie) \u4e0d\u540c\uff0c\u4f7f\u7528 --from\r\nuvx --from httpie http https:\/\/example.com\r\n<\/code><\/pre>\n<\/li>\n<li><strong>\u5b89\u88c5\u5168\u5c40\u5de5\u5177 (<code>uv tool install<\/code>)<\/strong>:<br \/>\n\u5c06\u5de5\u5177\u53ca\u5176\u4f9d\u8d56\u5b89\u88c5\u5230\u00a0<code>uv<\/code>\u00a0\u7ba1\u7406\u7684\u72ec\u7acb\u73af\u5883\u4e2d\uff0c\u5e76\u5c06\u5176\u53ef\u6267\u884c\u6587\u4ef6\u94fe\u63a5\u5230\u7528\u6237\u8def\u5f84\uff08\u53ef\u80fd\u9700\u8981\u91cd\u542f\u7ec8\u7aef\u6216\u624b\u52a8\u914d\u7f6e\u00a0<code>PATH<\/code>\u00a0\u624d\u80fd\u76f4\u63a5\u8c03\u7528\uff09\u3002\u8fd9\u7c7b\u4f3c\u4e8e\u00a0<code>pipx install<\/code>\u3002<\/p>\n<pre><code>uv tool install black\r\nuv tool install httpie\r\n<\/code><\/pre>\n<p>\u5b89\u88c5\u540e\uff0c\u7406\u8bba\u4e0a\u53ef\u4ee5\u5728\u4efb\u4f55\u5730\u65b9\u76f4\u63a5\u8fd0\u884c\u00a0<code>black .<\/code>\u00a0\u6216\u00a0<code>http https:\/\/example.com<\/code>\u3002<\/li>\n<li><strong>\u5217\u51fa\u5df2\u5b89\u88c5\u5de5\u5177 (<code>uv tool list<\/code>)<\/strong>:\n<pre><code>uv tool list\r\n<\/code><\/pre>\n<\/li>\n<li><strong>\u5347\u7ea7\u5de5\u5177 (<code>uv tool upgrade<\/code>)<\/strong>:\n<pre><code>uv tool upgrade black\r\n# \u5347\u7ea7\u6240\u6709\u5df2\u5b89\u88c5\u5de5\u5177\r\n# uv tool upgrade --all\r\n<\/code><\/pre>\n<\/li>\n<li><strong>\u5378\u8f7d\u5de5\u5177 (<code>uv tool uninstall<\/code>)<\/strong>:\n<pre><code>uv tool uninstall black\r\n<\/code><\/pre>\n<\/li>\n<li><strong>\u67e5\u770b\u5de5\u5177\u5b89\u88c5\u76ee\u5f55 (<code>uv tool dir<\/code>)<\/strong>:<br \/>\n\u663e\u793a\u00a0<code>uv<\/code>\u00a0\u5b58\u653e\u5168\u5c40\u5de5\u5177\u53ca\u5176\u73af\u5883\u7684\u6839\u8def\u5f84 (\u53d7\u00a0<code>UV_TOOL_INSTALL_DIR<\/code>\u00a0\u5f71\u54cd)\u3002<\/li>\n<\/ul>\n<h4>\u7ba1\u7406\u7f13\u5b58 (<code>uv cache<\/code>)<\/h4>\n<p><code>uv<\/code>\u00a0\u4f7f\u7528\u5168\u5c40\u7f13\u5b58\u6765\u52a0\u901f\u5305\u7684\u4e0b\u8f7d\u548c\u6784\u5efa\u8fc7\u7a0b\u3002\uff08\u7f13\u5b58\u4f4d\u7f6e\u53ef\u901a\u8fc7\u00a0<code>UV_CACHE_DIR<\/code>\u00a0\u73af\u5883\u53d8\u91cf\u914d\u7f6e\uff09<\/p>\n<ul>\n<li><strong>\u6e05\u7406\u7f13\u5b58 (<code>uv cache clean<\/code>)<\/strong>:<br \/>\n\u5220\u9664\u6240\u6709\u00a0<code>uv<\/code>\u00a0\u7f13\u5b58\u5185\u5bb9\u3002\u8fd9\u53ef\u4ee5\u7528\u4e8e\u89e3\u51b3\u6f5c\u5728\u7684\u7f13\u5b58\u6c61\u67d3\u95ee\u9898\u6216\u91ca\u653e\u78c1\u76d8\u7a7a\u95f4\u3002<\/p>\n<pre><code>uv cache clean\r\n<\/code><\/pre>\n<\/li>\n<li><strong>\u663e\u793a\u7f13\u5b58\u76ee\u5f55 (<code>uv cache dir<\/code>)<\/strong>:<br \/>\n\u67e5\u770b\u5f53\u524d\u00a0<code>uv<\/code>\u00a0\u7f13\u5b58\u6587\u4ef6\u7684\u5b58\u50a8\u4f4d\u7f6e (\u53d7\u00a0<code>UV_CACHE_DIR<\/code>\u00a0\u5f71\u54cd)\u3002<\/li>\n<\/ul>\n<h4>\u5355\u811a\u672c\u9879\u76ee\u7ba1\u7406<\/h4>\n<p>\u5bf9\u4e8e\u4e00\u4e9b\u7b80\u5355\u7684\u5c0f\u5de5\u5177\u6216\u811a\u672c\uff0c<code>uv<\/code>\u00a0\u652f\u6301\u4e00\u79cd\u975e\u5e38\u8f7b\u91cf\u7ea7\u7684\u7ba1\u7406\u65b9\u5f0f\uff1a\u5c06\u9879\u76ee\u5143\u6570\u636e\u548c\u4f9d\u8d56\u76f4\u63a5\u5d4c\u5165\u00a0<code>Python<\/code>\u00a0\u811a\u672c\u5934\u90e8\u7684\u7279\u6b8a\u6ce8\u91ca\u5757\u4e2d\u3002<\/p>\n<ol>\n<li><strong>\u521d\u59cb\u5316\u811a\u672c (<code>uv init --script<\/code>)<\/strong>:\n<pre><code># \u521b\u5efa\u4e00\u4e2a\u540d\u4e3a my_script.py \u7684\u811a\u672c\uff0c\u5e76\u6307\u5b9a Python \u7248\u672c\u8981\u6c42\r\nuv init --script my_script.py --python \"&gt;=3.10\"\r\n<\/code><\/pre>\n<p>\u8fd9\u4f1a\u5728\u00a0<code>my_script.py<\/code>\u00a0\u6587\u4ef6\u5f00\u5934\u751f\u6210\u7c7b\u4f3c\u4ee5\u4e0b\u7684\u6ce8\u91ca\u5757\uff1a<\/p>\n<pre><code>#!\/usr\/bin\/env python\r\n# \/\/\/ script\r\n# requires-python = \"&gt;=3.10\"\r\n# dependencies = [\r\n# ]\r\n# \/\/\/\r\nimport sys\r\ndef main() -&gt; None:\r\nprint(f\"Hello from {sys.argv[0]}!\")\r\nif __name__ == \"__main__\":\r\nmain()\r\n<\/code><\/pre>\n<\/li>\n<li><strong>\u6dfb\u52a0\/\u79fb\u9664\u811a\u672c\u4f9d\u8d56 (<code>uv add\/remove --script<\/code>)<\/strong>:<br \/>\n\u53ef\u4ee5\u76f4\u63a5\u4f7f\u7528\u00a0<code>add<\/code>\u00a0\u6216\u00a0<code>remove<\/code>\u00a0\u547d\u4ee4\uff0c\u914d\u5408\u00a0<code>--script<\/code>\u00a0\u53c2\u6570\u6765\u4fee\u6539\u811a\u672c\u5934\u90e8\u7684\u4f9d\u8d56\u5217\u8868\u3002<\/p>\n<pre><code># \u4e3a my_script.py \u6dfb\u52a0 requests \u4f9d\u8d56\r\nuv add --script my_script.py requests\r\n# \u4ece my_script.py \u79fb\u9664 requests \u4f9d\u8d56\r\nuv remove --script my_script.py requests\r\n<\/code><\/pre>\n<p>\u8fd9\u4e9b\u547d\u4ee4\u4f1a\u76f4\u63a5\u4fee\u6539\u811a\u672c\u6587\u4ef6\u5934\u90e8\u7684\u00a0<code>dependencies<\/code>\u00a0\u5217\u8868\u3002<\/li>\n<li><strong>\u8fd0\u884c\u811a\u672c (<code>uv run<\/code>)<\/strong>:<br \/>\n\u76f4\u63a5\u4f7f\u7528\u00a0<code>uv run<\/code>\u00a0\u5373\u53ef\u6267\u884c\u8be5\u811a\u672c\u3002<\/p>\n<pre><code>uv run my_script.py\r\n<\/code><\/pre>\n<p><code>uv<\/code>\u00a0\u4f1a\u81ea\u52a8\u8bfb\u53d6\u811a\u672c\u5934\u90e8\u7684\u5143\u6570\u636e\uff0c\u6309\u9700\u521b\u5efa\u4e34\u65f6\u7684\u865a\u62df\u73af\u5883\uff0c\u5b89\u88c5\u5176\u4e2d\u58f0\u660e\u7684\u4f9d\u8d56\uff0c\u7136\u540e\u6267\u884c\u811a\u672c\u3002\u8fd9\u79cd\u65b9\u5f0f\u975e\u5e38\u9002\u5408\u5206\u53d1\u5355\u4e2a\u3001\u81ea\u5305\u542b\u7684\u00a0<code>Python<\/code>\u00a0\u5de5\u5177\u811a\u672c\u3002<\/li>\n<\/ol>\n<h3>\u672a\u6765\u5c55\u671b\u4e0e\u5efa\u8bae<\/h3>\n<p><code>uv<\/code>\u00a0\u65e0\u7591\u662f\u4e00\u4e2a\u96c4\u5fc3\u52c3\u52c3\u4e14\u53d1\u5c55\u6781\u5176\u8fc5\u901f\u7684\u9879\u76ee\u3002\u5b83\u501f\u52a9\u00a0<code>Rust<\/code>\u00a0\u5e26\u6765\u7684\u6027\u80fd\u4f18\u52bf\u548c\u7cbe\u5fc3\u8bbe\u8ba1\u7684\u7edf\u4e00\u63a5\u53e3\uff0c\u6709\u671b\u663e\u8457\u6539\u5584\u00a0<code>Python<\/code>\u00a0\u5f00\u53d1\u8005\u7684\u5305\u4e0e\u73af\u5883\u7ba1\u7406\u4f53\u9a8c\u3002\u5176\u6838\u5fc3\u4ef7\u503c\u5728\u4e8e<strong>\u901f\u5ea6<\/strong>\u548c<strong>\u6574\u5408<\/strong>\u3002<\/p>\n<p>\u5c3d\u7ba1\u00a0<code>uv<\/code>\u00a0\u76f8\u5bf9\u5e74\u8f7b\uff0c\u751f\u6001\u7cfb\u7edf\uff08\u5982 IDE \u6df1\u5ea6\u96c6\u6210\u3001\u7b2c\u4e09\u65b9\u6559\u7a0b\u8d44\u6e90\uff09\u4ecd\u5728\u5feb\u901f\u6210\u957f\u4e2d\uff0c\u5e76\u4e14\u7531\u4e8e\u5176\u6d3b\u8dc3\u7684\u8fed\u4ee3\uff0c\u547d\u4ee4\u6216\u884c\u4e3a\u53ef\u80fd\u5728\u7248\u672c\u95f4\u6709\u7ec6\u5fae\u8c03\u6574\uff08\u5efa\u8bae\u5173\u6ce8\u5176\u66f4\u65b0\u65e5\u5fd7\uff09\u3002<\/p>\n<p>\u4f46\u5c31\u76ee\u524d\u800c\u8a00\uff0c<code>uv<\/code>\u00a0\u7684\u6838\u5fc3\u529f\u80fd\u5df2\u7ecf\u76f8\u5f53\u7a33\u5b9a\u548c\u5f3a\u5927\u3002<\/p>\n<p><strong>\u5efa\u8bae<\/strong>:<\/p>\n<ul>\n<li>\u5bf9\u4e8e<strong>\u65b0\u542f\u52a8\u7684\u00a0<code>Python<\/code>\u00a0\u9879\u76ee<\/strong>\uff0c\u5f3a\u70c8\u63a8\u8350\u76f4\u63a5\u91c7\u7528\u00a0<code>uv<\/code>\u3002\u5b83\u80fd\u4ece\u4e00\u5f00\u59cb\u5c31\u5e26\u6765\u6e05\u723d\u3001\u9ad8\u6548\u7684\u7ba1\u7406\u4f53\u9a8c\u3002<\/li>\n<li>\u5bf9\u4e8e\u90a3\u4e9b<strong>\u9971\u53d7\u73b0\u6709\u5de5\u5177\u94fe\uff08\u5982\u00a0<code>pip<\/code>\u00a0+\u00a0<code>virtualenv<\/code>\u00a0+\u00a0<code>pip-tools<\/code>\u00a0\u7ec4\u5408\uff09\u590d\u6742\u6027\u6216\u6027\u80fd\u95ee\u9898\u56f0\u6270<\/strong>\u7684\u5f00\u53d1\u8005\u548c\u56e2\u961f\uff0c<code>uv<\/code>\u00a0\u662f\u4e00\u4e2a\u975e\u5e38\u6709\u5438\u5f15\u529b\u7684\u66ff\u4ee3\u65b9\u6848\uff0c\u503c\u5f97\u6295\u5165\u65f6\u95f4\u8fdb\u884c\u8bc4\u4f30\u548c\u8fc1\u79fb\u5c1d\u8bd5\u3002<\/li>\n<li>\u5bf9\u4e8e\u5df2\u7ecf\u6df1\u5ea6\u4f7f\u7528\u00a0<code>Poetry<\/code>\u00a0\u6216\u00a0<code>PDM<\/code>\u00a0\u5e76\u4f9d\u8d56\u5176\u7279\u5b9a\u9ad8\u7ea7\u529f\u80fd\uff08\u4f8b\u5982\u590d\u6742\u7684\u63d2\u4ef6\u7cfb\u7edf\u3001\u7cbe\u7ec6\u7684\u53d1\u5e03\u6d41\u7a0b\u7ba1\u7406\uff09\u7684\u6210\u719f\u9879\u76ee\uff0c\u8fc1\u79fb\u53ef\u80fd\u9700\u8981\u66f4\u4ed4\u7ec6\u7684\u8bc4\u4f30\uff0c\u6743\u8861\u00a0<code>uv<\/code>\u00a0\u5e26\u6765\u7684\u901f\u5ea6\u548c\u7b80\u6d01\u6027\u4e0e\u53ef\u80fd\u5931\u53bb\u7684\u7279\u5b9a\u529f\u80fd\u3002<\/li>\n<\/ul>\n<p><code>uv<\/code>\u00a0\u6b63\u5728\u5feb\u901f\u6210\u4e3a\u00a0<code>Python<\/code>\u00a0\u5f00\u53d1\u5de5\u4f5c\u6d41\u4e2d\u4e00\u4e2a\u4e0d\u53ef\u5ffd\u89c6\u7684\u529b\u91cf\uff0c\u5b83\u7684\u51fa\u73b0\u53ef\u80fd\u4f1a\u50cf\u00a0<code>ruff<\/code>\u00a0\u4e00\u6837\uff0c\u5728\u00a0<code>Python<\/code>\u00a0\u793e\u533a\u5f15\u53d1\u65b0\u4e00\u8f6e\u7684\u5de5\u5177\u9769\u65b0\u3002\u5b83\u7684\u672a\u6765\u503c\u5f97\u6211\u4eec\u6301\u7eed\u5173\u6ce8\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Python\u00a0\u751f\u6001\u5411\u6765\u4e0d\u7f3a\u5305\u7ba1\u7406\u548c\u73af\u5883\u7ba1\u7406\u5de5\u5177\uff0c\u4ece\u7ecf\u5178\u7684\u00a0pip\u3001virtualenv\u00a0\u5230\u00a0pip-tools\u3001conda\uff0c\u518d\u5230\u73b0\u4ee3\u5316\u7684\u00a0Poetry\u3001PDM\u00a0\u7b49\u7b49\u3002\u6bcf\u79cd\u5de5\u5177\u90fd\u6709\u5176\u64c5\u957f\u7684\u9886\u57df\uff0c\u4f46\u4e5f\u5e38\u5e38\u8ba9\u5f00\u53d1\u8005\u7684\u5de5\u5177\u94fe\u53d8\u5f97\u96f6\u6563\u548c\u590d\u6742\u3002 \u73b0\u5728\uff0c&#8230;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[182,34],"tags":[],"class_list":["post-29563","post","type-post","status-publish","format-standard","hentry","category-shicao","category-knowledge"],"_links":{"self":[{"href":"https:\/\/www.kdjingpai.com\/ja\/wp-json\/wp\/v2\/posts\/29563","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.kdjingpai.com\/ja\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.kdjingpai.com\/ja\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.kdjingpai.com\/ja\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.kdjingpai.com\/ja\/wp-json\/wp\/v2\/comments?post=29563"}],"version-history":[{"count":0,"href":"https:\/\/www.kdjingpai.com\/ja\/wp-json\/wp\/v2\/posts\/29563\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.kdjingpai.com\/ja\/wp-json\/wp\/v2\/media?parent=29563"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.kdjingpai.com\/ja\/wp-json\/wp\/v2\/categories?post=29563"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.kdjingpai.com\/ja\/wp-json\/wp\/v2\/tags?post=29563"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}