Fixing the Python 3 Problem on my Raspberry Pi

In my last post I indicated that I may need to

reinstalling everything on the Pi and starting from scratch

While speaking about my issues with pip3 and python3. Turns out that the fix was easier than I though. I checked to see what where pip3 and python3 where being executed from by running the which command.

The which pip3 returned /usr/local/bin/pip3 while which python3 returned /usr/local/bin/python3. This is exactly what was causing my problem.

To verify what version of python was running, I checked python3 --version and it returned 3.6.0.

To fix it I just ran these commands to unlink the new, broken versions:

sudo unlink /usr/local/bin/pip3


sudo unlink /usr/local/bin/python3

I found this answer on StackOverflow and tweaked it slightly for my needs.

Now, when I run python --version I get 3.4.2 instead of 3.6.0

Unfortunately I didn’t think to run the --version flag on pip before and after the change, and I’m hesitant to do it now as it’s back to working.


My wife and I love baseball season. Specifically we love the Dodgers and we can’t wait for Spring Training to begin. In fact, today pitchers and catchers report!

I’ve wanted to do something with the Raspberry Pi Sense Hat that I got (since I got it) but I’ve struggled to find anything useful. And then I remembered baseball season and I thought, ‘Hey, what if I wrote something to have the Sense Hat say “#ITFDB” starting 10 minutes before a Dodgers game started?’

And so I did!

The script itself is relatively straight forward. It reads a csv file and checks to see if the current time in California is within 10 minutes of start time of the game. If it is, then it will send a show_message command to the Sense Hat.

I also wrote a cron job to run the script every minute so that I get a beautiful scrolling bit of text every minute before the Dodgers start!

The code can be found on my GitHub page in the itfdb repository. There are 3 files:

  1. which does the actual running of the script
  2. which defines a class used in
  3. schedule.csv which is the schedule of the games for 2018 as a csv file.

I ran into a couple of issues along the way. First, my development environment on my Mac Book Pro was Python 3.6.4 while the Production Environment on the Raspberry Pi was 3.4. This made it so that the code about time ran locally but not on the server 🤦‍♂️.

It took some playing with the code, but I was finally able to go from this (which worked on 3.6 but not on 3.4):

now = utc_now.astimezone(pytz.timezone("America/Los_Angeles"))
game_date_time = game_date_time.astimezone(pytz.timezone("America/Los_Angeles"))

To this which worked on both:

local_tz = pytz.timezone('America/Los_Angeles')
now = utc_now.astimezone(local_tz)
game_date_time = local_tz.localize(game_date_time)

For both, the game_date_time variable setting was done in a for loop.

Another issue I ran into was being able to display the message for the sense hat on my Mac Book Pro. I wasn’t ever able to because of a package that is missing (RTIMU ) and is apparently only available on Raspbian (the OS on the Pi).

Finally, in my attempts to get the code I wrote locally to work on the Pi I decided to install Python 3.6.0 on the Pi (while 3.4 was installed) and seemed to do nothing but break pip. It looks like I’ll be learning how to uninstall Python 3.4 OR reinstalling everything on the Pi and starting from scratch. Oh well … at least it’s just a Pi and not a real server.

Although, I’m pretty sure I hosed my Linode server a while back and basically did the same thing so maybe it’s just what I do with servers when I’m learning.

One final thing. While sitting in the living room watching DC Legends of Tomorrow the Sense Hat started to display the message. Turns out, I was accounting for the minute, hour, and day but NOT the month. The Dodgers play the Cubs on September 12 at 9:35 (according to the schedule.csv file anyway) and so the conditions to display were met.

I added another condition to make sure it was the right month and now we’re good to go!

Super pumped for this season with the Dodgers!

Using MP4Box to concatenate many .h264 files into one MP4 file: revisited

In my last post I wrote out the steps that I was going to use to turn a ton of .h264 files into one mp4 file with the use of MP4Box.

Before outlining my steps I said, “The method below works but I’m sure that there is a better way to do it.”

Shortly after posting that I decided to find that better way. Turns out, it wasn’t really that much more work it was much harder than originally thought.

The command below is a single line and it will create a text file (com.txt) and then execute it as a bash script:

(echo '#!/bin/sh'; for i in *.h264; do if [ "$i" -eq 1 ]; then echo -n " -add $i"; else echo -n " -cat $i"; fi; done; echo -n " hummingbird.mp4") > /Desktop/com.txt | chmod +x /Desktop/com.txt | ~/Desktop/com.txt

(echo '#!/bin/sh'; echo -n "MP4Box"; array=($(ls *.h264)); for index in ${!array[@]}; do if [ "$index" -eq 1 ]; then echo -n " -add ${array[index]}"; else echo -n " -cat ${array[index]}"; fi; done; echo -n " hummingbird.mp4") > com.txt | chmod +x com.txt

Next you execute the script with


OK, but what is it doing? The parentheses surround a set of echo commands that output to com.txt. I’m using a for loop with an if statement. The reason I can’t do a straight for loop is because the first h264 file used in MP4Box needs to have the -add flag while all of the others need the -cat flag.

Once the file is output to the com.txt file (on the Desktop) I pipe it to the chmod +x command to change it’s mode to make it executable.

Finally, I pipe that to a command to run the file ~/Desktop/com.txt

I was pretty stoked when I figured it out and was able to get it to run.

The next step will be to use it for the hundreds of h264 files that will be output from my hummingbird camera that I just installed today.

I’ll have a post on that in the next couple of days.

Using MP4Box to concatenate many .h264 files into one MP4 file

The general form of the concatenate command for MP4Box is:

MP4Box -add <filename>.ext -cat <filename>.ext output.ext1

When you have more than a couple of output files, you’re going to want to automate that -cat part as much as possible because let’s face it, writing out that statement even more than a couple of times will get really old really fast.

The method below works but I’m sure that there is a better way to do it.

  1. echo out the command you want to run. In this case:

(echo -n "MP4Box "; for i in *.h264; do echo -n " -cat $i"; done; echo -n " hummingbird.mp4") >> com.txt

  1. Edit the file com.txt created in (1) so that you can change the first -cat to -add

vim com.txt

  1. While still in vim editing the com.txt file add the #!/bin/sh to the first line. When finished, exit vim2
  2. Change the mode of the file so it can run

chmod +x com.txt

  1. Run the file:


Why am I doing all of this? I have a Raspberry Pi with a Camera attachment and a motion sensor. I’d like to watch the hummingbirds that come to my hummingbird feeder with it for a day or two and get some sweet video. We’ll see how it goes.

  1. The -add will add the <filename> to the output file while the -cat will add any other files to the output file (all while not overwriting the output file so that the files all get streamed together).
  2. I’m sure there’s an xkcd comic about this, but I just can’t find it!

The Sports Center Effect

This last weekend was the divisional round of the NFL playoffs. There were 3 really good games and the game that the Patriot played in. This is unfortunate because I only had the Patriots game on the calendar for the weekend so that meant other things could get scheduled whenever and I would end up missing many, if not all, of the other games.

Sunday had 2 amazing games. The Steelers lost to the Jaguars in an upset and I got to see the last drive that put the Steelers down by a Field Goal as time expired. It was simply amazing to see how hard they played even though they must have known that they weren’t going to win.

When I got home from being out the New Orleans at Minnesota game was at half time with Minnesota up 17-0. It looked like it was going to be a route and I was glad that I wasn’t really watching it.

I started to do the chores that needed to be done (laundry, straightening up, getting ready for the week) and had the game on in the background.

And then the improbable started to happen. Drew Brees played an amazing half of football and all of a sudden it’s 21-20 New Orleans. After a couple of field goals are exchanged it’s 24-23 New Orleans with Minnesota in possession of the ball.

Case Keenum had made a couple of errors earlier in the game (one interception lead to a touch down and really helped the Saints get back in the game). It looked like he was on track to do something similarly ill-advised.

Then, with 10 seconds left the bar is snapped and he passes the ball to Stefon Diggs who catches the ball. And just as he catches the ball Marcus Williams, a defensive back for New Orleans is cued up to make an ordinary tackle in an extraordinary situation.

I was only on my high school football team for 2 years, but one thing the coaches were always on us about was wrapping up the ball carrier when we were going to tackle. “Wrap him up” they’d scream at us. Over and over again.

It became something we did just so they’d stop yelling at us (for that anyway).

So Marcus Williams is getting ready to tackle Stefon Diggs and all he has to do is “Wrap him up!” But something inside of Willliams’ head is saying, “Sports Center highlight” and instead of going for the boring, but effective arm wrapping tackle, he tried to hit Diggs with his shoulder to hopefully get the ball to be knocked loose.

Instead, he whiffs by Diggs who spins, plants his hand on the ground to stay up and proceeds to run 60 yards for the game winning, walk-off, touchdown.

I truly believe that Williams was thinking about how cool it would be to get on Sport Center when he was deciding how to tackle Diggs, and that cost the Saints the game.

Dear Sports center, stop making our sports be bad and our athletes make dumb decisions. Can you just go away now. Ok, thanks, bye