Python-iOS-template icon indicating copy to clipboard operation
Python-iOS-template copied to clipboard

Problem importing PyObjC in `app_packages`

Open AnissaHum opened this issue 6 years ago • 6 comments

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 ?

AnissaHum avatar Oct 15 '19 16:10 AnissaHum

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.

freakboy3742 avatar Oct 15 '19 22:10 freakboy3742

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.

AnissaHum avatar Oct 16 '19 18:10 AnissaHum

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?

freakboy3742 avatar Oct 16 '19 22:10 freakboy3742

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.

AnissaHum avatar Oct 21 '19 17:10 AnissaHum

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.

freakboy3742 avatar Oct 22 '19 00:10 freakboy3742

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

AnissaHum avatar Oct 22 '19 12:10 AnissaHum