Tag Archives: python

Headless RaspPi: Tell Me Where You Are

I like several of the little SBC (Single Board Computer) systems that are available, despite having a love/hate relationship with my favourite – the ODROID C2. For the minute I’m stuck with just a Raspberry Pi 3 as a little SBC, so needs must when the devil, etc etc…

Anyway, when you control your own network, as I used to, it doesn’t really matter what IP DHCP decides to assign to each system. I could look it up on the router easily enough, or even fix an IP address based on MAC address.

OK, fine… but what if you don’t control your router?

Well, you could brute-force scan the entire known IP range of the network using NMAP… (nmap -sS xxx.yyy.zzz.0/24) but that seems a little extreme. It works in a pinch, though, and might be the only way of finding it that all important first time.

Once you know where it is, however, how can you keep it? On a network you don’t control, you can get jumped around the IP range depending on how the router is feeling and how many others are connected. Not very useful.

Here’s a little script modified from another one that didn’t work for me… (requires Python 2, not Python 3…)

Ah, and I found where the mods come from…!

This will send you an e-mail telling you your headless systems’ IP when the RPi boots.

Just add this to a file with vi bootupEmail.py, then chmod +x it:

import subprocess
import smtplib
import socket
from email.mime.text import MIMEText
import datetime
# Change to your own account information
to = 'me@example.com'
gmail_user = 'test@gmail.com'
gmail_password = 'yourpassword'
smtpserver = smtplib.SMTP('smtp.gmail.com', 587)
smtpserver.login(gmail_user, gmail_password)
today = datetime.date.today()
# Very Linux Specific
arg='ip route list'
data = p.communicate()
split_data = data[0].split()
ipaddr = split_data[split_data.index('src')+1]
my_ip = 'Your ip is %s' %  ipaddr
msg = MIMEText(my_ip)
msg['Subject'] = 'IP For RaspberryPi on %s' % today.strftime('%b %d %Y')
msg['From'] = gmail_user
msg['To'] = to
smtpserver.sendmail(gmail_user, [to], msg.as_string())

You’ll also need to add python /home/user/bin/scripts/bootupEmail.py to your rc.local, just before the exit 0 at the end.

IMPORTANT: Obviously, since you just put your Gmail password in a plain text file (really, really bad security practice!) just set up a gmail account to only do this one thing. Or, if you want, you could set up a mailserver on your Pi.

That may become the topic of a future post. In fact, it probably will, because I can’t believe I just suggested putting a password in plaintext.

Python, Windows and PyMol

So I was chatting with an ex-colleague who had been having some fun getting PyMol to install on Windows. So I thought I’d do a quick write-up.

To start with, you need four things:

  1. The latest (C)Python installation package (AMD64 for 64-bit Windows 10)
  2. The NumPy+MKL wheel from Christoph Gohlke’s collection for AMD64
  3. The PyMol wheel from the same for AMD64
  4. The PyMol Launcher wheel from the same (optional) for AMD64

Install Python:

Make sure to tick “add to path” also, disable the pathlength limit, since it’s an option:

Open a commandline: (shift+right click)

Use pip to install wheel:

Then install NumPy+MKL:

Then PyMol: (this will also pull in Pmw)

Then PyMol Launcher (if you want)

Then find where PyMol is installed: (a ‘cheat’ here is %appdata% in the address bar!)

And create a shortcut on the Desktop/Start Menu/Task Bar (to your taste)…

Protein loaded is 5XA7, a recent submission and nothing whatsoever to do with me. I just picked it for demonstration purposes.

And now it should work! In all honesty, I find the pip install system far more trouble than just finding and installing the relevant libraries used to be…

Python, PIP and Visual Studio

{{This post is a bit of a blast from the past, being somewhat historical. Well, I can’t change the publication date like I could in Drupal (I won’t go into the reasons I quit using Drupal just now) so it gets bumped up to 2017…}}

When Python moved to the ‘pip’ installer system, I was torn about it. On one hand, it sounded like a great idea – package management! Great! But so far I’ve spent a fair bit of time grumbling over its oddities and annoyances.

Trying to install Numpy, it just wouldn’t do it. It would always fail with, while not the most useless error message in the world (that is reserved for the wonderful “Error: no error”) one that could have been quite a bit less cryptic.

I recognise the file it’s talking about, because it’s part of Visual Studio.

It’s interesting that it’s complaining, because I have Visual Studio 2013 Community installed, and am slowly learning that… (shock)… I quite like it. But the issue is that Python 3.4 was compiled using Visual Studio 2010. And looks for vcvarsall.bat in one place and one place only.

Anyway, there are several options, most of which are simply unacceptable in my view.

“The internet” seems to think that installing Visual C++ 2010 Express, when I already have VS2013 installed is a sensible, (nay, essential!) thing to do. I disagree. So I refused to do it.

The next “internet suggestion” was install MinGW and point pip to it as a compiler. OK, but I’ve got a compiler already, I want to use that. While my dev environments tend to have a lot in them, I don’t need a Swiss Army Knife with 1001 tools – just a few will do me, thanks.

The second was use pre-compiled binaries. OK, I’ve done it before with things like PyMol – let me just take this opportunity to plug Christoph Gohlke’s superb collection – but it has to be possible to do this myself…

To that end, you can just do the following:

Create an Environment Variable for “VS100COMNTOOLS” (Visual Studio 2010 is version 10.0) which points at the same directory as “VS120COMNTOOLS”

Which works perfectly.