{"id":1179232,"date":"2025-01-15T18:20:49","date_gmt":"2025-01-15T10:20:49","guid":{"rendered":"https:\/\/docs.pingcode.com\/ask\/ask-ask\/1179232.html"},"modified":"2025-01-15T18:20:55","modified_gmt":"2025-01-15T10:20:55","slug":"%e5%a6%82%e4%bd%95%e6%9f%a5%e7%9c%8bpython%e4%b8%ad%e7%9a%84%e5%ba%93-2","status":"publish","type":"post","link":"https:\/\/docs.pingcode.com\/ask\/1179232.html","title":{"rendered":"\u5982\u4f55\u67e5\u770bpython\u4e2d\u7684\u5e93"},"content":{"rendered":"<p style=\"text-align:center;\" ><img decoding=\"async\" src=\"https:\/\/cdn-kb.worktile.com\/kb\/wp-content\/uploads\/2024\/04\/25113715\/c456f04e-2358-449d-a889-f5d553899072.webp\" alt=\"\u5982\u4f55\u67e5\u770bpython\u4e2d\u7684\u5e93\" \/><\/p>\n<p><p> <strong>\u5728Python\u4e2d\u67e5\u770b\u5e93\u53ef\u4ee5\u901a\u8fc7\u4ee5\u4e0b\u51e0\u79cd\u65b9\u6cd5\uff1a\u4f7f\u7528pip\u547d\u4ee4\u3001\u4f7f\u7528Python\u5185\u7f6e\u51fd\u6570\u3001\u901a\u8fc7Python\u4ea4\u4e92\u5f0f\u89e3\u91ca\u5668\u3001\u67e5\u770b\u73af\u5883\u914d\u7f6e\u6587\u4ef6\u3002<\/strong> <strong>\u4f7f\u7528pip\u547d\u4ee4<\/strong>\u662f\u6700\u5e38\u7528\u4e14\u6700\u65b9\u4fbf\u7684\u65b9\u6cd5\u4e4b\u4e00\uff0c\u53ef\u4ee5\u76f4\u63a5\u5728\u7ec8\u7aef\u6216\u547d\u4ee4\u884c\u4e2d\u4f7f\u7528\u3002\u8fd9\u4e9b\u65b9\u6cd5\u80fd\u591f\u5e2e\u52a9\u4f60\u5feb\u901f\u4e86\u89e3\u5f53\u524dPython\u73af\u5883\u4e2d\u5df2\u7ecf\u5b89\u88c5\u7684\u5e93\uff0c\u5e76\u4e14\u53ef\u4ee5\u8fdb\u4e00\u6b65\u67e5\u770b\u6bcf\u4e2a\u5e93\u7684\u8be6\u7ec6\u4fe1\u606f\u3002<\/p>\n<\/p>\n<p><h3>\u4e00\u3001\u4f7f\u7528pip\u547d\u4ee4<\/h3>\n<\/p>\n<p><p>\u4f7f\u7528pip\u547d\u4ee4\u662f\u67e5\u770bPython\u5e93\u6700\u5e38\u7528\u7684\u65b9\u6cd5\u4e4b\u4e00\u3002Pip\u662fPython\u7684\u5305\u7ba1\u7406\u5de5\u5177\uff0c\u53ef\u4ee5\u65b9\u4fbf\u5730\u5b89\u88c5\u548c\u7ba1\u7406Python\u5e93\u3002\u4ee5\u4e0b\u662f\u4e00\u4e9b\u5e38\u7528\u7684pip\u547d\u4ee4\uff1a<\/p>\n<\/p>\n<ol>\n<li>\n<p><strong>\u5217\u51fa\u5df2\u5b89\u88c5\u7684\u5e93<\/strong><\/p>\n<\/p>\n<p><p>\u53ef\u4ee5\u4f7f\u7528<code>pip list<\/code>\u547d\u4ee4\u6765\u5217\u51fa\u5f53\u524d\u73af\u5883\u4e2d\u5df2\u7ecf\u5b89\u88c5\u7684\u6240\u6709Python\u5e93\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">pip list<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u8be5\u547d\u4ee4\u5c06\u8f93\u51fa\u4e00\u4e2a\u5df2\u5b89\u88c5\u5e93\u7684\u5217\u8868\uff0c\u5305\u62ec\u5e93\u7684\u540d\u79f0\u548c\u7248\u672c\u53f7\u3002\u8f93\u51fa\u793a\u4f8b\u5982\u4e0b\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">Package         Version<\/p>\n<p>--------------- -------<\/p>\n<p>numpy           1.21.0<\/p>\n<p>pandas          1.3.0<\/p>\n<p>matplotlib      3.4.2<\/p>\n<p><\/code><\/pre>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u67e5\u627e\u7279\u5b9a\u5e93<\/strong><\/p>\n<\/p>\n<p><p>\u5982\u679c\u4f60\u53ea\u60f3\u67e5\u627e\u67d0\u4e2a\u7279\u5b9a\u5e93\u662f\u5426\u5df2\u7ecf\u5b89\u88c5\uff0c\u53ef\u4ee5\u4f7f\u7528<code>pip show<\/code>\u547d\u4ee4\uff0c\u6307\u5b9a\u5e93\u7684\u540d\u79f0\uff0c\u4f8b\u5982\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">pip show numpy<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u8be5\u547d\u4ee4\u5c06\u663e\u793a\u8be5\u5e93\u7684\u8be6\u7ec6\u4fe1\u606f\uff0c\u5305\u62ec\u7248\u672c\u53f7\u3001\u5b89\u88c5\u4f4d\u7f6e\u3001\u4f9d\u8d56\u5173\u7cfb\u7b49\u3002\u8f93\u51fa\u793a\u4f8b\u5982\u4e0b\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">Name: numpy<\/p>\n<p>Version: 1.21.0<\/p>\n<p>Summary: NumPy is the fundamental package for array computing with Python.<\/p>\n<p>Home-page: https:\/\/numpy.org\/<\/p>\n<p>Author: Travis E. Oliphant et al.<\/p>\n<p>License: BSD<\/p>\n<p>Location: \/usr\/local\/lib\/python3.9\/site-packages<\/p>\n<p>Requires: <\/p>\n<p>Required-by: pandas, matplotlib<\/p>\n<p><\/code><\/pre>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u67e5\u770b\u8fc7\u65f6\u7684\u5e93<\/strong><\/p>\n<\/p>\n<p><p>\u53ef\u4ee5\u4f7f\u7528<code>pip list --outdated<\/code>\u547d\u4ee4\u6765\u67e5\u770b\u54ea\u4e9b\u5e93\u6709\u66f4\u65b0\u7248\u672c\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">pip list --outdated<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u8be5\u547d\u4ee4\u5c06\u5217\u51fa\u6240\u6709\u5df2\u5b89\u88c5\u4f46\u6709\u66f4\u65b0\u7248\u672c\u7684\u5e93\uff0c\u8f93\u51fa\u793a\u4f8b\u5982\u4e0b\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">Package    Version   Latest   Type<\/p>\n<p>---------- --------- -------- -----<\/p>\n<p>numpy      1.21.0    1.21.1   wheel<\/p>\n<p>pandas     1.3.0     1.3.1    wheel<\/p>\n<p><\/code><\/pre>\n<\/p>\n<\/li>\n<\/ol>\n<p><h3>\u4e8c\u3001\u4f7f\u7528Python\u5185\u7f6e\u51fd\u6570<\/h3>\n<\/p>\n<p><p>\u9664\u4e86\u4f7f\u7528pip\u547d\u4ee4\u5916\uff0c\u8fd8\u53ef\u4ee5\u4f7f\u7528Python\u5185\u7f6e\u51fd\u6570\u6765\u67e5\u770b\u5df2\u5b89\u88c5\u7684\u5e93\u3002\u8fd9\u79cd\u65b9\u6cd5\u9002\u7528\u4e8e\u5728\u4ee3\u7801\u4e2d\u52a8\u6001\u83b7\u53d6\u5e93\u4fe1\u606f\u3002<\/p>\n<\/p>\n<ol>\n<li>\n<p><strong>\u4f7f\u7528pkg_resources\u6a21\u5757<\/strong><\/p>\n<\/p>\n<p><p><code>pkg_resources<\/code>\u662fsetuptools\u5e93\u7684\u4e00\u90e8\u5206\uff0c\u53ef\u4ee5\u7528\u6765\u83b7\u53d6\u5df2\u5b89\u88c5\u5e93\u7684\u4fe1\u606f\u3002\u4ee5\u4e0b\u662f\u4e00\u4e2a\u793a\u4f8b\u4ee3\u7801\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import pkg_resources<\/p>\n<p>installed_packages = pkg_resources.working_set<\/p>\n<p>installed_packages_list = sorted([&quot;%s==%s&quot; % (i.key, i.version) for i in installed_packages])<\/p>\n<p>for package in installed_packages_list:<\/p>\n<p>    print(package)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u8be5\u4ee3\u7801\u5c06\u8f93\u51fa\u4e00\u4e2a\u5df2\u5b89\u88c5\u5e93\u7684\u5217\u8868\uff0c\u5305\u62ec\u5e93\u7684\u540d\u79f0\u548c\u7248\u672c\u53f7\u3002<\/p>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u4f7f\u7528importlib.metadata\u6a21\u5757<\/strong><\/p>\n<\/p>\n<p><p>\u4ecePython 3.8\u5f00\u59cb\uff0c\u53ef\u4ee5\u4f7f\u7528<code>importlib.metadata<\/code>\u6a21\u5757\u6765\u83b7\u53d6\u5df2\u5b89\u88c5\u5e93\u7684\u4fe1\u606f\u3002\u4ee5\u4e0b\u662f\u4e00\u4e2a\u793a\u4f8b\u4ee3\u7801\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import importlib.metadata<\/p>\n<p>installed_packages = importlib.metadata.distributions()<\/p>\n<p>for package in installed_packages:<\/p>\n<p>    print(package.metadata[&#39;Name&#39;], package.version)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u8be5\u4ee3\u7801\u5c06\u8f93\u51fa\u4e00\u4e2a\u5df2\u5b89\u88c5\u5e93\u7684\u5217\u8868\uff0c\u5305\u62ec\u5e93\u7684\u540d\u79f0\u548c\u7248\u672c\u53f7\u3002<\/p>\n<\/p>\n<\/li>\n<\/ol>\n<p><h3>\u4e09\u3001\u901a\u8fc7Python\u4ea4\u4e92\u5f0f\u89e3\u91ca\u5668<\/h3>\n<\/p>\n<p><p>\u5728Python\u4ea4\u4e92\u5f0f\u89e3\u91ca\u5668\u4e2d\uff0c\u53ef\u4ee5\u4f7f\u7528<code>help()<\/code>\u51fd\u6570\u6765\u67e5\u770b\u5df2\u5b89\u88c5\u5e93\u7684\u4fe1\u606f\u3002\u4ee5\u4e0b\u662f\u4e00\u4e9b\u5e38\u7528\u7684\u65b9\u6cd5\uff1a<\/p>\n<\/p>\n<ol>\n<li>\n<p><strong>\u67e5\u770b\u5df2\u5b89\u88c5\u5e93\u7684\u6a21\u5757\u5217\u8868<\/strong><\/p>\n<\/p>\n<p><p>\u53ef\u4ee5\u4f7f\u7528<code>help(&#39;modules&#39;)<\/code>\u547d\u4ee4\u6765\u5217\u51fa\u5f53\u524d\u73af\u5883\u4e2d\u6240\u6709\u5df2\u5b89\u88c5\u7684\u6a21\u5757\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">help(&#39;modules&#39;)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u8be5\u547d\u4ee4\u5c06\u8f93\u51fa\u4e00\u4e2a\u5df2\u5b89\u88c5\u6a21\u5757\u7684\u5217\u8868\u3002<\/p>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u67e5\u770b\u7279\u5b9a\u6a21\u5757\u7684\u4fe1\u606f<\/strong><\/p>\n<\/p>\n<p><p>\u5982\u679c\u4f60\u60f3\u67e5\u770b\u67d0\u4e2a\u7279\u5b9a\u6a21\u5757\u7684\u8be6\u7ec6\u4fe1\u606f\uff0c\u53ef\u4ee5\u4f7f\u7528<code>help(module_name)<\/code>\u547d\u4ee4\uff0c\u6307\u5b9a\u6a21\u5757\u7684\u540d\u79f0\uff0c\u4f8b\u5982\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import numpy<\/p>\n<p>help(numpy)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u8be5\u547d\u4ee4\u5c06\u663e\u793a\u8be5\u6a21\u5757\u7684\u8be6\u7ec6\u4fe1\u606f\uff0c\u5305\u62ec\u51fd\u6570\u3001\u7c7b\u3001\u5c5e\u6027\u7b49\u3002<\/p>\n<\/p>\n<\/li>\n<\/ol>\n<p><h3>\u56db\u3001\u67e5\u770b\u73af\u5883\u914d\u7f6e\u6587\u4ef6<\/h3>\n<\/p>\n<p><p>\u5728\u67d0\u4e9b\u60c5\u51b5\u4e0b\uff0c\u4f60\u53ef\u80fd\u9700\u8981\u67e5\u770bPython\u73af\u5883\u7684\u914d\u7f6e\u6587\u4ef6\u6765\u4e86\u89e3\u5df2\u5b89\u88c5\u7684\u5e93\u3002\u4ee5\u4e0b\u662f\u4e00\u4e9b\u5e38\u7528\u7684\u65b9\u6cd5\uff1a<\/p>\n<\/p>\n<ol>\n<li>\n<p><strong>\u67e5\u770brequirements.txt\u6587\u4ef6<\/strong><\/p>\n<\/p>\n<p><p>\u5728\u9879\u76ee\u4e2d\uff0c\u901a\u5e38\u4f1a\u4f7f\u7528<code>requirements.txt<\/code>\u6587\u4ef6\u6765\u8bb0\u5f55\u9879\u76ee\u4f9d\u8d56\u7684\u5e93\u53ca\u5176\u7248\u672c\u53f7\u3002\u53ef\u4ee5\u901a\u8fc7\u67e5\u770b\u8be5\u6587\u4ef6\u6765\u4e86\u89e3\u9879\u76ee\u6240\u9700\u7684\u5e93\u3002<\/p>\n<\/p>\n<p><p>\u4f8b\u5982\uff0c<code>requirements.txt<\/code>\u6587\u4ef6\u7684\u5185\u5bb9\u5982\u4e0b\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-text\">numpy==1.21.0<\/p>\n<p>pandas==1.3.0<\/p>\n<p>matplotlib==3.4.2<\/p>\n<p><\/code><\/pre>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u67e5\u770bconda\u73af\u5883<\/strong><\/p>\n<\/p>\n<p><p>\u5982\u679c\u4f60\u4f7f\u7528Anaconda\u6765\u7ba1\u7406Python\u73af\u5883\uff0c\u53ef\u4ee5\u4f7f\u7528<code>conda list<\/code>\u547d\u4ee4\u6765\u67e5\u770b\u5f53\u524d\u73af\u5883\u4e2d\u5df2\u5b89\u88c5\u7684\u5e93\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">conda list<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u8be5\u547d\u4ee4\u5c06\u8f93\u51fa\u4e00\u4e2a\u5df2\u5b89\u88c5\u5e93\u7684\u5217\u8868\uff0c\u5305\u62ec\u5e93\u7684\u540d\u79f0\u3001\u7248\u672c\u53f7\u3001\u6784\u5efa\u53f7\u7b49\u3002<\/p>\n<\/p>\n<\/li>\n<\/ol>\n<p><h3>\u4e94\u3001\u4f7f\u7528IDE\u63d2\u4ef6<\/h3>\n<\/p>\n<p><p>\u73b0\u4ee3\u7684IDE\uff08\u96c6\u6210\u5f00\u53d1\u73af\u5883\uff09\u901a\u5e38\u4f1a\u63d0\u4f9b\u63d2\u4ef6\u6216\u5185\u7f6e\u529f\u80fd\u6765\u67e5\u770b\u548c\u7ba1\u7406Python\u5e93\u3002\u4f8b\u5982\uff0cPyCharm\u3001VS Code\u7b49IDE\u90fd\u63d0\u4f9b\u4e86\u63d2\u4ef6\u6216\u5185\u7f6e\u529f\u80fd\u6765\u67e5\u770b\u9879\u76ee\u4e2d\u7684Python\u5e93\u3002<\/p>\n<\/p>\n<ol>\n<li>\n<p><strong>PyCharm<\/strong><\/p>\n<\/p>\n<p><p>\u5728PyCharm\u4e2d\uff0c\u53ef\u4ee5\u901a\u8fc7\u4ee5\u4e0b\u6b65\u9aa4\u67e5\u770b\u5df2\u5b89\u88c5\u7684Python\u5e93\uff1a<\/p>\n<\/p>\n<ul>\n<li>\u6253\u5f00PyCharm\uff0c\u8fdb\u5165\u9879\u76ee\u7a97\u53e3\u3002<\/li>\n<li>\u5728\u9879\u76ee\u7a97\u53e3\u4e2d\uff0c\u53f3\u952e\u70b9\u51fb\u9879\u76ee\u540d\u79f0\uff0c\u9009\u62e9\u201cOpen Module Settings\u201d\u3002<\/li>\n<li>\u5728\u201cProject: \u9879\u76ee\u540d\u79f0\u201d\u7a97\u53e3\u4e2d\uff0c\u9009\u62e9\u201cProject Interpreter\u201d\u3002<\/li>\n<li>\u5728\u53f3\u4fa7\u7a97\u53e3\u4e2d\uff0c\u53ef\u4ee5\u770b\u5230\u5df2\u5b89\u88c5\u7684Python\u5e93\u53ca\u5176\u7248\u672c\u53f7\u3002<\/li>\n<\/ul>\n<\/li>\n<li>\n<p><strong>VS Code<\/strong><\/p>\n<\/p>\n<p><p>\u5728VS Code\u4e2d\uff0c\u53ef\u4ee5\u901a\u8fc7\u4ee5\u4e0b\u6b65\u9aa4\u67e5\u770b\u5df2\u5b89\u88c5\u7684Python\u5e93\uff1a<\/p>\n<\/p>\n<ul>\n<li>\u6253\u5f00VS Code\uff0c\u8fdb\u5165\u9879\u76ee\u7a97\u53e3\u3002<\/li>\n<li>\u5728\u7ec8\u7aef\u7a97\u53e3\u4e2d\uff0c\u8f93\u5165<code>pip list<\/code>\u547d\u4ee4\uff0c\u67e5\u770b\u5df2\u5b89\u88c5\u7684Python\u5e93\u3002<\/li>\n<li>\u6216\u8005\uff0c\u4f7f\u7528VS Code\u7684\u63d2\u4ef6\uff0c\u4f8b\u5982Python\u63d2\u4ef6\uff0c\u53ef\u4ee5\u5728\u63d2\u4ef6\u7684\u201cPython: Select Interpreter\u201d\u9009\u9879\u4e2d\u67e5\u770b\u5df2\u5b89\u88c5\u7684Python\u5e93\u3002<\/li>\n<\/ul>\n<\/li>\n<\/ol>\n<p><h3>\u516d\u3001\u4f7f\u7528\u7b2c\u4e09\u65b9\u5e93\u7ba1\u7406\u5de5\u5177<\/h3>\n<\/p>\n<p><p>\u9664\u4e86pip\u548cconda\u4e4b\u5916\uff0c\u8fd8\u6709\u4e00\u4e9b\u7b2c\u4e09\u65b9\u7684\u5e93\u7ba1\u7406\u5de5\u5177\u53ef\u4ee5\u5e2e\u52a9\u67e5\u770b\u548c\u7ba1\u7406Python\u5e93\u3002\u4f8b\u5982\uff0cpipenv\u3001poetry\u7b49\u5de5\u5177\u3002<\/p>\n<\/p>\n<ol>\n<li>\n<p><strong>pipenv<\/strong><\/p>\n<\/p>\n<p><p>Pipenv\u662f\u4e00\u4e2aPython\u5305\u7ba1\u7406\u5de5\u5177\uff0c\u96c6\u6210\u4e86\u865a\u62df\u73af\u5883\u7ba1\u7406\u548c\u5305\u7ba1\u7406\u529f\u80fd\u3002\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u67e5\u770b\u5df2\u5b89\u88c5\u7684\u5e93\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">pipenv graph<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u8be5\u547d\u4ee4\u5c06\u8f93\u51fa\u4e00\u4e2a\u5df2\u5b89\u88c5\u5e93\u7684\u4f9d\u8d56\u5173\u7cfb\u56fe\uff0c\u5305\u62ec\u5e93\u7684\u540d\u79f0\u548c\u7248\u672c\u53f7\u3002<\/p>\n<\/p>\n<\/li>\n<li>\n<p><strong>poetry<\/strong><\/p>\n<\/p>\n<p><p>Poetry\u662f\u4e00\u4e2aPython\u5305\u7ba1\u7406\u5de5\u5177\uff0c\u63d0\u4f9b\u4e86\u4f9d\u8d56\u7ba1\u7406\u548c\u53d1\u5e03\u529f\u80fd\u3002\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u67e5\u770b\u5df2\u5b89\u88c5\u7684\u5e93\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">poetry show<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u8be5\u547d\u4ee4\u5c06\u8f93\u51fa\u4e00\u4e2a\u5df2\u5b89\u88c5\u5e93\u7684\u5217\u8868\uff0c\u5305\u62ec\u5e93\u7684\u540d\u79f0\u548c\u7248\u672c\u53f7\u3002<\/p>\n<\/p>\n<\/li>\n<\/ol>\n<p><h3>\u4e03\u3001\u603b\u7ed3<\/h3>\n<\/p>\n<p><p>\u901a\u8fc7\u4e0a\u8ff0\u65b9\u6cd5\uff0c\u6211\u4eec\u53ef\u4ee5\u65b9\u4fbf\u5730\u67e5\u770bPython\u4e2d\u7684\u5e93\u4fe1\u606f\u3002\u4f7f\u7528pip\u547d\u4ee4\u662f\u6700\u5e38\u7528\u4e14\u6700\u65b9\u4fbf\u7684\u65b9\u6cd5\uff0c\u800cPython\u5185\u7f6e\u51fd\u6570\u548c\u4ea4\u4e92\u5f0f\u89e3\u91ca\u5668\u4e5f\u63d0\u4f9b\u4e86\u7075\u6d3b\u7684\u67e5\u770b\u65b9\u5f0f\u3002\u6b64\u5916\uff0c\u901a\u8fc7\u67e5\u770b\u73af\u5883\u914d\u7f6e\u6587\u4ef6\u3001\u4f7f\u7528IDE\u63d2\u4ef6\u548c\u7b2c\u4e09\u65b9\u5e93\u7ba1\u7406\u5de5\u5177\uff0c\u6211\u4eec\u53ef\u4ee5\u66f4\u5168\u9762\u5730\u4e86\u89e3\u548c\u7ba1\u7406Python\u5e93\u3002<\/p>\n<\/p>\n<p><p><strong>\u6838\u5fc3\u70b9\u603b\u7ed3\uff1a<\/strong><\/p>\n<\/p>\n<ul>\n<li><strong>\u4f7f\u7528pip\u547d\u4ee4<\/strong>\uff1a\u65b9\u4fbf\u5feb\u6377\uff0c\u53ef\u4ee5\u5217\u51fa\u5df2\u5b89\u88c5\u5e93\u3001\u67e5\u627e\u7279\u5b9a\u5e93\u3001\u67e5\u770b\u8fc7\u65f6\u5e93\u3002<\/li>\n<li><strong>\u4f7f\u7528Python\u5185\u7f6e\u51fd\u6570<\/strong>\uff1a\u901a\u8fc7pkg_resources\u548cimportlib.metadata\u6a21\u5757\u52a8\u6001\u83b7\u53d6\u5e93\u4fe1\u606f\u3002<\/li>\n<li><strong>\u901a\u8fc7Python\u4ea4\u4e92\u5f0f\u89e3\u91ca\u5668<\/strong>\uff1a\u4f7f\u7528help()\u51fd\u6570\u67e5\u770b\u6a21\u5757\u4fe1\u606f\u3002<\/li>\n<li><strong>\u67e5\u770b\u73af\u5883\u914d\u7f6e\u6587\u4ef6<\/strong>\uff1a\u901a\u8fc7requirements.txt\u6587\u4ef6\u548cconda\u547d\u4ee4\u4e86\u89e3\u5e93\u4fe1\u606f\u3002<\/li>\n<li><strong>\u4f7f\u7528IDE\u63d2\u4ef6<\/strong>\uff1a\u901a\u8fc7PyCharm\u3001VS Code\u7b49IDE\u63d2\u4ef6\u67e5\u770b\u548c\u7ba1\u7406\u5e93\u3002<\/li>\n<li><strong>\u4f7f\u7528\u7b2c\u4e09\u65b9\u5e93\u7ba1\u7406\u5de5\u5177<\/strong>\uff1a\u901a\u8fc7pipenv\u548cpoetry\u7b49\u5de5\u5177\u67e5\u770b\u548c\u7ba1\u7406\u5e93\u3002<\/li>\n<\/ul>\n<p><p>\u8fd9\u4e9b\u65b9\u6cd5\u53ef\u4ee5\u5e2e\u52a9\u4f60\u66f4\u597d\u5730\u7ba1\u7406\u548c\u4f7f\u7528Python\u5e93\uff0c\u63d0\u9ad8\u5f00\u53d1\u6548\u7387\u548c\u4ee3\u7801\u8d28\u91cf\u3002<\/p>\n<\/p>\n<h2><strong>\u76f8\u5173\u95ee\u7b54FAQs\uff1a<\/strong><\/h2>\n<p> <strong>\u5982\u4f55\u5728Python\u4e2d\u67e5\u627e\u5df2\u5b89\u88c5\u7684\u5e93\uff1f<\/strong><br \/>\u53ef\u4ee5\u4f7f\u7528\u547d\u4ee4\u884c\u5de5\u5177\u6765\u67e5\u770bPython\u4e2d\u5df2\u5b89\u88c5\u7684\u5e93\u3002\u6253\u5f00\u7ec8\u7aef\u6216\u547d\u4ee4\u63d0\u793a\u7b26\uff0c\u8f93\u5165<code>pip list<\/code>\u547d\u4ee4\uff0c\u8fd9\u5c06\u663e\u793a\u6240\u6709\u5df2\u5b89\u88c5\u7684\u5e93\u53ca\u5176\u7248\u672c\u4fe1\u606f\u3002\u5982\u679c\u9700\u8981\u67e5\u770b\u7279\u5b9a\u5e93\u7684\u4fe1\u606f\uff0c\u53ef\u4ee5\u4f7f\u7528<code>pip show \u5e93\u540d<\/code>\u547d\u4ee4\uff0c\u8fd9\u4f1a\u63d0\u4f9b\u66f4\u8be6\u7ec6\u7684\u4fe1\u606f\uff0c\u5305\u62ec\u5e93\u7684\u5b89\u88c5\u4f4d\u7f6e\u3001\u4f9d\u8d56\u5173\u7cfb\u7b49\u3002<\/p>\n<p><strong>\u5982\u4f55\u5728Python\u4e2d\u5b89\u88c5\u65b0\u7684\u5e93\uff1f<\/strong><br \/>\u5b89\u88c5\u65b0\u7684Python\u5e93\u975e\u5e38\u7b80\u5355\u3002\u53ea\u9700\u6253\u5f00\u7ec8\u7aef\u6216\u547d\u4ee4\u63d0\u793a\u7b26\uff0c\u5e76\u4f7f\u7528<code>pip install \u5e93\u540d<\/code>\u547d\u4ee4\u3002\u4f8b\u5982\uff0c\u5982\u679c\u60f3\u5b89\u88c5<code>requests<\/code>\u5e93\uff0c\u53ef\u4ee5\u8f93\u5165<code>pip install requests<\/code>\u3002\u786e\u4fdd\u5728\u5b89\u88c5\u65f6\u7f51\u7edc\u8fde\u63a5\u6b63\u5e38\uff0cpip\u5c06\u81ea\u52a8\u4ecePython\u5305\u7d22\u5f15\uff08PyPI\uff09\u4e0b\u8f7d\u5e76\u5b89\u88c5\u6240\u9700\u7684\u5e93\u3002<\/p>\n<p><strong>\u5982\u4f55\u67e5\u770b\u67d0\u4e2a\u5e93\u7684\u6587\u6863\u6216\u4f7f\u7528\u793a\u4f8b\uff1f<\/strong><br \/>\u5927\u591a\u6570Python\u5e93\u90fd\u5728\u5176\u5b98\u65b9\u7f51\u7ad9\u6216GitHub\u9875\u9762\u4e0a\u63d0\u4f9b\u6587\u6863\u3002\u53ef\u4ee5\u901a\u8fc7\u8bbf\u95ee\u5e93\u7684PyPI\u9875\u9762\uff08\u4f8b\u5982\uff0cpypi.org\uff09\u67e5\u627e\u76f8\u5173\u6587\u6863\u94fe\u63a5\u3002\u6b64\u5916\uff0c\u8bb8\u591a\u5e93\u5728GitHub\u4e0a\u4f1a\u6709README\u6587\u4ef6\uff0c\u5176\u4e2d\u5305\u542b\u4f7f\u7528\u793a\u4f8b\u548c\u5b89\u88c5\u8bf4\u660e\u3002\u4f7f\u7528<code>help(\u5e93\u540d)<\/code>\u547d\u4ee4\u4e5f\u53ef\u4ee5\u5728Python\u4ea4\u4e92\u5f0f\u73af\u5883\u4e2d\u67e5\u770b\u8be5\u5e93\u7684\u57fa\u672c\u6587\u6863\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"\u5728Python\u4e2d\u67e5\u770b\u5e93\u53ef\u4ee5\u901a\u8fc7\u4ee5\u4e0b\u51e0\u79cd\u65b9\u6cd5\uff1a\u4f7f\u7528pip\u547d\u4ee4\u3001\u4f7f\u7528Python\u5185\u7f6e\u51fd\u6570\u3001\u901a\u8fc7Python\u4ea4\u4e92\u5f0f\u89e3 [&hellip;]","protected":false},"author":3,"featured_media":1179244,"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\/1179232"}],"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=1179232"}],"version-history":[{"count":"1","href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1179232\/revisions"}],"predecessor-version":[{"id":1179246,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1179232\/revisions\/1179246"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media\/1179244"}],"wp:attachment":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media?parent=1179232"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/categories?post=1179232"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/tags?post=1179232"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}