我不能使用PythonKi在xcode11中导入Python模块

2024-04-20 09:34:40 发布

您现在位置:Python中文网/ 问答频道 /正文

我现在使用的是Swift包管理器。在

利用这个,我将PythonKit导入到我的Swift项目中。在

我现在无法使用PythonKit导入Python模块。在

它要求我设置PYTHON_库路径,但我不知道怎么做。在

有人能帮我吗?在

//
//  ViewController.swift
//  VideoStream
//
//  Created by HeRo Gold on 7/20/19.
//  Copyright © 2019 TopAce. All rights reserved.
//

import UIKit
import PythonKit

let sys = Python.import("sys")

class ViewController: UIViewController {

    @IBOutlet weak var netflixView: WKWebView!
    let netflixURL = URL(string: "https://www.netflix.com/login")

    override func viewDidLoad() {
        super.viewDidLoad()
        // Do any additional setup after loading the view.

        let pymsl = try Python.import(name: "pymsl")

        print("Python \(sys.version_info.major).\(sys.version_info.minor)")
        print("Python Version: \(sys.version)")
        print("Python Encoding: \(sys.getdefaultencoding().upper())")
    }
}

这是我在iPhone上运行iOS应用程序时的错误消息

Fatal error: Python library not found. Set the PYTHON_LIBRARY environment variable with the path to a Python library.: file /Users/herogold/Library/Developer/Xcode/DerivedData/VideoStream-cjytedddvtktmybclqlztmfdbekk/SourcePackages/checkouts/PythonKit/PythonKit/PythonLibrary.swift, line 40
2019-07-20 23:55:00.967869+0800 VideoStream[31841:170718] Fatal error: Python library not found. Set the PYTHON_LIBRARY environment variable with the path to a Python library.: file /Users/herogold/Library/Developer/Xcode/DerivedData/VideoStream-cjytedddvtktmybclqlztmfdbekk/SourcePackages/checkouts/PythonKit/PythonKit/PythonLibrary.swift, line 40


Tags: theimportinfoversionsyslibraryswiftprint
1条回答
网友
1楼 · 发布于 2024-04-20 09:34:40

首先回答,请原谅格式化/等等。我自己也经历了一段时间的不同错误,但通常是相同的问题。我希望这有助于您考虑一些资源:

1)Pyto一个用于iOS/Catalyst的完全嵌入式Python环境;使用LXML和Python库移植指令<;这是在iOS上运行所需的模型,我的解决方案适用于Mac Catalyst(预装了Python的Mac)

2)Python Kit Tutorial这家伙一步一步地讲述了如何实现PythonKit

以下是对我有效的方法:

1)在签名和功能中禁用应用程序沙盒:

In top right corner of App Sandbox, under Signing & Capabilities there is an "X", click that to remove App Sandbox

2)在“签名和功能”下的“强化运行时”:选中“禁用库验证”

Image of checkbox for Disable Library Validation

现在,我还没有根据这些规定向appstore提交应用程序,但至少我的python文件和库加载/构建/运行!在

相关问题 更多 >