Python.import with Xcode 10

Hi,

Dynamic member lookup was implemented in Swift 4.2.

Why is it then that when I do Python.import I'm getting an error?

I found a way to work around this by installing the TensorFlow toolchain and configuring the build system to use "Legacy" (more details at this SO answer) but I'm if that's the right path to go?

I'm hoping to use our python based code base in a new Swift project.

EDIT

Xcode 10.1

Maxims-MacBook-Pro:ontology-backend maximveksler$ swift --version
Apple Swift version 4.2.1 (swiftlang-1000.11.42 clang-1000.11.45.1)
Target: x86_64-apple-darwin18.0.0

Hi Max,

Im in the same boat.. how do you even get that far, though? import Python doesn't work.

In your last link, the steps 3 and 4 I'm not sure are working for me:

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

-- so I've added that after the defaults:
$(inherited)
@executable_path/Frameworks
/Library/Developer/Toolchains/swift-latest/usr/lib/swift/macosx

  1. make sure you've included libpython2.7.tbd (optional libtensorflow.so / libtensorflow_framework.so) in the linked frameworks.

Libppython is not there (and why is that 2.7??)

If you need Python interoperability but not the TensorFlow capabilities, I'd suggest using the official swift.org toolchain and use @pvieito's PythonKit as a SwiftPM package.

TensorFlow toolchains come from the tensorflow branch which is in flux and not stable.

1 Like