{"id":924,"date":"2025-12-24T10:55:05","date_gmt":"2025-12-24T02:55:05","guid":{"rendered":"https:\/\/www.52runoob.com\/?p=924"},"modified":"2025-12-24T10:55:05","modified_gmt":"2025-12-24T02:55:05","slug":"%e4%bd%bf%e7%94%a8poetry%e8%bf%9b%e8%a1%8cpython%e4%be%9d%e8%b5%96%e5%92%8c%e5%8c%85%e7%ae%a1%e7%90%86","status":"publish","type":"post","link":"https:\/\/www.52runoob.com\/index.php\/2025\/12\/24\/%e4%bd%bf%e7%94%a8poetry%e8%bf%9b%e8%a1%8cpython%e4%be%9d%e8%b5%96%e5%92%8c%e5%8c%85%e7%ae%a1%e7%90%86\/","title":{"rendered":"\u4f7f\u7528Poetry\u8fdb\u884cpython\u4f9d\u8d56\u548c\u5305\u7ba1\u7406"},"content":{"rendered":"\n<p>\u597d\u7684\uff0c\u6211\u6765\u7ed9\u4f60\u6574\u7406\u4e00\u4efd <strong>Python \u4f7f\u7528 Poetry \u8fdb\u884c\u4f9d\u8d56\u548c\u5305\u7ba1\u7406\u7684\u5b8c\u6574\u6307\u5357<\/strong>\uff0c\u6db5\u76d6\u5b89\u88c5\u3001\u521d\u59cb\u5316\u3001\u4f9d\u8d56\u7ba1\u7406\u3001\u6253\u5305\u53d1\u5e03\u7b49\u5185\u5bb9\uff0c\u4fbf\u4e8e\u9879\u76ee\u89c4\u8303\u5316\u7ba1\u7406\u3002<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h1 class=\"wp-block-heading\">\u4f7f\u7528 Poetry \u8fdb\u884c Python \u4f9d\u8d56\u548c\u5305\u7ba1\u7406<\/h1>\n\n\n\n<h2 class=\"wp-block-heading\">1\ufe0f\u20e3 Poetry \u7b80\u4ecb<\/h2>\n\n\n\n<p>Poetry \u662f Python \u7684\u73b0\u4ee3\u4f9d\u8d56\u7ba1\u7406\u548c\u6253\u5305\u5de5\u5177\uff0c\u7279\u70b9\uff1a<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u81ea\u52a8\u7ba1\u7406\u4f9d\u8d56\u7248\u672c\uff0c\u907f\u514d\u51b2\u7a81<\/li>\n\n\n\n<li>\u652f\u6301\u865a\u62df\u73af\u5883\u81ea\u52a8\u521b\u5efa\u548c\u7ba1\u7406<\/li>\n\n\n\n<li>\u4e00\u6761\u547d\u4ee4\u5373\u53ef\u6253\u5305\u548c\u53d1\u5e03 Python \u5305<\/li>\n\n\n\n<li>\u4f7f\u7528 <code>pyproject.toml<\/code> \u7edf\u4e00\u9879\u76ee\u914d\u7f6e<\/li>\n<\/ul>\n\n\n\n<p>Poetry \u66ff\u4ee3\u4e86 <code>requirements.txt<\/code> + <code>setup.py<\/code> \u7684\u7ec4\u5408\uff0c\u4f7f\u9879\u76ee\u7ba1\u7406\u66f4\u6e05\u6670\u3002<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">2\ufe0f\u20e3 \u5b89\u88c5 Poetry<\/h2>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>Linux \/ macOS<\/strong><\/h3>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\ncurl -sSL https:\/\/install.python-poetry.org | python3 -\n\n<\/pre><\/div>\n\n\n<h3 class=\"wp-block-heading\"><strong>Windows<\/strong><\/h3>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u4f7f\u7528 PowerShell\uff1a<\/li>\n<\/ul>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\n(Invoke-WebRequest -Uri https:\/\/install.python-poetry.org -UseBasicParsing).Content | python -\n\n<\/pre><\/div>\n\n\n<h3 class=\"wp-block-heading\"><strong>\u9a8c\u8bc1\u5b89\u88c5<\/strong><\/h3>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\npoetry --version\n\n<\/pre><\/div>\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">3\ufe0f\u20e3 \u521d\u59cb\u5316\u9879\u76ee<\/h2>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>\u65b0\u5efa\u9879\u76ee<\/strong><\/h3>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\npoetry new my_project\n# \u751f\u6210\u76ee\u5f55\u7ed3\u6784\uff1a\n# my_project\/\n# \u251c\u2500\u2500 pyproject.toml\n# \u251c\u2500\u2500 README.rst\n# \u251c\u2500\u2500 my_project\/\n# \u2502   \u2514\u2500\u2500 __init__.py\n# \u2514\u2500\u2500 tests\/\n#     \u2514\u2500\u2500 __init__.py\n\n<\/pre><\/div>\n\n\n<h3 class=\"wp-block-heading\"><strong>\u5df2\u6709\u9879\u76ee<\/strong><\/h3>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\ncd existing_project\npoetry init\n# \u6309\u63d0\u793a\u751f\u6210 pyproject.toml\n\n<\/pre><\/div>\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">4\ufe0f\u20e3 \u7ba1\u7406\u865a\u62df\u73af\u5883<\/h2>\n\n\n\n<p>Poetry \u4f1a\u81ea\u52a8\u521b\u5efa\u865a\u62df\u73af\u5883\uff1a<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\npoetry shell      # \u8fdb\u5165\u865a\u62df\u73af\u5883\npoetry env list    # \u67e5\u770b\u865a\u62df\u73af\u5883\npoetry env remove python3.11 # \u5220\u9664\u6307\u5b9a\u73af\u5883\n\n<\/pre><\/div>\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p>\u4e0d\u60f3\u4f7f\u7528 Poetry \u7ba1\u7406\u7684\u865a\u62df\u73af\u5883\uff0c\u53ef\u5173\u95ed\uff1a<\/p>\n<\/blockquote>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\npoetry config virtualenvs.create false\n\n<\/pre><\/div>\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">5\ufe0f\u20e3 \u6dfb\u52a0 \/ \u79fb\u9664\u4f9d\u8d56<\/h2>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>\u6dfb\u52a0\u4f9d\u8d56<\/strong><\/h3>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\npoetry add requests        # \u6dfb\u52a0\u751f\u4ea7\u4f9d\u8d56\npoetry add pytest --dev    # \u6dfb\u52a0\u5f00\u53d1\u4f9d\u8d56\npoetry add numpy@^1.26     # \u6307\u5b9a\u7248\u672c\u4f9d\u8d56\n\n<\/pre><\/div>\n\n\n<h3 class=\"wp-block-heading\"><strong>\u79fb\u9664\u4f9d\u8d56<\/strong><\/h3>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\npoetry remove requests\n\n<\/pre><\/div>\n\n\n<h3 class=\"wp-block-heading\"><strong>\u66f4\u65b0\u4f9d\u8d56<\/strong><\/h3>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\npoetry update              # \u66f4\u65b0\u6240\u6709\u4f9d\u8d56\npoetry update requests     # \u66f4\u65b0\u6307\u5b9a\u4f9d\u8d56\n\n<\/pre><\/div>\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">6\ufe0f\u20e3 \u5b89\u88c5\u4f9d\u8d56<\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>\u4ece <code>pyproject.toml<\/code> \u5b89\u88c5\u4f9d\u8d56<\/strong><\/li>\n<\/ul>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\npoetry install\n\n<\/pre><\/div>\n\n\n<ul class=\"wp-block-list\">\n<li>\u4f1a\u81ea\u52a8\u521b\u5efa\u865a\u62df\u73af\u5883\u5e76\u5b89\u88c5\u6240\u6709\u4f9d\u8d56<\/li>\n<\/ul>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">7\ufe0f\u20e3 \u67e5\u770b\u4f9d\u8d56\u4fe1\u606f<\/h2>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\npoetry show                # \u5217\u51fa\u6240\u6709\u4f9d\u8d56\npoetry show requests --tree # \u67e5\u770b\u4f9d\u8d56\u6811\n\n<\/pre><\/div>\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">8\ufe0f\u20e3 \u4f7f\u7528\u4f9d\u8d56\u8fd0\u884c\u811a\u672c<\/h2>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\npoetry run python main.py\npoetry run pytest tests\/\n\n<\/pre><\/div>\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p>\u4e0d\u9700\u8981\u6fc0\u6d3b\u865a\u62df\u73af\u5883\u5373\u53ef\u8fd0\u884c\u9879\u76ee\u5185\u547d\u4ee4<\/p>\n<\/blockquote>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">9\ufe0f\u20e3 \u6253\u5305\u4e0e\u53d1\u5e03<\/h2>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>\u6253\u5305<\/strong><\/h3>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\npoetry build\n# \u751f\u6210 dist\/ \u6587\u4ef6\u5939\uff0c\u5305\u542b .tar.gz \u548c .whl\n\n<\/pre><\/div>\n\n\n<h3 class=\"wp-block-heading\"><strong>\u53d1\u5e03\u5230 PyPI<\/strong><\/h3>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\npoetry publish --username &amp;lt;username&gt; --password &amp;lt;password&gt;\n\n<\/pre><\/div>\n\n\n<h3 class=\"wp-block-heading\"><strong>\u79c1\u6709\u4ed3\u5e93<\/strong><\/h3>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\npoetry config repositories.myrepo https:\/\/myrepo.example.com\/simple\npoetry publish -r myrepo\n\n<\/pre><\/div>\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">10\ufe0f\u20e3 \u9ad8\u7ea7\u6280\u5de7<\/h2>\n\n\n\n<ol class=\"wp-block-list\">\n<li><strong>\u9501\u5b9a\u4f9d\u8d56\u7248\u672c<\/strong><\/li>\n<\/ol>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\npoetry lock    # \u751f\u6210 poetry.lock\n\n<\/pre><\/div>\n\n\n<ul class=\"wp-block-list\">\n<li>lock \u6587\u4ef6\u53ef\u4fdd\u8bc1\u56e2\u961f\u4f7f\u7528\u76f8\u540c\u7248\u672c<\/li>\n<\/ul>\n\n\n\n<ol start=\"2\" class=\"wp-block-list\">\n<li><strong>\u4f7f\u7528\u4e0d\u540c Python \u7248\u672c<\/strong><\/li>\n<\/ol>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\npoetry env use python3.10\n\n<\/pre><\/div>\n\n\n<ol start=\"3\" class=\"wp-block-list\">\n<li><strong>\u5bfc\u51fa <code>requirements.txt<\/code><\/strong><\/li>\n<\/ol>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\npoetry export -f requirements.txt --output requirements.txt\n\n<\/pre><\/div>\n\n\n<ol start=\"4\" class=\"wp-block-list\">\n<li><strong>\u7ba1\u7406\u591a\u4e2a\u4f9d\u8d56\u7ec4<\/strong><\/li>\n<\/ol>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\npoetry add black --group dev\npoetry install --with dev\n\n<\/pre><\/div>\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">11\ufe0f\u20e3 \u9879\u76ee\u63a8\u8350\u7ed3\u6784\uff08Poetry\uff09<\/h2>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\nmy_project\/\n\u251c\u2500\u2500 pyproject.toml       # Poetry \u914d\u7f6e\n\u251c\u2500\u2500 poetry.lock          # \u9501\u5b9a\u4f9d\u8d56\u7248\u672c\n\u251c\u2500\u2500 README.md\n\u251c\u2500\u2500 my_project\/\n\u2502   \u251c\u2500\u2500 __init__.py\n\u2502   \u2514\u2500\u2500 main.py\n\u2514\u2500\u2500 tests\/\n    \u251c\u2500\u2500 __init__.py\n    \u2514\u2500\u2500 test_main.py\n\n<\/pre><\/div>\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p>\u5efa\u8bae\u5728\u56e2\u961f\u4e2d <strong>\u7edf\u4e00\u4f7f\u7528 Poetry \u7ba1\u7406\u865a\u62df\u73af\u5883\u548c\u4f9d\u8d56<\/strong>\uff0c\u907f\u514d <code>pip freeze<\/code> \u5bfc\u81f4\u7684\u7248\u672c\u51b2\u7a81\u3002<\/p>\n<\/blockquote>\n","protected":false},"excerpt":{"rendered":"<p>\u597d\u7684\uff0c\u6211\u6765\u7ed9\u4f60\u6574\u7406\u4e00\u4efd Python \u4f7f\u7528 Poetry \u8fdb\u884c\u4f9d\u8d56\u548c\u5305\u7ba1\u7406\u7684\u5b8c\u6574&#8230; <a class=\"more-link\" href=\"https:\/\/www.52runoob.com\/index.php\/2025\/12\/24\/%e4%bd%bf%e7%94%a8poetry%e8%bf%9b%e8%a1%8cpython%e4%be%9d%e8%b5%96%e5%92%8c%e5%8c%85%e7%ae%a1%e7%90%86\/\">Continue Reading &rarr;<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[12],"tags":[],"class_list":["post-924","post","type-post","status-publish","format-standard","hentry","category-12"],"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/www.52runoob.com\/index.php\/wp-json\/wp\/v2\/posts\/924","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.52runoob.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.52runoob.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.52runoob.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.52runoob.com\/index.php\/wp-json\/wp\/v2\/comments?post=924"}],"version-history":[{"count":1,"href":"https:\/\/www.52runoob.com\/index.php\/wp-json\/wp\/v2\/posts\/924\/revisions"}],"predecessor-version":[{"id":925,"href":"https:\/\/www.52runoob.com\/index.php\/wp-json\/wp\/v2\/posts\/924\/revisions\/925"}],"wp:attachment":[{"href":"https:\/\/www.52runoob.com\/index.php\/wp-json\/wp\/v2\/media?parent=924"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.52runoob.com\/index.php\/wp-json\/wp\/v2\/categories?post=924"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.52runoob.com\/index.php\/wp-json\/wp\/v2\/tags?post=924"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}