Welcome!
This is the community forum for my apps Pythonista and Editorial.
For individual support questions, you can also send an email. If you have a very short question or just want to say hello — I'm @olemoritz on Twitter.
Install Pymunk on Pythonista - get cffi error
-
Hey Folks,
I'm trying to use StaSh to install the module pymunk into Pythonista (pip install pymunk). When running this I get an error 'No module named cffi'. This appears to be a dependency of pymunk, but I can't work out if there's a way for me to actually get it installed or if it's just a limitation (i.e. is it by design because it's incompatible or available just not included by default?).
Sorry if this is a simple question or if the information exists elsewhere, I'm fairly new to both Pythonista and Python itself and couldn't find anything that seemed relevant.
Thanks in advance!
Duncan -
https://github.com/viblo/pymunk Is probably not going to work on Pythonista because it is not Pure Python so it will not be acceptable with Apple’s app guidelines. Go to the URL above and click on the colored bar to see the language mix of the repo. There is a lot of C code there.
-
@ccc I don't understand this library of @dgelessus who says "this library is meant for use in Pythonista and requires Python 3.5 and CFFI 1.8 or later"
And it imports cffi
How is that possible? -
On your Pythonista does import cffi work?
Without the full error log, I have no further comment.
-
@ccc I didn't try, never heard about that but I'm surprised by the sentence. I only want to understand how it could be possible.
-
@cvp i didnt understand this either, its supposed to be a cffi port for pythonista yet a non-pure python cffi version is a requirement? doesnt make sense to me
-
https://github.com/dgelessus/pythonista-c-utils is a cffi parser for pythonista that mocks the cffi interface (or perhaps patches a downloaded cffi to use his parser, I'm not sure)
The c bits of ffi itself are already included in pythonista (libffi is linked in, which is how ctypes works). cffi, as I understand it, is mainly an easy way to generate the ctypes wrappers, using just c headers directly. See https://forum.omz-software.com/topic/2014/beta-tinkering-with-pythonista-s-internals-using-objc_util/8 -- cffi itself is pure and can be pip installed, but you have to set the backend to ctypes. Iirc dgelessus made a modified c parse that works specifically with core foundation headers.
Pymunk is a wrapper around the chipmunk library, which is not included in iOS or pythonista, to my knowledge, so there is no dll for ffi to hook into. So pymunk won't work.
-
@JonB Thanks for this clear explanation
-
Thank you so much for your help everyone (@jonB, @cvp @ccc, @aidensala)! Will continue looking for alternative solutions rather than pymunk in that case. Appreciate everyone's time!
-
so, i did t look much at pymunk, but i gather it is a physics library?
check out @Cethric 's https://github.com/Cethric/OpenGLES-Pythonista
which, along with some nice opengl wrappers, which includes a wrapper to the cannon.js library, which itself is a port of bullet physics lib to js. cethric runs cannon inside a hidden webview.
-
@Squidgyd Hi, to test the library Pymunk (with some existing examples or with some yours test scripts) you could try to install it in Sagemathcell, but it doesn't work if the script requires PyGame (error: "No available video device"), I don't know how to install properly it in a remote Linux server like Sagemathcell, and it is a limit for a library that uses a lot of graphics.
For example try to open this permalink that refers to a saved cell: it tries to install the required libraries but the code can not work properly due to the absence of a working method to view a video (created with PyGame) remotely.
The only thing I can suggest is to try to ask Pymunk author if it is possible for him (if he is interested) to modify his library in order to automatically by-pass the importing of PyGame, when you run your test script, if it is not installed on the computer and instead of PyGame the modified version of Pymunk library could create a choosen number of static graphical images of the simulation (by using a different method that does not require PyGame lib) that can be transformed into a video (with some python libs) that can be viewed or downloaded from Sagemathcell. If he wants and can do this kind of modification in his lib and you want/can create a python script that automatically execute the test script and create a video of the 2D rigid body physical simulation from a set of images (in which you see the position and the real speed of the objects), it would be interesting.
Regards
Bye -
@Squidgyd, I made some tests with Pymunk lib and SageMathCell and if user doesn't want to create games (it needs PyGame that in SageMathCell server can't work) but only perform simulations for research or study, Pymunk and SageMathCell can work pretty well togheter.
If you want, try to download inside your Pythonista this zipped folder, extract it somewhere, open and execute script "_execute_sage.py", wait and, if you are online and your Pythonista is allowed to be online, you should see some output data and a simple t-x,y graph of a very simple simulation where a circle falls down, due to gravity, for 5 seconds from initial position x,y equal to 0,0.
In this way, by studing and following video tutorials and some documentation about Pymunk, you could create by yourself any kind of simulation scripts with your Pythonista (unfortunately no way to use PyGame as said before), that for the Pymunk calculation asks for some helps to his friend Sage ;-)
Happy simulations!
Bye