Can Not Import Tensorflow for Swift in Xcode Playground

Cannot import tensorflow in Swift playground

Answers to your queries:

  1. Swift Playgrounds are not yet supported (available in future) by S4TF toolchains.
  2. You can only build app for macOS right now but support for other OSs will be available in future.
  3. Before you run your Swift file via CMD you need to export PATH=/Library/Developer/Toolchains/{swift-toolchain}/usr/bin/"${PATH}" where you should replace {swift-toolchain} with your S4TF toolchain name (clicking tab will suggest you available toolchains on your system). Then running swift test.swift will be (hopefully) successful.

Note: S4TF is still in early stage of development & is ready for beginners and researchers to work with it. But I personally feel that if you're developing an app for iOS it's a little early. I hope Apple with announce this feature in WWDC either in 2020 or 2021.

I hope this was helpful!

-- Rahul Bhalley

Swift for TensorFlow `error: Couldn't lookup symbols: type metadata accessor for TensorFlow.Tensor`

Ok, it seems to be a known issue -
https://github.com/tensorflow/swift/issues/173

I can't use Python module in Swift

A year later, I got a solution.
The name of module was wrong.

import PythonKit
let np = Python.import("numpy")

I should have installed on this way and implemented this way exactly.

Thanks regards!

Xcode: 11.3.1

Swift: 4.2

Toolchain: Swift for TensorFlow 0.8 Release

swift playground error: module 'Python' has no member named 'import'

A few things to check.

  1. Presumably you're using the swift / tensorflow toolchain from latest download link here (and you've configured Xcode to use it.
    View Xcode’s (Preferences, Components > Toolchains, and select the installed Swift for TensorFlow toolchain.)
    https://github.com/tensorflow/swift/blob/master/Installation.md

  2. Make sure you change the Xcode build system to legacy (File > Project Settings > Build System).

  3. Check the runtime search path
    /Library/Developer/Toolchains/swift-latest/usr/lib/swift/macosx

UPDATE:
Have a look at XcodeGen which can automagically create an xcode project with relevant settings for swift for tensorflow.
I crafted a project.yml file here

DO NOT include libppython2.7.tbd in the linked frameworks. tensorflow will automagically find relevant python version 3 or 2.

OSLog Logger doesn't work on XCode Playground: Couldn't lookup symbols: ___dso_handle

There is a workaround to work with Logger on Playgrounds. You should make new file inside your playground (e.g. Sources/Log.swift) and implement code there:

// Log.swift

import os

let logger = Logger()

public func log(_ text: String) {
logger.log("\(text)")
}
// MyLog.playground

log("Hello OSLog")

Got a fatal error saying JVP does not exist. Differential-first differentiation APIs are experimental and should not be used.

You're seeing that error because you're attempting to take a forward-mode derivative, and support for that hasn't yet been implemented in the Swift automatic differentiation system. The current implementation supports reverse-mode differentiation, so you can use the gradient operator instead to obtain the result you want:

@differentiable
func f(_ x: Float) -> Float {
x * x
}
let dfdx = gradient(of: f)
dfdx(3) // 6

Forward-mode differentiation support is in the works, but the focus is presently on upstreaming the reverse-mode implementation and refining that first. As a disclaimer, I work on the Swift for TensorFlow team.



Related Topics



Leave a reply



Submit