Re: Using pyobjc with Sympy and Swift

Ian McCullough <[email protected]> Mon, 3 Apr 2017 10:12:53 -0700
Newsgroups gmane.comp.python.pyobjc.devel
Message-ID <CADa4atUOUE18NvWqHiHjomHf1W-zTMrRz-UkCkyjJBy-bXNUWg@mail.gmail.com>
--===============8924875205347888089==
Content-Type: multipart/alternative; boundary=001a113d465c3de8d1054c464607

--001a113d465c3de8d1054c464607
Content-Type: text/plain; charset=UTF-8

While this is a bit of an over-simplification, PyObjC is typically used to
write Cocoa applications using Python. Consuming Python libraries from an
ObjC (or Swift) application is far less common. PyObjC can (probably) help
you achieve this in eliminating some boilerplate, but the place to start is
really with the "embedding" section of the standard Extending and Embedding
the Python Interpreter <https://docs.python.org/2/extending/>
 documentation.

As I read your message I couldn't help but wince a little because this is a
lot of hoops to jump through in order to consume a Python library. Also,
starting from Swift makes this considerably harder because there's not yet
ABI stability for Swift, so if there are any callbacks, or other patterns
that depend on the Swift ABI, you're setting yourself up for future
disappointment. If you're dead set on using Swift, could you perhaps find
an equivalent symbolic math library written in C or C++ (Boost perhaps)
that would get the job done? This would eliminate one stop along the way,
not to mention likely having better run-time performance.

Overall, what you're trying to do is... complicated. PyObjC may be able to
help you avoid some boilerplate work, but it's not going to be a silver
bullet, and you should understand that this use case is pretty obscure, so
the number of folks that are going to be able to provide concrete,
actionable advice to get you unstuck is going to be relatively small.

The concrete, actionable advice I can give you right now is that the first
step will be getting a python interpreter running inside your application,
so the above linked docs on embedding are definitely the place to start.
Once you've embedded the interpreter, you can start to figure out how to
get it "wired" together with the rest of your application. Start small. Get
your embedded interpreter running Hello World or something first. Then
graduate to a simple library call, and then, when you've got that all
figured out, start to think about the best ways to integrate the larger
library.

Regards and Hope this Helped,
Ian







On Sun, Apr 2, 2017 at 11:22 PM, Robert Hai <[email protected]> wrote:

> Hi,
>
> I need to use a Python Library (Sympy -> http://www.sympy.org/en/
> index.html) in my Swift App. So my idea was to bridge between Objective-C
> and Swift and bridge between Objective-C and Swift to achieve my goal. So
> how do I use PyObjC with Sympy and where can I find excat documentation of
> how to use my Python in Objective-C via PyObjC ?
>
> Thanks a lot for your help ! I have ben trying to achieve this for the
> past four weeks. I finally want to solve this =(
>
> All my best,
> Robert
>
> ------------------------------------------------------------
> ------------------
> Check out the vibrant tech community on one of the world's most
> engaging tech sites, Slashdot.org! http://sdm.link/slashdot
> _______________________________________________
> Pyobjc-dev mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/pyobjc-dev
>
>

--001a113d465c3de8d1054c464607
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr">While this is a bit of an over-simplification, PyObjC is=
=C2=A0typically=C2=A0used to write Cocoa applications using Python. Consumi=
ng Python libraries from an ObjC (or Swift) application is far less common.=
 PyObjC can (probably) help you achieve this in eliminating some boilerplat=
e, but the place to start is really with the &quot;embedding&quot; section =
of the standard=C2=A0<a href=3D"https://docs.python.org/2/extending/">Exten=
ding and Embedding the Python Interpreter</a>=C2=A0documentation.=C2=A0<div=
><br></div><div>As I read your message I couldn&#39;t help but wince a litt=
le because this is a lot of hoops to jump through in order to consume a Pyt=
hon library. Also, starting from Swift makes this considerably harder becau=
se there&#39;s not yet ABI stability for Swift, so if there are any callbac=
ks, or other patterns that depend on the Swift ABI, you&#39;re setting your=
self up for future disappointment. If you&#39;re dead set on using Swift, c=
ould you perhaps find an equivalent symbolic math library written in C or C=
++ (Boost perhaps) that would get the job done? This would eliminate one st=
op along the way, not to mention likely having better run-time performance.=
</div><div><br></div><div>Overall, what you&#39;re trying to do is... compl=
icated. PyObjC may be able to help you avoid some boilerplate work, but it&=
#39;s not going to be a silver bullet, and you should understand that this =
use case is pretty obscure, so the number of folks that are going to be abl=
e to provide concrete, actionable advice to get you unstuck is going to be =
relatively small.=C2=A0</div><div><br></div><div>The concrete, actionable a=
dvice I can give you right now is that the first step will be getting a pyt=
hon interpreter running inside your application, so the above linked docs o=
n embedding are definitely the place to start. Once you&#39;ve embedded the=
 interpreter, you can start to figure out how to get it &quot;wired&quot; t=
ogether with the rest of your application. Start small. Get your embedded i=
nterpreter running Hello World or something first. Then graduate to a simpl=
e library call, and then, when you&#39;ve got that all figured out, start t=
o think about the best ways to integrate the larger library.</div><div><br>=
</div><div>Regards and Hope this Helped,</div><div>Ian</div><div><br></div>=
<div><br></div><div><br></div><div><br></div><div><br></div><div><br></div>=
</div><div class=3D"gmail_extra"><br><div class=3D"gmail_quote">On Sun, Apr=
 2, 2017 at 11:22 PM, Robert Hai <span dir=3D"ltr">&lt;<a href=3D"mailto:rh=
[email protected]" target=3D"_blank">[email protected]</a>&gt;</span> wrote:<br><blockquo=
te class=3D"gmail_quote" style=3D"margin:0 0 0 .8ex;border-left:1px #ccc so=
lid;padding-left:1ex"><div><div style=3D"font-family:Verdana;font-size:12.0=
px"><div>Hi,</div>

<div>=C2=A0</div>

<div>I need to use a Python Library (Sympy -&gt;=C2=A0<a href=3D"http://www=
.sympy.org/en/index.html" target=3D"_blank">http://www.sympy.org/en/<wbr>in=
dex.html</a>) in my Swift App. So my idea was to bridge between Objective-C=
 and Swift and bridge between Objective-C and Swift to achieve my goal. So =
how do I use PyObjC with Sympy and where can I find excat documentation of =
how to use my Python in Objective-C via PyObjC ?=C2=A0</div>

<div>=C2=A0</div>

<div>Thanks a lot for your help ! I have ben trying to achieve this for the=
 past four weeks. I finally want to solve this =3D(</div>

<div>=C2=A0</div>

<div>All my best,</div>

<div>Robert</div></div></div>

<br>------------------------------<wbr>------------------------------<wbr>-=
-----------------<br>
Check out the vibrant tech community on one of the world&#39;s most<br>
engaging tech sites, Slashdot.org! <a href=3D"http://sdm.link/slashdot" rel=
=3D"noreferrer" target=3D"_blank">http://sdm.link/slashdot</a><br>_________=
_____________________<wbr>_________________<br>
Pyobjc-dev mailing list<br>
<a href=3D"mailto:[email protected]">[email protected]=
forge.<wbr>net</a><br>
<a href=3D"https://lists.sourceforge.net/lists/listinfo/pyobjc-dev" rel=3D"=
noreferrer" target=3D"_blank">https://lists.sourceforge.net/<wbr>lists/list=
info/pyobjc-dev</a><br>
<br></blockquote></div><br></div>

--001a113d465c3de8d1054c464607--


--===============8924875205347888089==
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
--===============8924875205347888089==
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

_______________________________________________
Pyobjc-dev mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/pyobjc-dev

--===============8924875205347888089==--