在iOS Swift项目中使用Python库

时间:2017-08-30 11:00:15

标签: python ios swift py2app

我想在我的iOS应用程序中使用这个Python库,所以我一直在探索如何做到这一点。 我已经走了很远,使用py2app创建了一个包含我的Python安装的包(有点基于这篇文章:https://github.com/ndevenish/Site-ndevenish/blob/master/_posts/2017-04-11-using-python-with-swift-3.markdown,没有符号链接)。 所以我有import UIKit let path = Bundle.main.path(forResource: "Bridge", ofType: "plugin") guard let pluginbundle = Bundle(path: path!) else { fatalError("Could not load python plugin bundle") } pluginbundle.load() let ret = UIApplicationMain( CommandLine.argc, UnsafeMutableRawPointer(CommandLine.unsafeArgv) .bindMemory( to: UnsafeMutablePointer<Int8>.self, capacity: Int(CommandLine.argc)), nil, NSStringFromClass(AppDelegate.self) ) exit(ret) 文件加载我的包,但是当应用加载而不是在主文件上查看消息时,我收到错误。

  

加载时出错   /Users/blablabla/Library/Developer/CoreSimulator/Devices/C465435B-4EF3-4CDC-98E7-9ACF11C6736C/data/Containers/Bundle/Application/29C18165-D120-447E-A912-F4B4AFC77966/MyPython.app/Bridge.plugin/Contents / MacOS的/桥:   的dlopen(/Users/blablabla/Library/Developer/CoreSimulator/Devices/C465435B-4EF3-4CDC-98E7-9ACF11C6736C/data/Containers/Bundle/Application/29C18165-D120-447E-A912-F4B4AFC77966/MyRDP.app/Bridge.plugin / Contents / MacOS / Bridge,265):找不到合适的图像。找到了:
    /Users/blablabla/Library/Developer/CoreSimulator/Devices/C465435B-4EF3-4CDC-98E7-9ACF11C6736C/data/Containers/Bundle/Application/29C18165-D120-447E-A912-F4B4AFC77966/MyPython.app/Bridge.plugin/Contents / MacOS的/桥:   mach-o,但不适用于iOS模拟器

我应该怎样做才能让它发挥作用?下面我将发布一些我的文件:

main.swift

 """Bridge.py. The main Python-(Swift) plugin bundle entry module"""
import logging

logger = logging.getLogger(__name__)
logging.basicConfig(level=logging.INFO)

logger.info("Loaded python bundle")

Bridge.py(位于我的项目根文件夹中)

"""Setuptools setup for creating a .plugin bundle"""
from setuptools import setup

APP = ['Bridge.py']
OPTIONS = {
  # Any local packages to include in the bundle should go here.
  # See the py2app documentation for more
  "includes": ['mylib'], 
}

setup(
    plugin=APP,
    options={'py2app': OPTIONS},
    setup_requires=['py2app'],
    install_requires=['pyobjc'],
)

最后,来自py2app的setup.py

{{1}}

0 个答案:

没有答案