windows安装robotjs的心路

使用npm安装robotjs所遇到的问题

问题

通过命令npm install robotjs --save进行安装,遇到第一个待解决问题

gyp ERR! find Python 
gyp ERR! find Python Python is not set from command line or npm configuration
gyp ERR! find Python Python is not set from environment variable PYTHON
gyp ERR! find Python checking if "python" can be used
gyp ERR! find Python - "python" is not in PATH or produced an error
gyp ERR! find Python checking if "python2" can be used
gyp ERR! find Python - "python2" is not in PATH or produced an error
gyp ERR! find Python checking if "python3" can be used
gyp ERR! find Python - "python3" is not in PATH or produced an error
gyp ERR! find Python checking if the py launcher can be used to find Python 2
gyp ERR! find Python - "py.exe" is not in PATH or produced an error
gyp ERR! find Python checking if Python is C:\Python27\python.exe
gyp ERR! find Python - "C:\Python27\python.exe" could not be run
gyp ERR! find Python checking if Python is C:\Python37\python.exe
gyp ERR! find Python - "C:\Python37\python.exe" could not be run
gyp ERR! find Python
gyp ERR! find Python **********************************************************
gyp ERR! find Python You need to install the latest version of Python.
gyp ERR! find Python Node-gyp should be able to find and use Python. If not,
gyp ERR! find Python you can try one of the following options:
gyp ERR! find Python - Use the switch --python="C:\Path\To\python.exe"
gyp ERR! find Python   (accepted by both node-gyp and npm)
gyp ERR! find Python - Set the environment variable PYTHON
gyp ERR! find Python - Set the npm configuration variable python:
gyp ERR! find Python   npm config set python "C:\Path\To\python.exe"
gyp ERR! find Python For more information consult the documentation at:
gyp ERR! find Python https://github.com/nodejs/node-gyp#installation
gyp ERR! find Python **********************************************************
gyp ERR! find Python
gyp ERR! configure error
gyp ERR! stack Error: Could not find any Python installation to use
gyp ERR! stack     at PythonFinder.fail (C:\dev\nvm\v14.13.1\node_modules\npm\node_modules\node-gyp\lib\find-python.js:307:47)
gyp ERR! stack     at PythonFinder.runChecks (C:\dev\nvm\v14.13.1\node_modules\npm\node_modules\node-gyp\lib\find-python.js:136:21)
gyp ERR! stack     at PythonFinder.<anonymous> (C:\dev\nvm\v14.13.1\node_modules\npm\node_modules\node-gyp\lib\find-python.js:225:16)
gyp ERR! stack     at PythonFinder.execFileCallback (C:\dev\nvm\v14.13.1\node_modules\npm\node_modules\node-gyp\lib\find-python.js:271:16)
gyp ERR! stack     at exithandler (child_process.js:315:5)
gyp ERR! stack     at ChildProcess.errorhandler (child_process.js:327:5)
gyp ERR! stack     at ChildProcess.emit (events.js:314:20)
gyp ERR! stack     at Process.ChildProcess._handle.onexit (internal/child_process.js:274:12)
gyp ERR! stack     at onErrorNT (internal/child_process.js:464:16)
gyp ERR! stack     at processTicksAndRejections (internal/process/task_queues.js:80:21)
gyp ERR! System Windows_NT 10.0.18363
gyp ERR! command "C:\\dev\\nodejs\\node.exe" "C:\\dev\\nvm\\v14.13.1\\node_modules\\npm\\node_modules\\node-gyp\\bin\\node-gyp.js" "rebuild"      
gyp ERR! cwd D:\新建文件夹\代码\VSCode\Electron\RemoteControl\app\renderer\src\remotecontrol\node_modules\robotjs
gyp ERR! node -v v14.13.1
gyp ERR! node-gyp -v v5.1.0
gyp ERR! not ok

搜索结果:

结果一:npm install --global --production windows-build-tools
结果二:手动安装python2.7版本,配置环境变量

二者本质上应该就是安装python,并配置环境变量
结果一 会一直卡死在 python 安装成功上
具体原因不详

继续入坑

  1. 手动安装python成功
  2. 先使用npm cache clean -f命令清理npm缓存,尽量排除掉干扰
  3. 再次使用npm install robotjs --save进行安装,至此遇到第二个问题
Traceback (most recent call last):
  File "C:\dev\nvm\v14.13.1\node_modules\npm\node_modules\node-gyp\gyp\gyp_main.py", line 50, in <module>
    sys.exit(gyp.script_main())
  File "C:\dev\nvm\v14.13.1\node_modules\npm\node_modules\node-gyp\gyp\pylib\gyp\__init__.py", line 554, in script_main
    return main(sys.argv[1:])
  File "C:\dev\nvm\v14.13.1\node_modules\npm\node_modules\node-gyp\gyp\pylib\gyp\__init__.py", line 547, in main
    return gyp_main(args)
  File "C:\dev\nvm\v14.13.1\node_modules\npm\node_modules\node-gyp\gyp\pylib\gyp\__init__.py", line 532, in gyp_main
    generator.GenerateOutput(flat_list, targets, data, params)
  File "C:\dev\nvm\v14.13.1\node_modules\npm\node_modules\node-gyp\gyp\pylib\gyp\generator\msvs.py", line 2008, in GenerateOutput
    msvs_version)
  File "C:\dev\nvm\v14.13.1\node_modules\npm\node_modules\node-gyp\gyp\pylib\gyp\generator\msvs.py", line 1843, in _CreateProjectObjects
    guid = _GetGuidOfProject(proj_path, spec)
  File "C:\dev\nvm\v14.13.1\node_modules\npm\node_modules\node-gyp\gyp\pylib\gyp\generator\msvs.py", line 910, in _GetGuidOfProject
    guid = guid or MSVSNew.MakeGuid(proj_path)
  File "C:\dev\nvm\v14.13.1\node_modules\npm\node_modules\node-gyp\gyp\pylib\gyp\MSVSNew.py", line 48, in MakeGuid
    d = hashlib.md5((str(seed) + str(name)).encode('utf-8')).hexdigest().upper()
UnicodeDecodeError: 'ascii' codec can't decode byte 0xd0 in position 11: ordinal not in range(128)
gyp ERR! configure error 
gyp ERR! stack Error: `gyp` failed with exit code: 1
gyp ERR! stack     at ChildProcess.onCpExit (C:\dev\nvm\v14.13.1\node_modules\npm\node_modules\node-gyp\lib\configure.js:351:16)
gyp ERR! stack     at ChildProcess.emit (events.js:314:20)
gyp ERR! stack     at Process.ChildProcess._handle.onexit (internal/child_process.js:276:12)
gyp ERR! System Windows_NT 10.0.18363
gyp ERR! command "C:\\dev\\nodejs\\node.exe" "C:\\dev\\nvm\\v14.13.1\\node_modules\\npm\\node_modules\\node-gyp\\bin\\node-gyp.js" "rebuild"      
gyp ERR! cwd D:\新建文件夹\代码\VSCode\Electron\RemoteControl\app\renderer\src\remotecontrol\node_modules\robotjs
gyp ERR! node -v v14.13.1
gyp ERR! node-gyp -v v5.1.0
gyp ERR! not ok

经过搜索以及提示排查
大致问题是ascii的编码问题
找到提示的第一个文件File "C:\dev\nvm\v14.13.1\node_modules\npm\node_modules\node-gyp\gyp\gyp_main.py", line 50, in <module>

出坑

在找到的文件中修改如下

import os
import sys
import subprocess

# 添加代码
# 由于windows默认是使用的gbk字符集
# 故此将字符集修改为gbk
defaultencoding = 'gbk'
if sys.getdefaultencoding() != defaultencoding:
    reload(sys)
    sys.setdefaultencoding(defaultencoding)
# 结束添加代码

PY3 = bytes != str

# Below IsCygwin() function copied from pylib/gyp/common.py
def IsCygwin():
  try:
    out = subprocess.Popen("uname",
            stdout=subprocess.PIPE,
            stderr=subprocess.STDOUT)
    stdout, stderr = out.communicate()
    if PY3:
      stdout = stdout.decode("utf-8")
    return "CYGWIN" in str(stdout)
  except Exception:
    return False

成功

再次使用npm install robotjs --save进行安装
输出如下:

> robotjs@0.6.0 install D:\新建文件夹\代码\VSCode\Electron\RemoteControl\app\renderer\src\remotecontrol\node_modules\robotjs
> prebuild-install || node-gyp rebuild

prebuild-install WARN install No prebuilt binaries found (target=14.13.1 runtime=node arch=x64 libc= platform=win32)

D:\新建文件夹\代码\VSCode\Electron\RemoteControl\app\renderer\src\remotecontrol\node_modules\robotjs>if not defined npm_config_node_gyp (node "C:\dev\nvm\v14.13.1\node_modules\npm\node_modules\npm-lifecycle\node-gyp-bin\\..\..\node_modules\node-gyp\bin\node-gyp.js" rebuild )  else (node "C:\dev\nvm\v14.13.1\node_modules\npm\node_modules\node-gyp\bin\node-gyp.js" rebuild )
在此解决方案中一次生成一个项目。若要启用并行生成,请添加“-m”开关。
  robotjs.cc
  win_delay_load_hook.cc
D:\新建文件夹\代码\VSCode\Electron\RemoteControl\app\renderer\src\remotecontrol\node_modules\robotjs\src\os.h(26): warning C4005: “STRICT”: 宏重定
义 (编译源文件
..\src\robotjs.cc) [D:\新建文件夹\代码\VSCode\Electron\RemoteControl\app\renderer\src\remotecontrol\node_modules\robotjs\build\robotjs.vcxproj]
  C:\Program Files (x86)\Windows Kits\10\Include\10.0.17763.0\shared\minwindef.h(23): note: 参见“STRICT”的前一个定义 (编译源文件 ..\src\robotjs.cc)
  deadbeef_rand.c
  mouse.c
  keypress.c
  keycode.c
  screen.c
  screengrab.c
  snprintf.c
  MMBitmap.c
    正在创建库 D:\新建文件夹\代码\VSCode\Electron\RemoteControl\app\renderer\src\remotecontrol\node_modules\robotjs\build\Release\robotjs.lib 和对
象 D:\新建文件夹\代码
  \VSCode\Electron\RemoteControl\app\renderer\src\remotecontrol\node_modules\robotjs\build\Release\robotjs.exp
  robotjs.vcxproj -> D:\新建文件夹\代码\VSCode\Electron\RemoteControl\app\renderer\src\remotecontrol\node_modules\robotjs\build\Release\\robotjs.node
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@2.3.2 (node_modules\fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@2.3.2: wanted {"os":"darwin","arch":"any"} (current: {"os":"win32","arch":"x64"})
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: iconv-corefoundation@1.1.5 (node_modules\iconv-corefoundation):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for iconv-corefoundation@1.1.5: wanted {"os":"darwin","arch":"any"} (current: {"os":"win32","arch":"x64"})
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@1.2.13 (node_modules\watchpack-chokidar2\node_modules\fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@1.2.13: wanted {"os":"darwin","arch":"any"} (current: {"os":"win32","arch":"x64"})
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@1.2.13 (node_modules\webpack-dev-server\node_modules\fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@1.2.13: wanted {"os":"darwin","arch":"any"} (current: {"os":"win32","arch":"x64"})
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: dmg-license@1.0.8 (node_modules\dmg-license):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for dmg-license@1.0.8: wanted {"os":"darwin","arch":"any"} (current: {"os":"win32","arch":"x64"})

+ robotjs@0.6.0
added 40 packages from 33 contributors in 75.885s

107 packages are looking for funding
  run `npm fund` for details

再遇问题

  1. robotjs安装成功后,还需要进行编译的一个过程
  2. 先使用npm install electron-rebuild --save-dev命令安装编译所需的electron-rebuild
  3. 使用npx electron-rebuild进行编译,然而问题又一次的出现了
- Searching dependency tree
gyp info find Python using Python version 2.7.15 found at "C:\Python27\python.exe"
gyp http GET https://www.electronjs.org/headers/v11.4.4/node-v11.4.4-headers.tar.gz
gyp WARN install got an error, rolling back install
✖ Rebuild Failed

An unhandled error occurred inside electron-rebuild
node-gyp failed to rebuild 'D:\新建文件夹\代码\VSCode\Electron\RemoteControl\app\renderer\src\remotecontrol\node_modules\robotjs'.
Error: getaddrinfo EAI_AGAIN gh-contractor-zcbenz.s3.amazonaws.com


Error: node-gyp failed to rebuild 'D:\新建文件夹\代码\VSCode\Electron\RemoteControl\app\renderer\src\remotecontrol\node_modules\robotjs'.
Error: getaddrinfo EAI_AGAIN gh-contractor-zcbenz.s3.amazonaws.com


    at ModuleRebuilder.rebuildNodeGypModule (D:\新建文件夹\代码\VSCode\Electron\RemoteControl\app\renderer\src\remotecontrol\node_modules\electron-rebuild\lib\src\module-rebuilder.js:193:19)
    at async Rebuilder.rebuildModuleAt (D:\新建文件夹\代码\VSCode\Electron\RemoteControl\app\renderer\src\remotecontrol\node_modules\electron-rebuild\lib\src\rebuild.js:190:9)
    at async Rebuilder.rebuild (D:\新建文件夹\代码\VSCode\Electron\RemoteControl\app\renderer\src\remotecontrol\node_modules\electron-rebuild\lib\src\rebuild.js:152:17)
    at async D:\新建文件夹\代码\VSCode\Electron\RemoteControl\app\renderer\src\remotecontrol\node_modules\electron-rebuild\lib\src\cli.js:146:9
  1. 使用命令npx electron-rebuild -d=https://npm.taobao.org/mirrors/atom-shell尝试使用淘宝镜像进行解决,but 依然报错,而且似乎更严重
  2. 根据关键字gyp WARN install got an error, rolling back install进行搜索
  3. 结果:需要设置(临时的)环境变量,以使得其能重定向

详情参见:https://blog.csdn.net/u013613428/article/details/51545479
由此去

  1. 使用set ATOM_NODE_URL=http://gh-contractor-zcbenz.s3.amazonaws.com/atom-shell/dist进行设置环境变量,完成其重定向
  2. 再使用npx electron-rebuild命令进行编译,but又有问题,但一看便知与上面的字符编码是同一个问题,故此便不再赘述
  • 2
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
要在VMware上安装Windows 10,你可以按照以下步骤进行操作: 1. 首先,确保你已经下载了Windows 10的ISO文件。你可以从官方网站或其他可信的来源下载64位的Windows 10 ISO文件。 2. 打开VMware Workstation软件并点击"创建新的虚拟机"。 3. 在创建虚拟机向导中,选择"典型"模式,并点击"下一步"。 4. 在"选择客户机操作系统"页面上,选择"Windows"并选择"Windows 10 x64"作为操作系统版本。点击"下一步"。 5. 在"指定虚拟机名称和位置"页面上,为虚拟机指定一个名称和保存位置。点击"下一步"。 6. 在"指定磁盘容量"页面上,选择磁盘大小并点击"下一步"。通常建议选择至少40GB的磁盘容量。 7. 在"完成设置"页面上,点击"完成"以创建新的虚拟机。 8. 现在,你已经创建了一个新的虚拟机。接下来,需要配置虚拟机的一些设置。点击"编辑虚拟机设置"。 9. 在虚拟机设置中,你可以设置虚拟机的硬件配置,如内存、处理器等。你还可以设置网络和其他高级选项。根据你的需求,进行相应的配置。确保在设备状态中的启动时连接被勾选上。 10. 点击"确定"保存虚拟机的设置。 11. 现在,你可以启动虚拟机并开始安装Windows 10。选择虚拟机,点击"电源"按钮以启动虚拟机。 12. 在虚拟机中,按照安装Windows 10的常规步骤进行操作。选择语言、系统配置和其他设置。 13. 完成安装后,你就可以在VMware虚拟机中运行Windows 10了。 请注意,以上步骤仅提供了一种安装Windows 10的方法。具体的步骤可能会因VMware版本和操作系统版本而有所不同。建议你参考VMware的官方文档或相关教程,以获得更详细和准确的指导。<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* [VMware安装win10系统的心路历程](https://download.csdn.net/download/weixin_38643407/14039812)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"] - *2* *3* [VMware虚拟机安装win10系统教程(超详细)](https://blog.csdn.net/q2524607033/article/details/131394143)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"] [ .reference_list ]

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值