About Becky

I like to write things on the internet.
Author Archive | Becky

Python, Django, & MySQL on Windows 7, Part 2: Virtual Environments

This is the second post in a dummies guide to getting stared with Python, Django, & MySQL on Windows 7.

Part 1 of the Python, Django, and MySQL on Windows 7 tutorial covered the basics:  installing Python and some package management tools.

Set up virtual environments

We saw how easy it is to install Python packages such as iPython.  Just run the install command, and everything you need goes into Python’s site-packages folder.  But what if different projects require different packages or even different versions of the same package?  Of what if you have a project that requires an older version of Python?

If you’re planning to work on multiple applications, you need virtual environments to prevent a big mess of dependencies gone awry. Each virtual environment has its own installation directories, separate from other environments.

Virtual environments are brought to you courtesy of the virtualenv package.  To install the package and create a virtual environment:

  1. Open a command window.
  2. Install virtualenv by typing pip install virtualenv and waiting for the successfully installed virtualenv message.
  3. Create a folder to hold your virtual environments (for example, c:\virtualenvs) and cd it (it’s easier if there are no spaces in the folder name).
  4. Create a new virtual environment by typing virtualenv --no-site-packages [environment name].  The output will look something like this:
    virtualenv output
  5. Look at your virtual environments folder. You should now see a sub-folder with the name of your new environment.
  6. Create another environment, just for fun: virtualenv env2 --no-site-packages
  7. Activate a virtual environment by running its activate script, located in the environment’s Scripts folder. In this example, the command is c:\virtualenvs\env1\scripts\activate.
  8. The command prompt is now preceded by the environment name–that’s how you know the environment is active. The activate script also takes care of adding the virtual environment’s scripts folder to the beginning of your path.
  9. Now that a virtual environment is active, try installing  a package (we’ll use python-twitter as an example): pip install python-twitter
  10. Once the package is installed, you can see that it’s in the site-packages folder of the virtual environment, but the original Python install and the other virtual environments remain untouched.
    module installed into virtual environment
  11. To deactivate the environment, just run the deactivate script in [envrionment name]\scripts\deactivate

Bonus: Virtualenvwrapper is a handy set of extensions for virtual environments. This is a necessary tool if you deal with multiple environments on a daily basis, but it’s not essential right now if you’ll be working in a single environment. The Windows virtualenvwrapper port is here.

Coming next… getting iPython to work with virtual environments.

Comments { 5 }

Python, Django, & MySQL on Windows 7, Part 1: Installing Python, Pip, and iPython

When starting my current job, I was new to Linux, Python, Django, MySQL, and pretty much every other technology the organization uses.  Furthermore, as the office’s only Windows 7 person, I was on my own when setting up a development environment.

I found several helpful tutorials but ended up creating more detailed instructions to reflect my level of experience and our project structure. These notes became my dummies guide to setting up Python, Django, and MySQL on Windows 7.

Install Python

  1. Install Python (I used the Python 2.7.2 Windows Installer).
  2. Modify your path environment variable to include the location of the installed Python executable.  To change environment variables in Windows 7:
    • Click the Windows start button in the lower-left corner of the screen.
    • In the Search programs and files box, type environment variables
    • When the search results appear, click Edit the system environment variablesedit environment variables
    • You should now see the System Properties window.  Click Environment Variables…environment variables
    • When the Environment Variables window opens, choose Path from the System variables list and click Edit…
    • Append the following location of the Python executable and the Python Scripts folder to the variable value, making sure everything is separated by a semicolon. For example, ;C:\Python27;C:\Python27\Scripts
    • Click OK after modifying the variable value, and click OK again to exit the Environment Variables dialog.
  3. You should now be able to bring up an interactive Python shell by opening a command window and typing python.
    welcome to python

Get a package installation and management tool

Many kind people have written functionality-enhancing Python Packages, and sooner rather than later you’ll need to use some of them. Life will be much easier if you have a tool to install and manage these packages.

Two such tools are pip and easy_install (part of setuptools).  Despite some disadvantages on Windows, I chose pip after reading this StackOverflow thread.

Unfortunately, pip doesn’t have a Windows installer. The easiest workaround is to install setuptools (which does have a Windows installer) and then use it to install pip.  Directions below are a modified version of yet another StackOverflow thread.

  1. Download the setuptools MS Windows installer that corresponds to your installed version of Python. If you’re on a 64-bit version of Windows 7, use this instead (thanks to commenter JukkaN for that tip).
  2. Run the setuptools install wizard.  It should automatically find your Python installation directory.
    setuptools install
  3. Make sure you have a way to extract .tar files (e.g.7-Zip).
  4. Download pip.
  5. Uncompress the pip download
  6. Open a Windows command prompt and cd to the directory that contains the uncompressed pip download (the folder structure looks something like pip-1.1). Make sure it’s the directory that contains a file called setup.py.
  7. From that directory, type python setup.py install
  8. After this script runs, you should see a confirmation message that pip was installed to the site-packages folder of your python install (this folder will house all of the Python packages you install).
  9. If you get an error message, it’s probably because you haven’t added your Python directory to your path (see I above).

Install iPython

You don’t know it yet, but you need iPython.  It’s a richer version Python’s out-of-the-box interactive shell and has some extremely helpful features for people learning the language (object introspection, macros, code completion). iPython is easy to install now that you have a package management tool.

Even though I just had you install pip for this very scenario, it’s not the best choice for installing iPython on Windows. I promise pip will come in handy later, but to install iPython, use setuptools (setuptools will automatically install a module required for iPython’s code completion functionality, but pip will not).

  1. Open a windows command prompt.
  2. Type easy_install ipython
  3. iPython should now download and install.  If you get an error message, make sure your path environment variable contains the Python \Scripts folder.
    ipython install
  4. To use the iPython interactive shell, type ipython from a command window and peruse the built-in documentation.

The next part of Python, Django, & MySQL on Windows 7 will walk you through virtual environments.

Comments { 18 }

Two month milestone

flowering tree in Childs Park

Monday marked two completed months with the National Priorities Project. Though these weeks haven’t produced much writing, they’ve been a whirlwind of learning:

  • Python
  • Django
  • MySQL
  • The joy of setting up a proper Windows dev environment using the above three items
  • Piston, a tool for powering APIs through Django
  • Linux
  • Git/Github
  • The Federal Budget process
  • The Consolidated Federal Funds Report , a huge annual file of government expenditures.
  • Various other indicators about the state of our union: gas emissions by state, average teacher salaries, people in poverty, insurance enrollments, etc.
  • Finally, I’m NPP’s interim Twitterer, a fascinating distraction.

One day soon I’ll write a Dummies Guide to Setting up Python/Django/MySQL on Windows post. In the meantime, it’s great to be back in the hands-on tech saddle.

Comments { 2 }

Save the data, save on FOIA?

Last week I wrote my first entries on the National Priorities Project’s (NPP) blog. Friday’s piece concerned the potential $32 million cuts to the Federal government’s open data initiatives.

Alexander Howard wrote a tremendous overview of the situation, from the recent history of open government platforms to the less-than-perfect implementation of those platforms to the implications of having their funding cut from $34 million to $2 million.

He quoted some of NPP’s numbers that try to put $32 million in context. In terms of the Federal budget, it’s a tiny sum of money–.0009% of the proposed FY11 spending.

That’s an interesting figure, but even if $32 million is just a drop in the bucket, that’s not to say we should spend it carelessly. I’m new to the open government scene, but you don’t have to dig too far into Data.gov to realize it’s far from perfect. Howard’s primer provides some insight into the perverse incentives behind quirks like datasets split up by geography and agencies that don’t publish their juicy stuff.

But consider another number we published: $32 million is 7.7% of the amount that the government spent processing Freedom of Information Act (FOIA) requests in FY10.

A compelling story would be to find out what types of FOIA requests could be serviced via the Data.gov suite of sites. Even better, why not use these requests to prioritize the data that’s released online?

If we can use $32 million to take a bite out of that $416+ million FOIA bill*, why not pursue that investment?

Some of my colleagues would say because it’s not about the money—it’s about policy. As a developer, I have a hard time wrapping my brain around that. Policy? Why wouldn’t our elected officials just make decisions that are logical?

It seems I have much to learn.

*figure pulled from FOIA.gov/data.

Comments { 0 }

The new gig: return to data

Open Government Data Venn Diagram

diagram by Justin Grimes

I’m about two weeks into a new job with the National Priorities Project (NPP), a small, non-profit organization based in Northampton, MA.

NPP’s mission is to educate citizens about their federal budget: the budget process, the proposed numbers, and how our government ultimately spends money. All too often, it’s difficult for people to understand how the huge numbers bandied about in Washington, DC affect their states, schools, and communities.

The organization began in 1983, long before technology made it easier to analyze and share this information and long before the likes of sites like Data.gov.

NPP has formed some exciting partnerships in recent years, and I’m excited by our direction: combining the staff’s budget experts with an improved database search tool (launching soon) and an API developed in conjunction with the Sunlight Foundation. Finding additional indicators that, when combined with spending data, will tell a richer budget story. Telling those stories and giving our constituents the means to tell theirs too.

My role will be to look after and augment our database and help create visualizations and web tools for general use. Naturally, I took it upon myself to expand the job description to blogging, so look out budget analysts: I’m coming to gum up your blog with data stories.

It’s daunting, but I’m very excited to jump into the government data transparency community and learn the ropes. I’m also thrilled to return to a data-oriented job.

The ecosystem of government departments and agencies and their respective datasets is downright crazy, but I like crazy. It makes for good blog stories.

Comments { 1 }

New Opportunities

City Hall and Masonic Temple

City Hall and Masonic Temple

In less than two weeks, after years of discussion, my husband and I are moving away from Philadelphia.

Yes, it’s a terrible time to leave good jobs and find new ones, and it’s not the best time to sell a house. We have no friends or family in our new town. But the time is now.

I truly and deeply love Philly. However, for many reasons—some related to the city, and some related to us—I know it’s not our forever home.

After spending the last month of my father’s life in Lititz with my family, I witnessed the importance of community and the forever home. I saw the same thing again in Galloway, NJ after Nana died. The forever home is more than an investment, more than a five year plan. And community is so much more than acquaintances, loose connections, and professional networks.

After a lot of research (and a spreadsheet, of course),we decided to relocate to Northampton, Massachusetts. The Pioneer Valley has everything we could want from nature (rivers, lakes, trees, and mountains), and Northampton has most things we could want from a town (thriving retail, restaurants, theaters, and music venues).  My new job is local and promises to be challenging and interesting.

Taking the leap without a bridge is hard, but the house, jobs, and other details fell into place after we committed to the change. Because why wait?

Thanks to Wharton Computing for 5 ½ years of opportunity. It’s a great place to work and a tough place to leave.

And goodbye to the Philadelphia characters and friends we’ve met over the years through blogs, neighborhood dramas, work, clubs, and just wandering around this great city of ours. Walking away from you after 15 years is downright heartbreaking.

(cross-posted with some favorite Philly pics over on my personal site)

Comments { 1 }

Kindle: a fling, or a long-term relationship?

Amazon's Kindle 3

Amazon's Kindle 3

For the last four months, I’ve been having a love affair with the Kindle 3.  It’s a sleek, sexy companion, and with the push of a button it can deliver a whole universe of books and magazines.

And it’s easy.  Easy to carry, easy on the eyes, and easy to use.

But the Kindle ecosystem reminds me of another product that makes it easy to access digital content—iTunes.  When iTunes came along those many years ago, it was so fun to download one-hit wonders from the 80s and to grab albums that the much-cooler-than-me girl across the hall listened to in college.

The geeks complaining about DRM were just chatter in the background of my new-found music.

But now I regret spending money on content that’s locked to a single family of devices and can’t be shared with the rest of the household.  I’ve long since migrated to Amazon and eMusic, but I still own a large set of captive songs from the iTunes days.

Which raises the question:  a few years from now, will I have the same regrets about Kindle purchases?

Comments { 0 }

Testing the PowerShot S90 in South Philly

My latest mantra for all things tech is easy. Which is why, although I covet the beautiful photos taken by friends with DSLRs (digital single-lens reflex), I refuse to use a complex, heavy camera.

It’s not that I’m too dumb to learn a DSLR (in fact, most have an auto mode for people like me). Rather, the disinterest is because a DSLR is not compatible with my lifestyle and goals, namely to take decent vacation pictures while not carrying something around my neck.

So I’m strictly point and shoot. The main limitation of that has always been low light. Luckily, my friend Scott owns many cameras and loaned me his Canon PowerShot S90, which he claims is the best option out there.

These are the results of my very unscientific “use the camera to shoot South Philly Christmas lights” test. The results are inconclusive.

Basically, this whole entry is just an excuse to post pictures of South Philly Christmas lights. Should you ever have a chance to visit Smedley Street during the holidays, don’t miss it!

Comments { 0 }

How eMusic changed my music shopping

music is in the air

Music is in the air by *MarS

Earlier this year I signed up for eMusic, a long-running service that operates on a “download to own” model; you pay a monthly subscription fee and redeem that money for DRM-free MP3s.

I joined eMusic only because I saw an offer for a bunch of bonus credits and also needed to get a copy of Leonard Bernstein’s MASS immediately (long story). I had every intention of joining, using the free credits, and quitting. Who needs another monthly bill?

But I forgot to quit, and now I look forward to the monthly charge. The subscription model has changed my music shopping process–it’s like giving yourself a monthly music allowance. Psychologically, it’s easier to allocate pre-paid money for something unknown than it is to buy it outright. So I finally have those songs I bookmarked on Pandora back in 2008 and the album that’s spent years on my Amazon wishlist.

And the subscription model leads to more music discovery. If you know you have money to spend on the site, you’re more likely to browse around and see what your neighbors are into, what’s newly-released, and what’s recommended for you.

So welcome, The Young Knives and Starlight Mints and Hellogoodbye. Serge Gainsbourg, you’re only here because I was on a lot of cold medicine that day, but welcome to you too. Viva la subscription.

Comments { 0 }

Choices, curation, and CSAs

Greensgrow haul

CSA share from Greensgrow Farms

Back in 2005, I read Barry Schwartz’s Paradox of Choice, a life-changing book*.  I think of Schwartz’s maximizers and satisficers whenever I’m paralyzed by many choices in, say, the toothpaste aisle of Target.

But what if you’re not in the toothpaste aisle of Target?  What if you’re on Amazon.com and can choose from millions of book?  Or you’re facing a feed reader with thousands of unread items?  Assuming that funds and time are finite, how do you choose?

It’s no longer a matter of choosing the first option that meets your needs.  We need to pre-screen and remove the cognitive load of irrelevant options altogether, either through a human curator or an algorithm.

When I tell people about our community supported agriculture (CSA) membership, the first question is usually, “is pre-paying for a season of farm food cheaper than buying it at the store?”

Frankly, I have no idea.  This is the wrong question.  We’re paying first and foremost to support local farmers, but we’re also paying the good folks of Greensgrow (our local urban farm) to build relationships with growers and choose the week’s produce.  We pay them to make sure each delivery has leafy greens, veggies, fruit, and cheese.  In other words, we pay them to curate our food, and it’s a great investment.

*Barry Schwartz recently signed my copy of the book—so cool!

Comments { 0 }