Use `swiftenv` in toolchain installation instructions
The current macOS toolchain installation instructions are copied from https://swift.org/download:

However, $PATH and xcrun --toolchain swift are not the easiest to work with. There have been multiple issues over time:
- https://github.com/tensorflow/swift/issues/331
- https://github.com/tensorflow/swift/pull/345
The swiftenv Swift version manager is much easier to use. It works nicely with Swift for TensorFlow macOS toolchains - I've personally used it since 2018 and never had any issues.
Example usage:
$ swiftenv versions # list available versions
tensorflow-DEVELOPMENT-2019-12-22-a
tensorflow-RELEASE-0.5
tensorflow-RELEASE-0.6
5.1.1
* 5.1.2 (set by /Users/danielzheng/.swiftenv/version)
$ swiftenv global tensorflow-DEVELOPMENT-2019-12-22-a # set global version
$ swiftenv global # print global version
tensorflow-DEVELOPMENT-2019-12-22-a
$ swift # use toolchain set by swiftenv
Welcome to Swift version 5.2-dev (Swift a34e25915a).
Type :help for assistance.
1> import TensorFlow
2>
The last time I tried, I couldn't figure out how to use swiftenv easily with Swift for TensorFlow Linux toolchains. That's also worth investigating.
Ooooh very much 👍 to this
Hi @dan-zheng I took your advice and install the swiftenv. I set the global env to be the S4TF, but when I use swift in command-line, it is still the apple version. Do you have any suggestions? thx! I can run S4TF in Xcode but not in command-line
$ ~ % swiftenv versions
* tensorflow-RELEASE-0.9
5.2.4
$ ~ % swiftenv global
tensorflow-RELEASE-0.9
$ ~ % swift
Welcome to Apple Swift version 5.2.4 (swiftlang-1103.0.32.9 clang-1103.0.32.53).
Type :help for assistance.
1>
@BenLucas7: it seems like swiftenv is working correctly. Did you add swiftenv to your PATH (step 2)?
I follow the instruction to install via Homebrew and configure the shims and completions for ZSH. But is still Apple version Swift.
$ echo $PATH
/Users/Lucas/.swiftenv/shims:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Applications/VMware Fusion.app/Contents/Public:/Library/TeX/texbin:/usr/local/aria2/bin:/opt/X11/bin:/Library/Apple/usr/bin:/opt/ImageMagick/bin:/Applications/Wireshark.app/Contents/MacOS:/Users/Lucas/.swiftenv/bin:/Users/Lucas/.vim/plugged/fzf/bin:/Users/Lucas/bin
Btw, if I also change ~/.bash_profile, this error occurs
<unknown>:0: error: The Swift for TensorFlow toolchain does not support the Swift REPL. Colab
(https://github.com/tensorflow/swift/blob/master/Usage.md#colaboratory) and Swift-Jupyter
(https://github.com/google/swift-jupyter) are supported alternatives.
@BenLucas7 @dan-zheng Take a look at this https://stackoverflow.com/questions/11530090/adding-a-new-entry-to-the-path-variable-in-zsh Having migrated to ZSH with Catalina macOS, you may stumble upon a few issues when setting variables the old way. Can you locate your .zshrc and edit it instead? Also check this method: https://stackoverflow.com/questions/11530090/adding-a-new-entry-to-the-path-variable-in-zsh/18077919#18077919
Hi, @8bitmp3 thx for your reply. Could you be more specific about what to edit to .zshrc?
I tried to add export PATH=/Library/Developer/Toolchains/swift-latest/usr/bin:"${PATH}" into .zshrc, and faild to activate S4TF in terminal. I also tried to reinstall swiftenv and modified the .zshenv as suggested. Faild again.
@BenLucas7 @dan-zheng Wonder if it has to do with macOS accounts created pre-Catalina and therefore still relying on bash 3.2 even after enabling ZSH (%). There's a good write-up on moving to ZSH I'm reading write now to understand this issue better https://scriptingosx.com/2019/06/moving-to-zsh/ I've a had a few variable exports not working since trying ZSH but I can return back to bash to again. Fyi, use ~/.zshrc not the one in `/etc/). 🤷♂️
@BenLucas7 @dan-zheng judging by your output
$ ~ % swiftenv versions
* tensorflow-RELEASE-0.9
5.2.4
$ ~ % swiftenv global
tensorflow-RELEASE-0.9
You set v0.9 as global and the ran swift.
Have you tried reinstalling/reregistering the Xcode toolkit with xcode-select --install before running swift again? Source: https://ma.ttias.be/mac-os-xcrun-error-invalid-active-developer-path-missing-xcrun/
@BenLucas7 @dan-zheng Ok, I got a similar issue, maybe it's not ZSH.
-
swiftenvhas been installed. - Ran
xcode-select --installin the terminal to reregister the toolkit. - Deleted Xcode and installed a fresh copy via the AppStore
- Launched Xcode - it downloaded some new components.
- Downloaded
tensorflow-RELEASE-0.9and installed the toolkit. -
swiftenvlists v0.9 along with the main Swift toolkit.
Then:
$ swiftenv global tensorflow-RELEASE-0.9
$ swiftenv version
> tensorflow-RELEASE-0.9 (set by .../.swiftenv/version)
$ swift
> Welcome to Apple Swift version 5.2.4 (swiftlang-1103.0.32.9 clang-1103.0.32.53).
> Type :help for assistance.
> import TensorFlow
> ...
> struct MLPClassifier {
> var w1 = Tensor<Float>(repeating: 0.1, shape: [2, 4])
...
Returns error: use of unresolved identifier 'Tensor'. Same with tanh(...) > error: use of unresolved identifier 'matmul'. Note that import TensorFlow is Ok. 🤔
YES! This is what I exactly met, import TensorFlow is ok, but can not create a Tensor, the error message is the same with you error: use of unresolved identifier 'Tensor'. I tried for two days and already gave up 😂... Maybe writing inside Xcode is more suitable for me...
I think they've dropped the support for REPL with newer toolchains. But @8bitmp3 I don't know how could you launch S4TF in REPL mode in terminal because I get error on tensorflow-RELEASE-0.9 toolchain.
% swiftenv global tensorflow-RELEASE-0.9
% swift
<unknown>:0: error: The Swift for TensorFlow toolchain does not support the Swift REPL. Colab (https://github.com/tensorflow/swift/blob/master/Usage.md#colaboratory) and Swift-Jupyter (https://github.com/google/swift-jupyter) are supported alternatives.
Yes indeed, the REPL is not supported in 0.9 S4TF toolchain.
From your version, It looks like the swift that you're launching is from an Apple toolchain from Xcode. Notice the "Apple Swift version" below:
Welcome to Apple Swift version 5.2.4 (swiftlang-1103.0.32.9 clang-1103.0.32.53).
Thanks,
Ewa
On Sun, Jun 14, 2020 at 6:54 PM ਰਾਹੁਲ ਭੇਲੇ [email protected] wrote:
I think they've dropped the support for REPL with newer toolchains. But @8bitmp3 https://github.com/8bitmp3 I don't know how could you launch S4TF in REPL mode in terminal because I get error on tensorflow-RELEASE-0.9 toolchain.
% swiftenv global tensorflow-RELEASE-0.9 % swift
:0: error: The Swift for TensorFlow toolchain does not support the Swift REPL. Colab (https://github.com/tensorflow/swift/blob/master/Usage.md#colaboratory) and Swift-Jupyter (https://github.com/google/swift-jupyter) are supported alternatives. — You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/tensorflow/swift/issues/360#issuecomment-643861786, or unsubscribe https://github.com/notifications/unsubscribe-auth/ADUMI3U5SR2HKVKCKOMFU3TRWV5MVANCNFSM4KFD6QBQ .
Thanks @ematejska. Without the read eval print loop support, what do you and the team suggest we do to have CLI support here when using swiftenv?