如何通过包管理器安装Swift包?

时间:2023-01-24 07:39:20

I am currently following the document from swift.org to play around with the new Swift Package Manager.

我目前正在关注swift.org上的文档,以使用新的Swift Package Manager。

I cloned the demo project from Github and run the following command from terminal.

我从Github克隆了演示项目,并从终端运行以下命令。

git clone https://github.com/apple/example-package-dealer.git
cd example-package-dealer
swift build
.build/debug/Dealer

While I run swift build, error arise.

当我运行快速构建时,会出现错误。

<unknown>:0: error: no such file or directory: 'build'

Any idea?

任何想法?

4 个解决方案

#1


18  

I stuck for an hour. Sadly, it's just an epic fail that downloading the wrong swift package. If you want to use swift build, MAKE SURE you download the development version.

我坚持了一个小时。可悲的是,下载错误的swift包只是一个史诗般的失败。如果你想使用swift build,请确保下载开发版本。

#2


6  

You did not add the newly installed swift to your PATH. The instructions for doing that are here.

您没有将新安装的swift添加到PATH中。这样做的说明。

On OS X:

在OS X上:

export PATH=/Library/Developer/Toolchains/swift-latest.xctoolchain/usr/bin:"${PATH}"

On Linux:

在Linux上:

export PATH=/path/to/Swift/usr/bin:"${PATH}"

Then to test it works:

然后测试它的工作原理:

swift build --version

#3


3  

I think it is a problem with the latest snapshot:

我认为这是最新快照的问题:

  • Ubuntu 14.04 Swift 2.2 Snapshot of January 11 contains swift-build in usr/bin
  • Ubuntu 14.04 Swift 2.2 1月11日的快照包含了usr / bin中的swift-build
  • Ubuntu 14.04 Swift 2.2 Snapshot of January 25 doesn't contain swift-build in usr/bin
  • Ubuntu 14.04 Swift 2.2 1月25日的快照不包含usr / bin中的swift-build

Besides, the January 25 release also seems to miss other files (libFoundation.so and libXCTest.so in usr/lib/swift/linux for instances).

此外,1月25日版本似乎也错过了其他文件(例如usr / lib / swift / linux中的libFoundation.so和libXCTest.so)。

Either there has been a structure change....or, simply, the latest snapshot had a problem ;) While they fix the snapshot, simply take the older (January 11th) snapshot, and you should be fine.

要么发生了结构变化....或者,简单地说,最新的快照有问题;)当他们修复快照时,只需要拍摄较旧的(1月11日)快照,你应该没问题。

#4


3  

I was facing the same issue and in my case, I recently updated my Xcode to 8.2.1 and swift 3.0 comes with it. I was getting this log.

我遇到了同样的问题,在我的情况下,我最近将我的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)

The path it was taking was incorrect. It was suppose to be:

它采取的路径是不正确的。它被认为是:

/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin


To change the path, run this command.

要更改路径,请运行此命令。

export PATH=/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin:$PATH

And DONE.
Run : swift build again on your project and if you get this error.

并做了。在您的项目上运行: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

then you need to change the SDK path as well.
In my case, I had two .sdk at path

那么你也需要改变SDK路径。在我的情况下,我在路径上有两个.sdk

/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/ 

MacOSX.sdk  MacOSX10.12.sdk

To know what is your SDK path, run this command.

要了解SDK路径是什么,请运行此命令。

xcrun --sdk macosx --show-sdk-path

My case i got this.

我的情况我得到了这个。

/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk

To change it run this command.

要更改它,请运行此命令。

sudo xcode-select -switch /Applications/Xcode.app/Contents/Developer

and NOW DONE. Try running swift build now.

现在就完成了。尝试现在运行swift build。

#1


18  

I stuck for an hour. Sadly, it's just an epic fail that downloading the wrong swift package. If you want to use swift build, MAKE SURE you download the development version.

我坚持了一个小时。可悲的是,下载错误的swift包只是一个史诗般的失败。如果你想使用swift build,请确保下载开发版本。

#2


6  

You did not add the newly installed swift to your PATH. The instructions for doing that are here.

您没有将新安装的swift添加到PATH中。这样做的说明。

On OS X:

在OS X上:

export PATH=/Library/Developer/Toolchains/swift-latest.xctoolchain/usr/bin:"${PATH}"

On Linux:

在Linux上:

export PATH=/path/to/Swift/usr/bin:"${PATH}"

Then to test it works:

然后测试它的工作原理:

swift build --version

#3


3  

I think it is a problem with the latest snapshot:

我认为这是最新快照的问题:

  • Ubuntu 14.04 Swift 2.2 Snapshot of January 11 contains swift-build in usr/bin
  • Ubuntu 14.04 Swift 2.2 1月11日的快照包含了usr / bin中的swift-build
  • Ubuntu 14.04 Swift 2.2 Snapshot of January 25 doesn't contain swift-build in usr/bin
  • Ubuntu 14.04 Swift 2.2 1月25日的快照不包含usr / bin中的swift-build

Besides, the January 25 release also seems to miss other files (libFoundation.so and libXCTest.so in usr/lib/swift/linux for instances).

此外,1月25日版本似乎也错过了其他文件(例如usr / lib / swift / linux中的libFoundation.so和libXCTest.so)。

Either there has been a structure change....or, simply, the latest snapshot had a problem ;) While they fix the snapshot, simply take the older (January 11th) snapshot, and you should be fine.

要么发生了结构变化....或者,简单地说,最新的快照有问题;)当他们修复快照时,只需要拍摄较旧的(1月11日)快照,你应该没问题。

#4


3  

I was facing the same issue and in my case, I recently updated my Xcode to 8.2.1 and swift 3.0 comes with it. I was getting this log.

我遇到了同样的问题,在我的情况下,我最近将我的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)

The path it was taking was incorrect. It was suppose to be:

它采取的路径是不正确的。它被认为是:

/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin


To change the path, run this command.

要更改路径,请运行此命令。

export PATH=/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin:$PATH

And DONE.
Run : swift build again on your project and if you get this error.

并做了。在您的项目上运行: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

then you need to change the SDK path as well.
In my case, I had two .sdk at path

那么你也需要改变SDK路径。在我的情况下,我在路径上有两个.sdk

/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/ 

MacOSX.sdk  MacOSX10.12.sdk

To know what is your SDK path, run this command.

要了解SDK路径是什么,请运行此命令。

xcrun --sdk macosx --show-sdk-path

My case i got this.

我的情况我得到了这个。

/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk

To change it run this command.

要更改它,请运行此命令。

sudo xcode-select -switch /Applications/Xcode.app/Contents/Developer

and NOW DONE. Try running swift build now.

现在就完成了。尝试现在运行swift build。