Using Python with Swift

Now that the proposal has been merged is there an updated version of PythonGlue.swift that we can use?

What can I do right now to be able to use Python in my swift project?

Hi Alper,

There is no Xcode build that has @dynamicMemberLookup in it yet. You can try with an open source toolchain or wait until Swift 4.2 comes out in beta.

Oh, that said, nothing stops you from using the existing PythonGlue implementation. I posted a recent version of it here: Swift/Python interop library, Xcode 9.3b3 edition

I have updated the PythonKit package with basic @dynamicMemberLookup support for Swift 4.2.

I have also added support for camelCase to snake_case conversion so now you can do things like this:

import PythonKit

let sys = try Python.import("sys")

print("Python \(sys.versionInfo.major).\(sys.versionInfo.minor)")
print("Python Path: \(sys.path[0])")
print("Python Version: \(sys.version)")
2 Likes

Hey, I hope you're still active! I have a question, is that the computer gives an error that it can't find the library for python. Similar to this I found: https://forums.developer.apple.com/message/401515#401515 however it's not answered

Terms of Service

Privacy Policy

Cookie Policy