Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Importing Modules #2 #8

Closed
IvanNextToJunior opened this issue Feb 25, 2022 · 4 comments
Closed

Importing Modules #2 #8

IvanNextToJunior opened this issue Feb 25, 2022 · 4 comments

Comments

@IvanNextToJunior
Copy link

I would like to know how to import Python modules. I tried to use it like this:

override func viewDidLoad() {
super.viewDidLoad()
PythonSupport.initialize()
}
extension PlayerViewController: PlayerDelegate {

func play() {
    
    guard
        let url = URL(string: audioString)
    
    else {
        return
    }
    url.insertPythonPath()
@kewlbear
Copy link
Owner

Basically, you add the path to the module, then import it.

let sys = Python.import("sys")
sys.path.insert(1, pathToModule)
let module = Python.import("module")

See https://github.com/kewlbear/YoutubeDL-iOS/blob/811ea597014bc483f44737a1d80c54d0896c36b0/Sources/YoutubeDL/YoutubeDL.swift#L147 for more sophisticated example.

@IvanNextToJunior
Copy link
Author

IvanNextToJunior commented Feb 28, 2022

Thank you! And what is the major version of your PythonKit package? I put 0.0.1 in swift package manager, but it gave me an error

@kewlbear
Copy link
Owner

kewlbear commented Mar 2, 2022

You should not use my fork. Use https://github.com/pvieito/PythonKit.

@IvanNextToJunior
Copy link
Author

Thank you

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants