我遇到了同样的问题,就我而言,我最近将我的 Xcode 更新到了 8.2.1 并且 swift 3.0 附带了它。
我得到了这个日志。
Ranvijay-Mac-mini:PerfectTemplate ranaranvijaysingh$ swift build
error: unable to invoke subcommand: /Library/Developer/CommandLineTools/usr/bin/swift-build (No such file or directory)
它所走的路径不正确。应该是这样的:
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin
要更改路径,请运行此命令。
export PATH=/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin:$PATH
然后完成。
在您的项目上再次运行:swift build,如果出现此错误。
xcrun: error: unable to lookup item 'PlatformPath' from command line tools installation
xcrun: error: unable to lookup item 'PlatformPath' in SDK '/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk'
error: Invalid platform path
那么您还需要更改 SDK 路径。
就我而言,我在路径中有两个 .sdk
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/
MacOSX.sdk MacOSX10.12.sdk
要知道您的 SDK 路径是什么,请运行此命令。
xcrun --sdk macosx --show-sdk-path
我的情况是这样的。
/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk
要更改它,请运行此命令。
sudo xcode-select -switch /Applications/Xcode.app/Contents/Developer
现在完成了。
现在尝试运行swift build。