Giter VIP home page Giter VIP logo

python-ios's Introduction

Python-iOS

This swift package enables you to use python modules in your iOS apps.

Installation

.package(url: "https://github.com/kewlbear/Python-iOS.git", from: "0.1.1-b")

Usage

import PythonSupport

PythonSupport.initialize()

If you want to build XCFrameworks yourself, see https://github.com/kewlbear/kivy-ios.

License

MIT

python-ios's People

Contributors

kewlbear avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

python-ios's Issues

Importing Modules

Hi again!

I've been experimenting the current implementation some when I try to import specific modules I get the following error:

Fatal error: 'try!' expression unexpectedly raised an error: Python exception: No module named 'numpy': file PythonKit/Python.swift, line 674
2021-02-28 22:10:32.622406-0500 PythonPlayground[76992:6218680] Fatal error: 'try!' expression unexpectedly raised an error: Python exception: No module named 'numpy': file PythonKit/Python.swift, line 674
(lldb)

This error resulted adding this line below line 41 of the ContentView file (let sys = Python.import("sys"):
let np = Python.import("numpy")

Do I need to need to have the modules pre-installed in a specific location (on my hard drive or in the app bundle) for me to be able to import them, and how would I go about doing that?

Thanks again!

How to add requirements ?

How to add requirements library ? Should I implement a requirements.txt file in the assets or there is another way ?

Crash on iOS16

I get a crash on iOS16

#0 (null) in assertionFailure(:_:file:line🎏) ()
#1 (null) in swift_unexpectedError ()
#2 (null) in specialized static PythonLibrary.loadSymbol(name:legacyName:type:) ()
#3 (null) in specialized static PythonLibrary.loadSymbol(name:legacyName:type:) ()
#4 (null) in one-time initialization function for Py_Initialize ()
#7 0x000000010044995c in Py_Initialize.unsafeMutableAddressor
#8 0x000000010044995c in PythonInterface.init()

In debug I working, once archived and released it crashes

where I'm wrong ? :)
Thanks

The libcrypto symbols are conflicting when Python-iOS framework is used along with AmazonFling frameworks.

Example warning :
ld: warning: duplicate symbol '_CRYPTO_memcmp' in:
/Users/nandishbellad/Development/TestYoutubeApp/TestPythonApp/AmazonFling.framework/AmazonFling(cryptlib.o)
/Users/nandishbellad/Library/Developer/Xcode/DerivedData/TestPythonApp-akquhzlstsszvfdavaajjevmysua/Build/Products/Debug-iphoneos/libcrypto.a(arm64cpuid.o)

Amazon Fling framework is using libcrypto internally and so we can just delete the the duplicate symbol in AmazonFling framework using lipo and ar commands. However , I think Amazon framework is using old openssl version code , so when removed some to the apis are not there in latest version of openssl that Python-iOS uses.

Can I get the Python-iOS framework with old version of openssl, probably 1.0.2?

This is not work why ? Is it the right way ?

I did this swiftUI code, its working without error, but also without python results!

The expected thing is to open a new safari tab on the iOS with the URL, but its not!:

import SwiftUI
import PythonSupport
import LinkPython

struct ContentView: View {
    var body: some View {
        VStack {
            Image(systemName: "globe")
                .imageScale(.large)
                .foregroundColor(.accentColor)
            Text("Hello, world!")
                .onSubmit {
                    PythonSupport.initialize()
                    PythonRunSimpleString("""
import webbrowser
webbrowser.open ("https://apple.com")
""")
                }
        }
        .padding()
    }
}

App crashes when I deploy it on my physical device

Hello there,

I'm using the library sympy and imported it. In the simulator, everything is working fine but as soon as I deploy on my physical device the app crashes with

PythonKit/Python.swift:682: Fatal error: 'try!' expression unexpectedly raised an error: Python exception: No module named 'sympy'

as soon as I execute a function which uses that library. I have tried to insert a copy of the sympy folder at /Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/ into my bundle but that didn't work out either. I additionally disabled Bitcode and set the Strip Style to Debugging Symbols.

What am I doing wrong?

App crashes in Testflight

Hello.

I've been able to successfully integrate it in my iOS project and works well in release mode.
Bit, when I archive it and open it through Testflight the app crashes.
Error is "PythonKit Fatal error: Python library not found."

[My tries during 1 week]
I tried "Enable Bitcode" and "Strip Style" all yes or all no.
updated Python package (update package)
PythonSupport.initialize() in appdelegate.wift
I read all issue in your project for python-ios, pythonkit ..

[My config]
Xcode 13.3.1
IOS14/15

How can I resolve this issue?

Thank you.

Mac support

I currently use this on ios but would like to know if it is possible to build this package for mac arm64 and x86_64 architectures? I cannot use catalyst and need to re-use the same code for my mac app version. I don't want to rely on the installed mac python version but use this embedded python exactly as on my ios app.
I saw it uses precompiled libssl and libcrypto as dependencies. if i compiled my own version of these libraries for mac and use them as dependency, will it work?

Swift UI example?

Hi @kewlbear,

Thank you for this incredible package! I've been struggling to find something like this for the last week.

Question: I have a large iOS app that's about 90% written to which I need to add this PythoKit-iOS functionality. Do you by any chance have an example of the example app written in UIKit, as opposed to SwiftUI?

Thanks again for putting together this package!

Importing Modules #2

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()

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.