Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8775149
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T18:44:06+00:00 2026-06-13T18:44:06+00:00

I am looking for the best way to call Python code from Objective-C program.

  • 0

I am looking for the best way to call Python code from Objective-C program.
Few details:

  • Python’s code doesn’t use PyObjC at all, just Python’s basics.
  • There are several Python’s files with similar functionality each (aka “variations on a theme”).

NSBundle

Encapsulating each *.py into *.bundle was the first thing that has came into mind.

PythonClass.py:

import objc
NSObject = objc.lookUpClass('NSObject')

class PythonClass(NSObject):
    def Function(self):
        print("Python is speaking!")

setup.py:

from distutils.core import setup
import py2app

setup(
    plugin = ['PythonClass.py'],
)

Terminal command: python setup.py py2app -s -p objc

It works fine, but there are several problems:

  • Large *.bundle size. Even though Foundation is not imported, and bundle is semi standalone (flag “-s”), the size of the *.bundle is ~1MB. Is there any other way to reduce the size?
  • PyObjC dependance. Class doesn’t use objc, but if we don’t subclass NSObject then, on Objective-C side, [bundle principalClass] is (Null) and PythonClass cannot be instantiated. Is there a way to avoid using NSObject in *.py?

CFBundle

I have also been thinking about using CFBundle, but CFBundleGetFunctionPointerForName(...) always returns NULL (of course, in this case, *.py contains a function, not a class). I couldn’t find any material on this matter. Maybe some of you are more lucky.

Is there a better way of embedding Python into Objective-C?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T18:44:07+00:00Added an answer on June 13, 2026 at 6:44 pm

    Use Python/C API (a bridge between Python and C), C++ class (OOP layer for easier management) that calls Python code, and this method to put C++ class into CFBundle.

    If necessary, this also works with Dynamic Library (*.dylib) instead of CFBundle.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've been looking for a way to call Objective-C code from some JavaScript in
I'm looking for the best way to dynamically call a method from a different
What's the best way to call R functionality from within Java? I'm looking for
I'm looking for best way to initiate call from a web page, and am
I'm looking for the best way to select numbers directly from an in clause.
I'm looking for the best way to use a duration field in a Rails
I am looking for a best way to trigger windows application automation from Java
Basically I'm looking for the best way to remove the need to hard code
Looking at some code cleanup and I was wondering the best way to deal
I'm looking for best way of using session within zf application. At first I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.