{"id":7075,"date":"2023-10-19T15:45:18","date_gmt":"2023-10-19T07:45:18","guid":{"rendered":"https:\/\/www.yimenyun.cn\/emen\/?p=7075"},"modified":"2023-10-19T15:45:18","modified_gmt":"2023-10-19T07:45:18","slug":"nvm%e6%89%93%e5%8c%85%e6%88%90exe%e6%96%87%e4%bb%b6%e6%98%af%e6%80%8e%e4%b9%88%e5%ae%9e%e7%8e%b0%e7%9a%84%ef%bc%9f","status":"publish","type":"post","link":"https:\/\/www.yimenyun.cn\/emen\/7075\/","title":{"rendered":"nvm\u6253\u5305\u6210exe\u6587\u4ef6\u662f\u600e\u4e48\u5b9e\u73b0\u7684\uff1f"},"content":{"rendered":"

NVM\uff08Node Version Manager\uff09\u662f\u4e00\u4e2a\u7528\u4e91\u6548\u6253\u5305exe\u6587\u4ef6<\/a>\u4e8e\u7ba1\u7406\u591a\u4e2a Node.js \u7248\u672c\u7684\u5de5\u5177\uff0c\u53ef\u4ee5\u8ba9\u5f00\u53d1\u8005\u5728\u540c\u4e00\u53f0\u7535\u8111\u4e0a\u540c\u65f6\u4f7f\u7528\u591a\u4e2a Node.js \u7248\u672c\u3002\u5728\u5f00\u53d1\u8fc7\u7a0b\u4e2d\uff0c\u4e0d\u540c\u7684\u9879\u76ee\u53ef\u80fd\u9700\u8981\u4e0d\u540c\u7684 Node.js \u7248\u672c\uff0cNVM \u53ef\u4ee5\u65b9\u4fbf\u5730\u5207\u6362\u4e0d\u540c\u7684\u7248\u672c\u3002<\/p>\n

NVM \u7684\u5b89\u88c5\u548c\u4f7f\u7528\u90fd\u975e\u5e38\u7b80\u5355\uff0c\u4f46\u662f\u6bcf\u6b21\u4f7f\u7528\u65f6\u90fd\u9700\u8981\u5728\u547d\u4ee4\u884c\u4e2d\u8f93\u5165\u76f8\u5e94\u7684\u547d\u4ee4\uff0c\u6bd4\u8f83\u9ebb\u70e6\u3002\u4e3a\u4e86\u65b9\u4fbf\u4f7f\u7528\uff0c\u6211\u4eec\u53ef\u4ee5\u5c06 NVM \u6253\u5305\u6210\u4e00\u4e2a\u53ef\u6267\u884c\u6587\u4ef6\uff08exe\uff09\uff0c\u8fd9\u6837\u5c31\u53ef\u4ee5\u76f4\u63a5\u5728\u684c\u9762\u4e0a\u53cc\u51fb\u6253\u5f00\uff0c\u800c\u4e0d\u7528\u6bcf\u6b21\u90fd\u5728\u547d\u4ee4\u884c\u4e2d\u8f93\u5165\u547d\u4ee4\u3002<\/p>\n

\u5177\u4f53\u5b9e\u73b0\u65b9\u6cd5\u7f51\u9875\u4e00\u952e\u5c01\u88c5exe<\/a>\u5982\u4e0b\uff1a<\/p>\n

1. \u5b89\u88c5 PyInstaller<\/p>\n

PyInstaller \u662f\u4e00\u4e2a\u7528\u4e8e\u5c06 Python \u4ee3\u7801\u6253\u5305\u6210\u53ef\u6267\u884c\u6587\u4ef6\u7684\u5de5\u5177\uff0c\u53ef\u4ee5\u5728 Windows\u3001Linux\u3001MacOS \u7b49\u5e73\u53f0\u4e0a\u4f7f\u7528\u3002\u6211\u4eec\u53ef\u4ee5\u4f7f\u7528 PyInstaller \u6765\u5c06 NVM \u6253\u5305\u6210 exe \u6587\u4ef6\u3002<\/p>\n

\u9996\u5148\u9700\u8981\u5b89\u88c5 PyInstaller\uff0c\u53ef\u4ee5\u4f7f\u7528 pip \u547d\u4ee4\u8fdb\u884c\u5b89\u88c5\uff1a<\/p>\n

“`<\/p>\n

pip install pyinstaller<\/p>\n

“`<\/p>\n

2. \u7f16\u5199\u6253\u5305\u811a\u672c<\/p>\n

\u5728 NVM \u5b89\u88c5\u76ee\u5f55\u4e0b\u521b\u5efa\u4e00\u4e2a\u540d\u4e3a nvm_app.py \u7684 Python \u6587\u4ef6\uff0c\u7528\u4e8e\u6267\u884c NVM \u547d\u4ee4\u3002\u4ee3\u7801\u5982\u4e0b\uff1a<\/p>\n

“`<\/p>\n

import os<\/p>\n

import sys<\/p>\n

import subprocess<\/p>\n

def main():<\/p>\n

nvm_path = os.path.join(os.environ[‘APPDATA’], ‘nvm’)<\/p>\n

nvm_cmd = os.path.join(nvm_path, ‘nvm.exe’)<\/p>\n

args = sys.argv[1:]<\/p>\n

cmd = [nvm_cmd] + args<\/p>\n

subprocess.call(cmd)<\/p>\n

if __name__ == ‘__main__’:<\/p>\n

main()<\/p>\n

“`<\/p>\n

\u8fd9\u4e2a\u811a\u672c\u7684\u4f5c\u7528\u662f\u83b7\u53d6 NVM \u5b89\u88c5\u8def\u5f84\uff0c\u7136\u540e\u6267\u884c\u4f20\u5165\u7684\u53c2\u6570\u3002\u6bd4\u5982\u6211\u4eec\u53ef\u4ee5\u5728\u547d\u4ee4\u884c\u4e2d\u6267\u884c\u4ee5\u4e0b\u547d\u4ee4\uff1a<\/p>\n

“`<\/p>\n

python nvm_app.py use 12.16.1<\/p>\n

“`<\/p>\n

\u8fd9\u4e2a\u547d\u4ee4\u4f1a\u5207\u6362\u5230 Node.js 12.16.1 \u7248\u672c\u3002<\/p>\n

3. \u6253\u5305\u6210 exe \u6587\u4ef6<\/p>\n

\u5728\u547d\u4ee4\u884c\u4e2d\u8fdb\u5165 NVM \u5b89\u88c5\u76ee\u5f55\uff0c\u6267\u884c\u4ee5\u4e0b\u547d\u4ee4\uff1a<\/p>\n

“`<\/p>\n

pyinstaller nvm_app.py –onefile –name nvm<\/p>\n

“`<\/p>\n

\u8fd9\u4e2a\u547d\u4ee4\u4f1a\u5c06 nvm_app.py \u6587\u4ef6\u6253\u5305\u6210\u4e00\u4e2a\u540d\u4e3a nvm.exe \u7684\u53ef\u6267\u884c\u6587\u4ef6\uff0c\u5e76\u4e14\u53ea\u751f\u6210\u4e00\u4e2a\u6587\u4ef6\u3002\u751f\u6210\u7684 exe \u6587\u4ef6\u4f1a\u4fdd\u5b58\u5728 dist \u76ee\u5f55\u4e0b\u3002<\/p>\n

4. \u4f7f\u7528 exe \u6587\u4ef6<\/p>\n

\u5c06\u751f\u6210\u7684 nvm.exe \u6587\u4ef6\u62f7\u8d1d\u5230\u684c\u9762\u6216\u5176\u4ed6\u65b9\u4fbf\u7684\u4f4d\u7f6e\uff0c\u53cc\u51fb\u6253\u5f00\u5373\u53ef\u4f7f\u7528\u3002\u6bd4<\/p>\n

<\/figure>\n<\/p>\n

\u5982\u6211\u4eec\u53ef\u4ee5\u76f4\u63a5\u5728\u547d\u4ee4\u884c\u4e2d\u6267\u884c\u4ee5\u4e0b\u547d\u4ee4\uff1a<\/p>\n

“`<\/p>\n

nvm use 12.16.1<\/p>\n

“`<\/p>\n

\u8fd9\u4e2a\u547d\u4ee4\u4f1a\u5207\u6362\u5230 Node.js 12.16.1 \u7248\u672c\u3002<\/p>\n

\u603b\u7ed3\uff1a<\/p>\n

\u5c06 NVM \u6253\u5305\u6210 exe \u6587\u4ef6\u53ef\u4ee5\u65b9\u4fbf\u5f00\u53d1\u8005\u5728 Windows \u5e73\u53f0\u4e0a\u4f7f\u7528\uff0c\u4e0d\u9700\u8981\u6bcf\u6b21\u90fd\u5728\u547d\u4ee4\u884c\u4e2d\u8f93\u5165\u76f8\u5e94\u7684\u547d\u4ee4\u3002\u8fd9\u4e2a\u65b9\u6cd5\u4e5f\u53ef\u4ee5\u5e94\u7528\u5230\u5176\u4ed6\u9700\u8981\u9891\u7e41\u4f7f\u7528\u7684\u547d\u4ee4\u884c\u5de5\u5177\u4e0a\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"

NVM\uff08Node Version Manager\uff09\u662f\u4e00\u4e2a\u7528\u4e8e\u7ba1\u7406\u591a\u4e2a Node.js \u7248\u672c\u7684\u5de5\u5177\uff0c\u53ef\u4ee5\u8ba9\u5f00\u53d1\u8005\u5728\u540c\u4e00\u53f0\u7535\u8111\u4e0a\u540c\u65f6\u4f7f\u7528\u591a\u4e2a Node.js \u7248\u672c\u3002\u5728\u5f00\u53d1\u8fc7\u7a0b\u4e2d\uff0c\u4e0d\u540c\u7684\u9879\u76ee\u53ef\u80fd\u9700\u8981\u4e0d\u540c\u7684<\/p>\n","protected":false},"author":8,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[7],"tags":[12637,6189,832,1622,16],"topic":[],"class_list":["post-7075","post","type-post","status-publish","format-standard","hentry","category-exekf","tag-phpexe","tag-phython","tag-832","tag-1622","tag-16"],"_links":{"self":[{"href":"https:\/\/www.yimenyun.cn\/emen\/wp-json\/wp\/v2\/posts\/7075","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.yimenyun.cn\/emen\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.yimenyun.cn\/emen\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.yimenyun.cn\/emen\/wp-json\/wp\/v2\/users\/8"}],"replies":[{"embeddable":true,"href":"https:\/\/www.yimenyun.cn\/emen\/wp-json\/wp\/v2\/comments?post=7075"}],"version-history":[{"count":0,"href":"https:\/\/www.yimenyun.cn\/emen\/wp-json\/wp\/v2\/posts\/7075\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.yimenyun.cn\/emen\/wp-json\/wp\/v2\/media?parent=7075"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.yimenyun.cn\/emen\/wp-json\/wp\/v2\/categories?post=7075"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.yimenyun.cn\/emen\/wp-json\/wp\/v2\/tags?post=7075"},{"taxonomy":"topic","embeddable":true,"href":"https:\/\/www.yimenyun.cn\/emen\/wp-json\/wp\/v2\/topic?post=7075"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}