解决 node-gyp 错误问题|node与python版本不匹配报错|node-gyp|vue

本文介绍了解决在Windows环境下安装node-gyp时遇到的问题,特别是由于找不到Python 2.7而导致的错误。通过安装Python 2.7并设置npm配置来指定Python路径的方法,帮助用户顺利完成node-gyp的安装。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

gyp info using node-gyp@3.8.0
npm ERR! gyp info using node@14.15.0 | win32 | x64
npm ERR! gyp verb command rebuild []
npm ERR! gyp verb command clean []
npm ERR! gyp verb clean removing "build" directory
npm ERR! gyp verb command configure []
npm ERR! gyp verb check python checking for Python executable "python2.7" in the PATH
npm ERR! gyp verb `which` failed Error: not found: python2.7
npm ERR! gyp verb `which` failed     at getNotFoundError (F:\my_download\001components-master\001components-master\node_modules\which\which.js:13:12)
npm ERR! gyp verb `which` failed     at F (F:\my_download\001components-master\001components-master\node_modules\which\which.js:68:19)
npm ERR! gyp verb `which` failed     at E (F:\my_download\001components-master\001components-master\node_modules\which\which.js:80:29)
npm ERR! gyp verb `which` failed     at F:\my_download\001components-master\001components-master\node_modules\which\which.js:89:16
npm ERR! gyp verb `which` failed     at F:\my_download\001components-master\001components-master\node_modules\isexe\index.js:42:5
npm ERR! gyp verb `which` failed     at F:\my_download\001components-master\001components-master\node_modules\isexe\windows.js:36:5
npm ERR! gyp verb `which` failed     at FSReqCallback.oncomplete (fs.js:183:21)
npm ERR! gyp verb `which` failed  python2.7 Error: not found: python2.7
npm ERR! gyp verb `which` failed     at getNotFoundError (F:\my_download\001components-master\001components-master\node_modules\which\which.js:13:12)
npm ERR! gyp verb `which` failed     at F (F:\my_download\001components-master\001components-master\node_modules\which\which.js:68:19)
npm ERR! gyp verb `which` failed     at E (F:\my_download\001components-master\001components-master\node_modules\which\which.js:80:29)
npm ERR! gyp verb `which` failed     at F:\my_download\001components-master\001components-master\node_modules\which\which.js:89:16
npm ERR! gyp verb `which` failed     at F:\my_download\001components-master\001components-master\node_modules\isexe\windows.js:36:5
npm ERR! gyp verb `which` failed     at FSReqCallback.oncomplete (fs.js:183:21) {
npm ERR! gyp verb `which` failed   code: 'ENOENT'
npm ERR! gyp verb `which` failed }
npm ERR! gyp verb could not find "python2.7". checking python launcher
npm ERR! gyp verb could not find "python2.7". guessing location
npm ERR! gyp verb ensuring that file exists: C:\Python27\python.exe
npm ERR! gyp ERR! stack Error: Can't find Python executable "python2.7", you can set the PYTHON env variable.
npm ERR! gyp ERR! stack     at PythonFinder.failNoPython (F:\my_download\001components-master\001components-master\node_modules\node-gyp\lib\configure.js:484:19)
npm ERR! gyp ERR! stack     at PythonFinder.<anonymous> (F:\my_download\001components-master\001components-master\node_modules\node-gyp\lib\configure.js:509:16)
npm ERR! gyp ERR! stack     at callback (F:\my_download\001components-master\001components-master\node_modules\graceful-fs\polyfills.js:295:20)
npm ERR! gyp ERR! stack     at FSReqCallback.oncomplete (fs.js:183:21)
npm ERR! gyp ERR! System Windows_NT 10.0.18363
npm ERR! gyp ERR! command "C:\\akula\\nodejs\\node.exe" "F:\\my_download\\001components-master\\001components-master\\node_modules\\node-gyp\\bin\\node-gyp.js" "rebuild" "--verbonpm ERR! gyp ERR! cwd F:\my_download\001components-master\001components-master\node_modules\node-sass
npm ERR! gyp ERR! node -v v14.15.0
npm ERR! gyp ERR! node-gyp -v v3.8.0
npm ERR! gyp ERR! not ok
npm ERR! Build failed with error code: 1

npm ERR! A complete log of this run can be found in:

项目要用到node-gyp(给爷爬)

mac上没问题 windows有问题

看上面的日志, 提到了 python2.7

看来这个模块用的上古时代的python2.7的技术

windows的同学可以先安装 python2 这里下载:  https://www.python.org/ftp/python/2.7/python-2.7.amd64.msi

不要修改路径!! 不要修改路径!! 等他安装到 C:\python2.7\ 目录下面哈. 这样不会影响你的 python3+体系

安装了python再执行  npm config set python python2.7 表示npm中凡是遇到python命令统一修正为执行python2.7

再执行 npm install node-gyp 就好了, 是不是很顺利哇?

以后如又有其他的包用的python3遇到报错的话那么可以使用 npm config delete python 这样恢复npm命令的python版本环境变量( npm config list 查看)

------------------------

win10了解WSL的同学完全可以切换到WSL里面编码哈,支持热更新.什么node-gyp上面这些问题都不会遇到.  WSL2还没试过(因为WSL用着挺顺手)

----------------------

总结:

  1. 默认安装python2.7
  2. 映射npm config set pytyon python2.7
### DeepSeek API 调用方法 对于希望利用大型语言模型构建服务的应用开发者而言,了解并掌握DeepSeek API的调用方法至关重要。进入官网完成账户注册后,通过API开放平台获取专属API Key是第一步[^1]。 #### 获取API Key - 注册账号于官方站点:DeepSeek | 深度求索。 - 导航至API开放平台页面。 - 在左侧菜单选择API Keys选项卡。 - 创建新的API Key用于后续请求认证。 #### Python示例代码 一旦拥有了有效的API Key,就可以借助编程语言如Python发起HTTP POST请求来交互数据: ```python import requests url = "https://api.deepseek.com/v1/chat/completions" headers = { 'Content-Type': 'application/json', 'Authorization': 'Bearer YOUR_API_KEY' } data = { "messages": [ {"role": "system", "content": "You are a helpful assistant."}, {"role": "user", "content": "Tell me about the weather today"}, {"role": "assistant", "content": ""} ], "stream": False, } response = requests.post(url, headers=headers, json=data) if response.status_code == 200: result = response.json() print(result['choices'][0]['message']['content']) else: print(f"Error {response.status_code}: {response.text}") ``` 此段程序展示了如何发送消息给AI聊天接口,并接收返回的结果。注意替换`YOUR_API_KEY`为实际取得的关键字字符串[^2]。 #### Java环境下的实现方案 除了Python之外,Java也是一种流行的选择。为了简化集成过程,可以考虑采用预编译好的库或工具包,比如Ollama项目提供了便捷的方式来进行安装配置以及DeepSeek的大规模语言模型互动[^3]。
评论 9
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

AKULAKK

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值