Getting Started with Kivy, Part 2

Let's continue our exploration of Kivy. Time to get our hands dirty. What do we need to do to start playing around with Kivy?

Well, you are going to have to install it on your computer. And chances are you are probably going to also be installing an appropriate python version to run it.

And you should probably think about what you are going to be using for your Python code editor.

Like all noble programmers, you will of course strike out in the beloved Terminal and select the terminal editor of your choice...

Yeah, right. Maybe you, not me. I want a decent modern IDE (integrated development environment) for writing my code.  You will probably want the same.  Just because we used terminal editors in the 70's is no reason to want to use one these days (in my humble opinion).


So PyCharm by JetBrains seems like the obvious IDE choice to get going with for your Python and Kivy development. And the price is certainly right, because you get to choose. The Open Source version is for everyone who is cheap. Because it is free. And has everything you need to get going. If you feel you just must pay something for this you can always buy the professional version.

Now installing PyCharm is pretty simple. Just a drag and drop dmg installer on mac os.

But all of that other stuff, ugh!


So here's where you take a leap of faith and dive into HomeBrew if you don't use it already. HomeBrew is apparently a magical code gnome who lives under a bridge or something. Or maybe it's a free and open source Package Manager.  I get confused.  I think your good pal Wikipedia explains it better than that first HomeBrew site link does to be honest.

Why do i say you are about to embark on a leap of faith into the unknown? Because you are just going to copy/paste a few terminal commands into your terminal and run them. They will ask for your machine password. They will then start to do all kinds of crazy shit to your machine. Hopefully exactly the amount of crazy shit that is required to install all of this new stuff you want to work with onto your computer. And nothing else.

The package manager builds software from source using "formulae", Ruby scripts constructed with Homebrew's domain-specific language (DSL) for managing dependencies, downloading source files, and configuring and compiling software. Binary packages called "bottles" provide pre-built formulae with default options.

So like i said, HomeBrew is your magical software gnome that mysteriously installs packages onto your computer when you command it to do so.

Now i resisted using HomeBrew for quite some kind. No thank you, i'll just travel to the appropriate GitHub page myself and download exactly what i want so i know exactly what i have and then i'll try to follow the arcane, always different depending on where you found them install instructions that never seem to quite work right for the library i want to use and the operating system version i am running, and then you spend 2 days trying to figure out what the stupid problem(s) is(are). And then you decide to focus on something else instead because all of this is a total waste of time.

And after you do that a few times HomeBrew starts to look pretty damn appealing. Even if it is magical.

Homebrew does not honor the default privileges of /usr/local; directory ownership is changed from root with group permissions for the wheel group to the installing user and the "admin" group. Specifically, the mode changes from drwxr-xr-x root wheel to drwxrwxr-x myuser admin.  All files, not just the directories, have their ownership changed by the installer. This is considered by some as a major security flaw.



I'm presenting the official Setting up Kivy with PyCharm on OSX install instructions. There are also additional instructions at that link if you are on windows.

So, fire up that Terminal application on your mac. You know where it is, right?
Everything below just corresponds to commands you run in the Terminal to get everything you need to run Kivy in an appropriate python system.

Install Homebrew

/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

Install Python 3

brew install python3
or Python 2

brew install python
Install Kivy (Merging with instructions from: https://kivy.org/docs/installation/installation-osx.html). Note that if you are using Python 2, replace 'pip3' below with 'pip'.

brew install hg sdl sdl2 sdl2_image sdl2_ttf sdl2_mixer gstreamer
pip3 install --upgrade pip
pip3 install cython
USE_OSX_FRAMEWORKS=0 pip3 install kivy
And there you go.

You have now installed HomeBrew. And then used HomeBrew to install Python, numerous packages, and all of Kivy.

And as you watch all of that stuff flash by on your terminal screen as HomeBrew does this, you will realize that it really is a magical gnome.

At this point go ahead and download and install PyCharm. Fire it up. And you are all set to go.


PyCharm does all kinds of nice things for you. Beside letting you type in code, and then organize the files associated with it.  It handles all of the gory details of running everything you are working with in a virtual python environment. Which is suggested procedure. So that if you totally mess everything up, you only messed up your virtual python environment, not the actual one installed on your computer. More magic.


So dive in and have fun. HomeBrew will help insure you don't drown too soon in the overall process.  Which always used to be one of my biggest issues about working with open source projects. They often have atrocious, horribly out of date instructions for how to install them. Using HomeBrew just seems to make all of that horror just go away. As long as you believe in magic.


In our next Getting Started with Kivy installment, we'll be taking a look at what i consider to be a super cool feature of Kivy. The Kv language.

Wait, wait. I thought we were programming in Python. Now you say we are programming in Kv?

No, no.  I think a good analogy is to think about how html5 works with CSS3 style sheets. The style of the web page is separated from the html and encoded into the style sheet.

Kivy also tries to split up your application code from the description of what it looks like. So we're separating application presentation and logic into 2 separate files. The logic of the application is addressed by the .py python file. The presentation or layout of the application is addressed by the kv file.

How this works is actually pretty slick when you fully understand it and start working with it. Some things to look forward to in our next installment in this series.

Of course my analogy kind of falls apart if you think about it too much since html encodes some aspects of presentation, specifically page layout. Kv does all of the layout for you. But you get the idea.



Comments

Popular posts from this blog

CycleGAN: a GAN architecture for learning unpaired image to image transformations

Pix2Pix: a GAN architecture for image to image transformation

Smart Fabrics