beeware / Python-iOS-template

A cookiecutter template for creating an iOS project running Python code.
MIT License
303 stars 36 forks source link

Problem importing PyObjC in `app_packages` #29

Open AnissaHum opened 5 years ago

AnissaHum commented 5 years ago

I am currently using the library and the associated template in an iOS app mainly written in Obj-C. I've achieved, thanks to the template, to call Python methods from Obj-C files. I am now trying to do the other way around : calling Obj-C functions from Python code. I tried to use Rubicon but it doesn't seem compatible : I failed to install it with pip in app_packages folder. Then, I tried to use PyObjc. I've successfully installed PyObjC module in app_packages thanks to pip install -t [ProjectFolder]/[ProjectName]/app_packages objc. However, when I am trying to launch, I get the following error : ImportError: No module named _objc. Though, the library named _objc.so is available in the app_packages folder.

Is there any path to configure when using modules installed in app_packages ?

freakboy3742 commented 5 years ago

In principle - yes; but in practice, not at present.

If your code contains a compiled module, you need to integrate the compilation of that module into your XCode project. In theory, that could be done by reading the build instructions for the package, but we haven't implemented that to date, so you'll need to work out how to add the individual source files to the XCode project as dependencies.

This is something that I've done (and documented) for numpy; but I haven't looked at any other binary package so far.

Are you able to provide any additional details about the failure you obtained with Rubicon? I've never had any problems installing it; I'd be interested in hearing what errors you saw.

AnissaHum commented 5 years ago

Thank you for the explanations tried to use only import rubicon.objc on my project and I got the following error: ImportError: No module named _objc.

freakboy3742 commented 5 years ago

Errr... I have no idea where that message is coming from, because there's no module named _objc in Rubicon. It sounds like something else in your environment is overlapping or colliding with Rubicion.

What version of Rubicon have you got installed? Can you share a full traceback? Can you share the result of a pip freeze in your environment?

AnissaHum commented 5 years ago

Sorry, I messed it up, it was actually with PyObjC and not rubicon. I am not using Rubicon yet because I am using Python 2.7. I'm planning on moving to Python 3 soon.

freakboy3742 commented 4 years ago

Right - so PyObjC won't "just work". It's not pure Python; it contains compiled components, and those compiled components will need to be compiled for the multiple architectures that iOS requires. That's possible in theory, but I can't give you a simple set of instructions to follow.

AnissaHum commented 4 years ago

I get it, thank you for the support. I guess my question was actually redundant so I will close it. Thanks again.