Catherine Devlin
cannot import name MAXREPEAT
When I upgraded from Xubuntu 12.10 to 13.04 today, all my existing Python virtualenvs broke! Fortunately, they're just virtualenvs and easy to replace (that's kind of the point). But don't panic if you start seeing these.
$ ipython
Traceback (most recent call last):
File "/home/catherine/ve/e2/bin/ipython", line 5, in
from pkg_resources import load_entry_point
File "build/bdist.linux-i686/egg/pkg_resources.py", line 16, in
File "/home/catherine/ve/e2/lib/python2.7/re.py", line 105, in
import sre_compile
File "/home/catherine/ve/e2/lib/python2.7/sre_compile.py", line 14, in
import sre_parse
File "/home/catherine/ve/e2/lib/python2.7/sre_parse.py", line 17, in
from sre_constants import *
File "/home/catherine/ve/e2/lib/python2.7/sre_constants.py", line 18, in
from _sre import MAXREPEAT
ImportError: cannot import name MAXREPEAT
Apparently Python 2.7.4 introduces _sre.MAXREPEAT. Here it is in my (new) system Python, 2.7.4:
Python 2.7.4 (default, Apr 19 2013, 18:28:01)
[GCC 4.7.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import _sre
>>> _sre.MAXREPEAT
4294967295L
... but the virtualenvs I created before the upgrade still use Python 2.7.3
Python 2.7.3 (default, Sep 26 2012, 21:51:14)
[GCC 4.7.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import _sre
>>> _sre.MAXREPEAT
Traceback (most recent call last):
File "", line 1, in
AttributeError: 'module' object has no attribute 'MAXREPEAT'
If I were a deeper hacker I'd try to figure out why code running within my old virtualenvs is trying to access a 2.7.4-only attribute, or what's the most efficient way to recover my old virtualenvs. But I'll settle for recognizing the problem and spinning up new virtualenvs instead. That fixes the problem.
I know... I could have avoided this problem by using Python 3! I've got code that depends on fabric, though, which still isn't available for 3.
Speak at PyOhio
Have you responded yet to PyOhio's Call For Proposals (due date: June 1)? You should. Here's why.
Why you should speak at PyOhioPerfect. Because the great curse of expert teachers is that they can forget what it was like to be a beginner. So dive into something you want to learn, take careful notes as you go about what confused you and how you resolved it, and you'll blaze a trail that you can guide other beginners along. Your non-expert perspective will make you a great teacher!
Team upYou can draw on that friendly community to help you present, too! Share a presentation with somebody more or less experienced to make an expert-beginner duet, or have a friend cover an aspect of your topic that they know better. Get a friend to review your talk as you develop it. Shop your ideas around your local Python usergroup and see what suggestions they have.
Many ways to contributePyOhio is not all about talks, of course (for me, the talks are kind of the excuse we use to get together and do the other stuff.) Also consider proposing something like
- a tutorial
- an Open Space
- a Sprint
- a Lightning Talk (actually, you propose these on-the-spot, but you can get it ready in advance)
Thank you, and spread the word!
ipython-sql for multi-database comparisons
For my newest ipython-sql trick, I needed to compare some queries run across different databases. How hard would it be to get side-by-side results into tidy IPython Notebook output?
Not hard at all, it turns out, if you're willing to violate basic principles of human decency.
That's an itty-bitty image, so here's the crazy part:
class SQL_Comparitor(object):
def __init__(self, *connection_strings):
self.connection_strings = connection_strings
def run(self, qry):
dframes = []
for connection_string in self.connection_strings:
result = %sql $connection_string $qry
Did you catch that? I used %sql magic and IPython variable substitution inside an instance method. It feels so wrong! But it works! Provided you're running within IPython, of course; normal Python will not under any circumstances run an unholy perlish abomination like this. I'm just really amazed that we can use IPython tricks inside class definitions, but it's real.
Since the result is a Pandas DataFrame, it's easy to apply transformations. For instance, say you only want the rows where the values are different:
diff = results[results['svr1/db1_Value'] != results['svr2/db2_Value']]
HTML(diff.to_html())
I'm not sure how to distribute this class, since it's small and it's not actually valid Python, just valid IPython. For now I've made a gist (and its nbviewer version).
Linux Installfest, Dayton, Sat April 13
Dayton folks - are you coming to the Dayton Linux User Group's Installfest tomorrow?
The main point of our Installfests is to get everyone together for mutual help setting up and configuring computers and programs. But we like to throw in some educational talks, too, and I volunteered to give two:
Corrupting the Youth: a survey of programming environments for kidsSeveral open-source projects have been created to help introduce kids to computer programming by creating programming environments more intuitive and fun than simply writing code at a text editor. We'll take a quick look at several of them, some suitable for teens and others for kids barely into elementary school.
Introduction to Object-Oriented Programming ConceptsObject-oriented is the most common programming paradigm in use today, but some people who've only programmed in procedural languages find object-oriented terms and concepts mysterious and intimidating. We'll take the mystery out by explaining the motivations and fundamental techniques of OO programming with some easy-to-understand examples.
Hope to see some of you there!
%sql to Pandas
After getting %sql magic for IPython working, my next big goal was to figure out how to get those results into Pandas.
Er, OK, not such a big goal. Even with zero Pandas experience, it took about five minutes of skimming the first page of documentation to figure out:
In [1]: %load_ext sql
In [2]: data = %sql postgresql://will:longliveliz@localhost/shakes select * from work
In [3]: import pandas as pd
In [4]: s = pd.DataFrame.from_records(data, columns=data.keys)
This is not the only way to move data from an RDBMS to Pandas (there's pandas.io.sql, for example), and I don't know enough about Pandas to know if it's the best way. But I bet it's the easiest way.
released: %sql magic for IPython
Inspired and informed by discussions with the IPython developers at PyCon 2013, I've released ipython-sql, a %sql magic for IPython.
With this, I really think the IPython Notebook will become the most amazing database tool ever. In fact, virtually every computing problem will become a lot more workable when manipulated via the IPython Notebook - you can remember, inspect, and annotate all the steps to investigate whatever your issue is. All hail the Notebook! The FSF really chose well in choosing Fernando Perez for their 2012 award.
post-PyCon post
You might be sick of me saying after each PyCon, "That was the best PyCon ever!", but it's not my fault if it's true.
I hardly know where to start summing up the highlights...
- PyPGDay was a great addition! I've had virtually no exposure to the PostgreSQL community before, so this was very valuable to me. Evan Klitzke from Uber gave a talk on migrating to PG from MySQL that is going to save me a ton of time, and Jeff Davis from Aster showed off the huge usefulness of range types.
- Naomi had to talk me into the Education Summit, but I'm glad she did - I got a lot of great ideas and inspiration that will help in teaching future workshops.
- One of these ideas was the use of Matt Davis' fantastic ipythonblocks, which will let us do graphical exercises right within the IPython Notebook - an amazing, intuitive, seamless learning experience.
- Speaking of the IPython Notebook, this PyCon was really its tour de force. Seemed like everyone was using it to do and show just amazing things. If you haven't seen some talks on it yet, go watch a bunch of videos immediately and then watch a bunch more when the PyCon 2013 talks are online - the docs alone can't do justice to the possibilities the Notebook creates. We've only begun to take advantage of this fantastic environment.
- I mentioned my ambition to create an IPython-based SQL client to Fernando Perez from the IPython team, and he jumped to show me what I need to know. The day after coming home, I checked in a %%sql magic. It's not ready for prime time yet (or even PyPi) and it may warrant merging into a similar project, but it was a delight to play off the capability of the Notebook.
- Peter Wang and Travis Oliphant showed me - personally! - Wakari, an amazingly powerful online hosted Python environment. I can't wait to play.
- I'm not going to list all the people I loved seeing and catching up with, because it wouldn't mean much to most blog readers. But the fact is it would be a lonely year if I couldn't see my PyCon friends (and make some new ones).
- If GitHub had an AI, it would be looking at me funny and asking, "What's got into you lately?" PyCon, that's what. And I'm nowhere near done.
Thank you to the fantastic bunch of volunteers who make this such an amazing conference, and to all the participants who bring their ideas and their friendship.
The Canadian menace
Incidentally, some people have been asking, "Wait a minute - PyCon-US in Canada? How does that work? Wouldn't it be more correct to call it PyCon-NA for North America?"
It might, if this were a case of nations cooperating to share PyCon. However, that is not the case. You will notice that the Canadians haven't cancelled their own PyCon. Rather, they have seized PyCon-US by ruthless volunteerism and are even now dragging it off to their stronghold on the St. Lawrence, to hoard it along with the PyCon they already have. That's right, they want ALL THE PYCONS.
Pythonistas of the world, be warned! When friendly faces from the North arrive to lend a hand, watch them carefully! Or you'll soon be flying to Vancouver for PyAr and Winnipeg for EuroPython.
Just to clarify: I am giddy over having PyCon in Montreal. I'm so excited that they'll probably need to name a Montreal Syndrome to go along with Jerusalem Syndrome and Paris Syndrome.
HTSQL lightning talk slides
I posted the slideshow from my PyPGDay HTSQL lightning talk here. Thanks to everybody involved with PyPGDay, I loved it!
Forsooth, a dataset
Do you ever want a demo or sample dataset that doesn't bore you to death? How about one steaming with sex, murder, and mayhem?
I'll be giving a lightning talk on HTSQL at PyPGDay this Wednesday, and wanted to show it off with some data worthy of its awesomeness. How about Shakespeare? Yeah! Luckily, Open Source Shakespeare has published a database of all Will's works. Unluckily, they've only published it as flat text files and as a Microsoft Access database. ("Open Source" Shakespeare? In a closed-source database? And a horrible one at that? Yeah, I know.)
So I fixed that; opensourceshakespeare on GitHub is a port of the opensourceshakespeare.org data to the RDBMS the Bard himself would have used, PostgreSQL. Porting further to MySQL and SQLite is left as an exercise for the reader (for now; maybe I'll add those after PyCon.)
Enjoy! And if you're ever in Cincinnati, you have GOT to see the Cincinnati Shakespeare Company. They're like... they're like actually eating the food, when all you've done before is look at the recipes.
Dayton Python Workshop, April 5-6
Announcing the first Dayton Python Workshop for women and their friends, April 5-6, 2013!
The Workshop is a free, friendly, hands-on, beginners' introduction to computer programming. In one short weekend (a Friday evening and a Saturday), participants get a real handle on programming for practical tasks, using the easy yet powerful Python language... while having a fun time with new friends!
The primary target audience is women of all ages and backgrounds, including those who have never programmed before. Men can participate as the guest of a female attendee - that's where the "women and their friends" part comes in. If you're a man who wants to take part, ask a woman you know to join you. Don't underestimate the power of a personal invitation - you'll never know which of your friends just needs a nudge to try it until you give her that nudge.
The workshop is the latest in a series based on the famous Boston Python Workshop; they've already introduced hundreds of beginners to programming in Boston, Columbus, Indianapolis, Portland, Chicago, and Kansas City. It's designed for true beginners to programming - absolutely no programming or computer experience is assumed. (Even experienced programmers have enjoyed the workshop, though - so long as they're new to Python!)
We'll enjoy food and a great venue at New Horizons in Fairborn.
Space is limited, so please sign up at tinyurl.com/day-py-workshop
New Horizons: newhorizons.com


