Using Python Libraries with Kivy?

821 views
Skip to first unread message

Eamonn Rea

unread,
Nov 12, 2013, 12:21:18 PM11/12/13
to kivy-...@googlegroups.com
Hello. I have been working on a project for a while that uses the fantastic Python library, Mechanize. Indeed it has been dead for a while, but it is actually a lot of fun to use. My friend wanted me to do a YouTube Tutorial Series on it, and I said that would be OK.

Even though I haven't started the series yet, I'd like to eventually add a GUI to the project I have in mind. Since it is so easy to use, I'd like to use Kivy for the GUI! I plan on doing a Kivy series separate, and then merge the series' together.

Unfortunately, when I try to import mechanize, it throws an Import Error exception, saying it cannot import Mechanize because it does not exist.

I racked my brain for a bit, and thought about putting in the path to the Python Environment (#!/usr/bin/python or #!/usr/bin/env python), as well as the path to the Kivy environment (#!/usr/bin/kivy). This did not work.

I tried importing a few other modules with the Python Environment Path specified as well, such as PyGame, PyGlet, Cocos2d and wxPython. I have all of these installed in the Python Environment. It actually imported PyGame for some reason, but nothing else. Anyone know why it imported PyGame?

Anyway, is it possible to use Mechanize (or any other module for Python) along with Kivy? If not, is it planned in the future? I think it would be useful to add if it's not in Kivy already.

Thanks!

Ben Rousch

unread,
Nov 12, 2013, 1:25:09 PM11/12/13
to kivy-...@googlegroups.com
You should be able to install mechanize with the easy_install or pip for the same Python as you using to run Kivy. If you're using the system Python, just sudo pip install mechanize. If you're using a virtualenv, use the virtualenv's pip.


--
You received this message because you are subscribed to the Google Groups "Kivy users support" group.
To unsubscribe from this group and stop receiving emails from it, send an email to kivy-users+...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.



--
 Ben Rousch
   bro...@gmail.com
   http://clusterbleep.net/

Eamonn Rea

unread,
Nov 12, 2013, 1:46:04 PM11/12/13
to kivy-...@googlegroups.com
I installed Mechanize. I installed it from source. It wont import into Kivy. Same with most other libraries I have installed.

I tried using Pip and Easy_Install, but no luck.

Am I supposed to do python main.py for the Kivy file?

Doug Linder

unread,
Nov 13, 2013, 4:06:06 AM11/13/13
to kivy-...@googlegroups.com
Are you using a mac?

If so, just do this:
pip install virtualenv
virtualenv py
./py/bin/pip install mechanize
cp `which kivy` .

Edit kivy and change:
exec python "$@"

To:
exec ./py/bin/python "$@"

Then:

doug:demo doug$ cat main.py
import mechanize
doug:demo doug$ ./kivy  main.py

NB. This approach will work for osx and windows pyinstaller builds, but not android or osx.

~
Doug.

Eamonn Rea

unread,
Nov 13, 2013, 10:18:02 AM11/13/13
to kivy-...@googlegroups.com
Oh sorry. I didn't think it was relevant that I was using a Mac. I'll change that and let you know how I get on.

Thanks! :-)

Eamonn Rea

unread,
Nov 15, 2013, 1:10:20 PM11/15/13
to kivy-...@googlegroups.com
What do you mean, 'edit kivy'? How/what do I edit?

Doug

unread,
Nov 15, 2013, 6:14:34 PM11/15/13
to kivy-...@googlegroups.com

on osx 'kivy' is just a shell script. open it with sublime or textedit or whatever.

~
Doug.

You received this message because you are subscribed to a topic in the Google Groups "Kivy users support" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/kivy-users/0pxrtbvTaX8/unsubscribe.
To unsubscribe from this group and all its topics, send an email to kivy-users+...@googlegroups.com.

Eamonn Rea

unread,
Nov 15, 2013, 7:46:07 PM11/15/13
to kivy-...@googlegroups.com
Ok, that works. Mechanize imports... but now Kivy doesn't exist!

When I run ./kivy main2.py, it says that there is no such module as kivy.app.

When I run kivy main2.py, it says Mechanize doesn't exist.

... yeah...

Doug Linder

unread,
Nov 15, 2013, 8:42:52 PM11/15/13
to kivy-...@googlegroups.com
Try having a look at this example:
https://github.com/shadowmint/kivy-buildout

~
Doug.
Reply all
Reply to author
Forward
0 new messages