简体   繁体   English

VS Code 命令面板中的 Flutter 找不到 git

[英]Flutter in VS Code command pallete doesn't find git

I've been trying to setup Flutter on my laptop without success.我一直在尝试在我的笔记本电脑上设置 Flutter,但没有成功。 The problem is most likely in the extensions or something in VS Code.问题最有可能出现在扩展或 VS Code 中。 I can run flutter commands from Powershell no problem.我可以从 Powershell 运行 flutter 命令没问题。 But the commands executed from the VS Code command palette report this:但是从 VS Code 命令面板执行的命令报告了这个:

[flutter] flutter doctor -v
'where' is not recognized as an internal or external command,
operable program or batch file.
Error: Unable to find git in your PATH. 
exit code 1

Which is weird, I do have git in my computer setup to work directly from Powershell as well - it's in PATH.这很奇怪,我的计算机设置中确实有 git 可以直接从 Powershell 工作 - 它在 PATH 中。 Also the GIT commands from VS Code available in the command palette work no problem.此外,命令面板中可用的 VS Code 中的 GIT 命令也没有问题。

Every log I've been able to check reports the above message or just the "where" part.我能够检查的每个日志都报告上述消息或仅报告“where”部分。

Please help, if you need any additional information, I'll gladly provide it.请帮助,如果您需要任何其他信息,我很乐意提供。 Thank you :)谢谢 :)

Edit #1: Flutter doctor generates a crash now.编辑 #1:Flutter doctor 现在产生崩溃。 It worked before, but now it's reporting errors.以前可以用,现在报错了。 This is the log it generates:这是它生成的日志:

```
Flutter crash report; please file at https://github.com/flutter/flutter/issues.

## command

flutter doctor

## exception

ArgumentError: Invalid argument(s): Cannot find executable for where.

```
#0      _getExecutable (package:process/src/interface/local_process_manager.dart:127:5)
#1      LocalProcessManager.runSync (package:process/src/interface/local_process_manager.dart:94:30)
#2      _WindowsUtils._which (package:flutter_tools/src/base/os.dart:239:49)
#3      OperatingSystemUtils.whichAll (package:flutter_tools/src/base/os.dart:52:43)
#4      AndroidSdk.locateAndroidSdk.findAndroidHomeDir (package:flutter_tools/src/android/android_sdk.dart:336:38)
#5      AndroidSdk.locateAndroidSdk (package:flutter_tools/src/android/android_sdk.dart:360:53)
#6      AppContext._generateIfNecessary.<anonymous closure> (package:flutter_tools/src/base/context.dart:100:41)
#7      _LinkedHashMapMixin.putIfAbsent (dart:collection-patch/compact_hash.dart:293:23)
#8      AppContext._generateIfNecessary (package:flutter_tools/src/base/context.dart:88:20)
#9      AppContext.get (package:flutter_tools/src/base/context.dart:117:32)
#10     AppContext.get (package:flutter_tools/src/base/context.dart:115:23)
#11     AppContext.get (package:flutter_tools/src/base/context.dart:115:23)
#12     androidSdk (package:flutter_tools/src/android/android_sdk.dart:19:38)
#13     AndroidWorkflow.canListDevices (package:flutter_tools/src/android/android_workflow.dart:45:41)
#14     AndroidDevices.canListAnything (package:flutter_tools/src/android/android_device.dart:62:47)
#15     DeviceManager.canListAnything.<anonymous closure> (package:flutter_tools/src/device.dart:148:80)
#16     Iterable.any (dart:core/iterable.dart:388:15)
#17     DeviceManager.canListAnything (package:flutter_tools/src/device.dart:148:33)
#18     _DefaultDoctorValidatorsProvider.validators (package:flutter_tools/src/doctor.dart:90:25)
#19     Doctor.validators (package:flutter_tools/src/doctor.dart:145:46)
#20     Doctor.startValidatorTasks (package:flutter_tools/src/doctor.dart:151:39)
#21     Doctor.diagnose (package:flutter_tools/src/doctor.dart:252:41)
#22     DoctorCommand.runCommand (package:flutter_tools/src/commands/doctor.dart:59:39)
#23     FlutterCommand.verifyThenRunCommand (package:flutter_tools/src/runner/flutter_command.dart:615:18)
#24     _asyncThenWrapperHelper.<anonymous closure> (dart:async-patch/async_patch.dart:73:64)
#25     _rootRunUnary (dart:async/zone.dart:1134:38)
#26     _CustomZone.runUnary (dart:async/zone.dart:1031:19)
#27     _FutureListener.handleValue (dart:async/future_impl.dart:139:18)
#28     Future._propagateToListeners.handleValueCallback (dart:async/future_impl.dart:680:45)
#29     Future._propagateToListeners (dart:async/future_impl.dart:709:32)
#30     Future._completeWithValue (dart:async/future_impl.dart:524:5)
#31     Future._asyncComplete.<anonymous closure> (dart:async/future_impl.dart:554:7)
#32     _rootRun (dart:async/zone.dart:1126:13)
#33     _CustomZone.run (dart:async/zone.dart:1023:19)
#34     _CustomZone.runGuarded (dart:async/zone.dart:925:7)
#35     _CustomZone.bindCallbackGuarded.<anonymous closure> (dart:async/zone.dart:965:23)
#36     _microtaskLoop (dart:async/schedule_microtask.dart:43:21)
#37     _startMicrotaskLoop (dart:async/schedule_microtask.dart:52:5)
#38     _runPendingImmediateCallback (dart:isolate-patch/isolate_patch.dart:118:13)
#39     _RawReceivePortImpl._handleMessage (dart:isolate-patch/isolate_patch.dart:175:5)
```

## flutter doctor

```
encountered exception: Invalid argument(s): Cannot find executable for where.

#0      _getExecutable (package:process/src/interface/local_process_manager.dart:127:5)
#1      LocalProcessManager.runSync (package:process/src/interface/local_process_manager.dart:94:30)
#2      _WindowsUtils._which (package:flutter_tools/src/base/os.dart:239:49)
#3      OperatingSystemUtils.whichAll (package:flutter_tools/src/base/os.dart:52:43)
#4      AndroidSdk.locateAndroidSdk.findAndroidHomeDir (package:flutter_tools/src/android/android_sdk.dart:336:38)
#5      AndroidSdk.locateAndroidSdk (package:flutter_tools/src/android/android_sdk.dart:360:53)
#6      AppContext._generateIfNecessary.<anonymous closure> (package:flutter_tools/src/base/context.dart:100:41)
#7      _LinkedHashMapMixin.putIfAbsent (dart:collection-patch/compact_hash.dart:293:23)
#8      AppContext._generateIfNecessary (package:flutter_tools/src/base/context.dart:88:20)
#9      AppContext.get (package:flutter_tools/src/base/context.dart:117:32)
#10     AppContext.get (package:flutter_tools/src/base/context.dart:115:23)
#11     androidSdk (package:flutter_tools/src/android/android_sdk.dart:19:38)
#12     AndroidWorkflow.canListDevices (package:flutter_tools/src/android/android_workflow.dart:45:41)
#13     AndroidDevices.canListAnything (package:flutter_tools/src/android/android_device.dart:62:47)
#14     DeviceManager.canListAnything.<anonymous closure> (package:flutter_tools/src/device.dart:148:80)
#15     Iterable.any (dart:core/iterable.dart:388:15)
#16     DeviceManager.canListAnything (package:flutter_tools/src/device.dart:148:33)
#17     _DefaultDoctorValidatorsProvider.validators (package:flutter_tools/src/doctor.dart:90:25)
#18     Doctor.validators (package:flutter_tools/src/doctor.dart:145:46)
#19     Doctor.startValidatorTasks (package:flutter_tools/src/doctor.dart:151:39)
#20     Doctor.diagnose (package:flutter_tools/src/doctor.dart:252:41)
#21     _doctorText.<anonymous closure> (package:flutter_tools/runner.dart:205:26)
#22     AppContext.run.<anonymous closure> (package:flutter_tools/src/base/context.dart:146:29)
#23     _rootRun (dart:async/zone.dart:1126:13)
#24     _CustomZone.run (dart:async/zone.dart:1023:19)
#25     _runZoned (dart:async/zone.dart:1518:10)
#26     runZoned (dart:async/zone.dart:1465:12)
#27     AppContext.run (package:flutter_tools/src/base/context.dart:145:18)
#28     _doctorText (package:flutter_tools/runner.dart:204:19)
#29     _createLocalCrashReport (package:flutter_tools/runner.dart:182:32)
#30     _handleToolError (package:flutter_tools/runner.dart:138:31)
<asynchronous suspension>
#31     run.<anonymous closure>.<anonymous closure> (package:flutter_tools/runner.dart:68:22)
<asynchronous suspension>
#32     _rootRun (dart:async/zone.dart:1126:13)
#33     _CustomZone.run (dart:async/zone.dart:1023:19)
#34     _runZoned (dart:async/zone.dart:1518:10)
#35     runZoned (dart:async/zone.dart:1502:12)
#36     run.<anonymous closure> (package:flutter_tools/runner.dart:61:18)
<asynchronous suspension>
#37     AppContext.run.<anonymous closure> (package:flutter_tools/src/base/context.dart:146:29)
#38     _rootRun (dart:async/zone.dart:1126:13)
#39     _CustomZone.run (dart:async/zone.dart:1023:19)
#40     _runZoned (dart:async/zone.dart:1518:10)
#41     runZoned (dart:async/zone.dart:1465:12)
#42     AppContext.run (package:flutter_tools/src/base/context.dart:145:18)
#43     runInContext (package:flutter_tools/src/context_runner.dart:64:24)
#44     run (package:flutter_tools/runner.dart:50:10)
#45     main (package:flutter_tools/executable.dart:65:9)
#46     main (file:///C:/b/s/w/ir/k/archive/flutter/packages/flutter_tools/bin/flutter_tools.dart:8:3)
#47     _startIsolate.<anonymous closure> (dart:isolate-patch/isolate_patch.dart:305:32)
#48     _RawReceivePortImpl._handleMessage (dart:isolate-patch/isolate_patch.dart:174:12)
```

I had the same problem when I upgraded to flutter 1.19.0-3 and I solved it.我在升级到 flutter 1.19.0-3 时遇到了同样的问题,我解决了。 This issue is likely caused by the "path variable", I suggest you make sure that your path contains all of the following routes.此问题可能是由“路径变量”引起的,建议您确保您的路径包含以下所有路由。 'system32, Git bin, flutter bin and powershell'. 'system32、Git bin、flutter bin 和 powershell'。 If you are using Windows, these routes are usually the following, so you can copy the following lines into your 'path variable'.如果您使用的是 Windows,这些路由通常如下所示,因此您可以将以下行复制到您的“路径变量”中。

C:\Windows\System32;
C:\Program Files\Git\bin
C:\flutter\bin;
%systemroot%\System32\WindowsPowerShell\v1.0\;
%SystemRoot%\system32;%SystemRoot%;

将 git desktop 安装到您的计算机上并重新启动您的 IDE。

So, what I was missing C:\\Windows\\System32 value from my PATH variable.所以,我在PATH变量中缺少C:\\Windows\\System32值。 I had the Powershell in my PATH but not System32.我的 PATH 中有 Powershell,但没有 System32。 To get Flutter working you need both.要让 Flutter 工作,你需要两者。

My advice to anyone having a similar error is, check the default values of the PATH variable and set them back :)我对任何有类似错误的人的建议是,检查 PATH 变量的默认值并将它们重新设置:)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM