Search code examples
pythonandroidpython-modulepython-turtlechaquopy

Can't import turtle in Chaquopy


I want to use turtle module of Python in Chaquopy on Android, but just importing turtle as normal (import turtle) doesn't work.

I know that turtle is a built-in module of Python, and I don't need to install anything on my computer to be able to use turtle. It seems like in Chaquopy, turtle is not built-in.

I also know that I can define what modules to install, in the app gradle, but as turtle is built-in (most of the time), it can't be installed using pip.


Solution

  • TLDR: Not possible currently and only possible if someone writes supporting graphics classes between Chaquopy and Android.

    If you look at the Python documentation for turtle you'll see that the library needs:

    The TurtleScreen class defines graphics windows as a playground for the drawing turtles. Its constructor needs a tkinter.Canvas or a ScrolledCanvas as argument.

    Both of those items require tkinter which is the Python interface to the Tk/Tcl library. If you check any PC which supports tkinter you'll see that Tk/Tcl has been installed. That library is responsible for drawing stuff on the screen.

    Android uses it own distinct framework for drawing things on the screen, and to my understanding Chaquopy only provides an interface between Android and Python code (with support for some libraries).

    Since Logo/Turtle has a long history, it has been re-implemented a number of times. A quick search brings up this library: https://github.com/GolubevDenis/android_turtle which may suit your needs for Android.