使用PYTHON库的路径设置PYTHON_库环境变量

2024-09-27 07:35:06 发布

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

我正在Xcode 11.4.1中开发一个iOS单视图应用程序 我在文件中添加了pythonkit框架>;Swift套餐>;添加包依赖性并添加git repo:https://github.com/pvieito/PythonKit.git

My project tree looks like this

当我尝试导入pythonkit并在“ViewController.swift”中使用它时:

import UIKit
import PythonKit

class ViewController: UIViewController {

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

func myfunc(){
    print("Hello...")
    print(Python.version)
    }
}

它给出了以下错误:

Fatal error: Python library not found. Set the PYTHON_LIBRARY environment variable with the 
path to a Python library.: file 
/Users/sayansen/Library/Developer/Xcode/DerivedData/TestApp1-cjzcpyjbchjbrlbzuhbvpjlsttfp/SourcePackages/checkouts/PythonKit/PythonKit/PythonLibrary.swift, 
line 40
2020-05-06 17:42:27.320360+0530 TestApp1[35313:1897321] Fatal error: Python library not found. Set the PYTHON_LIBRARY environment variable with the path to a Python library.: file /Users/sayansen/Library/Developer/Xcode/DerivedData/TestApp1-cjzcpyjbchjbrlbzuhbvpjlsttfp/SourcePackages/checkouts/PythonKit/PythonKit/PythonLibrary.swift, line 40
(lldb) 

我试图在xcode中为MacOS构建一个“命令行工具”。在那个项目中,我添加了上面提到的pythonkit框架,它工作起来很有魅力! 为什么这个错误发生在iOS应用程序而不是Mac OS应用程序上

注意:我已经试过了this simmilar post 请帮帮我


Tags: theimportgitgt框架应用程序libraryxcode
2条回答

我用PythonKit来支持iOShttps://github.com/kewlbear/PythonKit此Swift包将通过依赖关系将Python嵌入到您的应用程序中

我们可以如下安装PythonKit。请从项目文件夹中创建macOS应用程序,并按照以下步骤操作

  1. 转到文件->;Swift套餐->;添加Swift包
  2. 输入url作为“https://github.com/pvieito/PythonKit.git
  3. 然后继续这个过程
  4. 在签名和功能中禁用应用程序沙盒
  5. 在签名和功能下的“强化运行时”中:选中“禁用库验证”

Pythonkit也适用于macOS、Linux和Windows。它的要求没有具体说明iOS。iOS没有任何python解释器,因此无法识别“python”。 希望这有帮助

相关问题 更多 >

    热门问题