Posts Tagged ‘python’

h1

Setting Up a Raspberry Pi with Ubuntu

17/05/2013

I had been putting off posting about this project until I had gotten RaspBMC to work, as that was step two, but it looks like the problem I need to be resolved is going to be a little while coming. So, I’m going to come back later and put an update if I get it running correctly. Either way, the Raspbian (the Debian Wheezy Raspberry Pi distro) setup is pretty clear and the same for every model of Raspberry Pi.

Here is the hardware that I’m working with:

  • Raspberry Pi Model B
  • Logitech USB Wireless Mouse Keyboard combo
  • 4GB SDHC Class 10 Memory Card
  • Edimax USB wireless adaptor
  • 4GB USB stick (for extra storage)
  • Gearhead Passive USB hub
  • USB 1.0A power adapter and Micro USB cable
Raspberry Pi Model B with SD card and wireless adapter inserted.

Raspberry Pi Model B with SD card and wireless adapter inserted.

I did this all in Ubuntu 12.04, so my work will be related to that OS; though commands are pretty similar across many distributions. Also, I have an SD card slot in my laptop, which means I did not need an adaptor to access the card directly.

The first step is to get the image on the card. I snapped in the card, it mounted and I went to the disk utility to find out where it had put it (in the system). It was mounted at /dev/mmclbk0. Once I knew that, I was ready to go get the Raspbian OS.

You can get the latest image off of Raspberrypi.org’s downloads page. I’d recommend the straight Raspberry Pi Wheezy image, as the “soft float” one is slow, and the others are more for advanced users that want to do very specific things.

Raspberry Pi booting for the first time

Raspberry Pi booting for the first time

In any case, once I had it downloaded I checked the SHA1 sum, because we’d hate to have a corrupted image from the word go. If you’re unfamiliar with SHA1, then it’s simply a method of verifying file integrity. Quite basically, an algorithm generates a unique number for a file and then that number can be checked against a copy of a file to make sure that it’s in good condition. In terminal, and in the folder that I downloaded the file into you put the command:

sha1sum 2013-02-09-wheezy-raspbian.zip

And you’ll get an output that looks something like the string listed on the downloads page. In my case, I was looking for the following: b4375dc9d140e6e48e0406f96dead3601fac6c81

Then, I just opened the archive and drag/dropped the file into a folder I had created previously, and returned to terminal. We’re going to be using the dd command to copy the extracted image (input file) to the card (output file). We’ll set the byte size to 4M and need be superuser to do this. My command was:

sudo dd bs=4M if=2013-02-09-wheezy-raspbian.img of=/dev/mmcblk0

Raspberry Pi Wheezy default Desktop

Raspberry Pi Wheezy default Desktop

Once it was done, I unmounted my card and slapped it in my Raspberry Pi for boot. On first boot you’ll get a lot of options. I’m not going to go through them one by one, as it’s pretty clear what each one is. The two I want to point you to however, are the expand rootfs and the memory split.

Expand rootfs is necessary if you have, like me, a larger than 2GB SD card. This opens up the rest of your card to be used by the system, so you have more storage space for your OS.

The memory split is important because the Raspberry Pi has a unified memory structure, meaning that it has one unified “bank” of memory that it divides towards certain tasks. If you’re going to be doing processor-heavy tasks like number crunching or multiple cron jobs, then you might want to push this towards the system memory side. However, if you intend to be using a lot of the graphical features, then you might want to lean towards the GPU.

My Raspberry Pi as it I use it now.

My Raspberry Pi as it I use it now.

The system is installed and ready to go. If you hit a command-line on boot, use startx to start the X Windows system (the GUI), and that’s it. I spent a good few hours customizing it, changing the wallpaper and such, but also removing and adding some software from the system to make it more useful to me, but that’s the basic setup.

I’ll come back at a later date if I get RaspBMC working, but as of right now it forgets that I have a mouse and keyboard attached to it, and there isn’t a simple solution that works so far. Everything works in Raspbian, and I’ve got quite a few things that I want to do in that, including Python that I mentioned in a previous post.

-CJ Julius

Advertisements
h1

Using Python 3 on Ubuntu 12.04

14/05/2013
Python on Linux

Python on Linux

Recently, I’ve turned my attention to Python, the programming language. I had some work with it in the past, but never really gotten that far. As a hobby, it was time consuming and other things got in the way. Now that I’ve freed up a small chunk of time every week I’ve decided to devote that to working on learning the new Python 3, since 2.x is going away eventually.

I quickly found out that Python 3 is not directly supported on my platform of choice: Ubuntu 12.04 LTS. So, I needed to get this running from scratch, which involves downloading, compiling and making it easy to get to for working in.

Compiling and Installing

If you haven’t done so already, you’ll need to get a C compiler for Ubuntu. In general, it’s good to keep this resident on your machine anyway, since you don’t always know when you’ll need it and it doesn’t take up a whole lot of space.

sudo apt-get install build-essential

Then, we’ll need to get our Python installer from the web. I’m currently pointing towards the 3.3.1 version, but there will always be newer versions on the horizon, so check the download page.

wget http://www.python.org/ftp/python/3.3.1/Python-3.3.1.tar.bz2

This will download and the bzip tarball of the source code from the python website. Then, we need to un-ball it and change to the newly created directory.

tar jxf ./Python-3.3.1.tar.bz2
cd ./Python-3.3.1

Lastly, we’ll configure the source code, tell it where to install and then point our compiler (the first thing we did) at Python and tell it to put it all together.

./configure --prefix=/opt/python3.3
make && sudo make install

And now the basic Python core is ready to go. You can test it by putting the following in the command line.

/opt/python3.3/bin/python3

You should get the following output, or something quite similar:

Python 3.3.1 (default, May 12 2013, 22:10:01)
[GCC 4.6.3] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>>

Getting Fancy

A command line-type of person may want to create a symbolic link that will let them have a sort of “python command”. Keep in mind that in the following code, you can substitute the “/bin/python” for anything you want the command to be (ie. “/bin/py” or “/bin/pthn” which will make the command py or pthn respectively).

mkdir ~/bin
ln -s /opt/python3.3/bin/python ~/bin/python

Alternatively, you may want to install a virtual environment for testing or whatnot. To do this and activate it, use this in the command line.

/opt/python3.3/bin/pyvenv ~/py33
source ~/py33/bin/activate

Integrated Development Environments

If you’re anything like me, then coding directly from gedit or the like is cumbersome and not really all that fun. I like options, a GUI and all the bells and whistles, so I went looking for a an IDE.

KomodoEdit install is as simple as downloading it and running the install.sh

KomodoEdit’s install is as simple as downloading it and running the install.sh

Netbeans was the first choice, as I’d used that before for PHP work. Here, I wanted something more dedicated to Python. If you do decide to go this route, make sure that you get the one from the Netbeans website and install it yourself. The version in the Ubuntu Software Center is terribly out of date and judging from the reviews, fatally flawed.

My second choice was KomodoEdit, the stripped down version of the Komodo IDE which I’ve heard some good things about (but never used). You can get it for both x86 and x64 as an AS package from their website.

If you have another IDE that you like better, let me know and I’ll take a look at it. I’m always on the hunt for a better/easier way to code.

-CJ Julius