Friday, January 16, 2015

Learning Log -- Linux Install Attempt, and more Python Installations

I sometimes use these "Learning Logs" to help me keep my thoughts collected while I work. Feel free to check out my thought process, but don't expect a polished article.

So far, I've...
  • downloaded a .iso file for Ubuntu. This was annoying because Chrome kept crashing at the end of the large download. I ended up having to switch to Firefox after two failed attempts.
  •  Copied the .iso file to an empty USB stick, tried to boot from it, didn't work. Boot menu gave two options UEFI and non-UEFI, neither worked -- all booted to Windows.
  • Burned the .iso file to an empty DVD, tried to boot from it, didn't work. Tried both the "file system" option and the "CD/DVD" options when burning.
  • Formatted the USB stick as directed here --> (Create a Bootable USB Stick), copied the .iso to it, and tried to boot from it. Still booted to windows. 
After that, I found the BootFromCD article on help.ubuntu.com, which told me my .isos haven't been burning properly, as indicated by the lack of a multi-folder filesystem present on the drive when viewed in Windows Explorer. (The pictures in the article help.) So, I'm heading over to their BurningIsoHowto article, which is going to help me a bit.

---

5 minutes later:

After reading that article for a sec, here's what I'm doing next:
  • checking the md5 sums for the .iso I downloaded -- DONE
  • Continuing thru the BurningIsoHowto article and eventually booting Linux from the disk.
---

15 minutes and many googles later:

This article tells me I need a mounting program. None of the other articles mention this. Maybe they suck. OK, let's find a mounting program.

I've heard "daemon tools" twice, so, trying to get it. It's a bit sketchy. This thing is supposed to be free, but I keep finding myself in places where they're trying to get me to spend money.

NOW SOMETHING WANTS ME TO SAVE A .EXE. UMMMMMMM

OK, after looking at reviews on cnet, looks like Daemon Tools distros have been carrying various undesirables going back at least as far as last fall. So, let's look for another option.

---

Went back to using a DVD instead.

5 minutes later:

googled "burning an iso from command prompt", found this useful article, which gave me the command to use:

isoburn /q drive:\file.iso

Which, in my case, translates to:

isoburn /q C:\Users\David\Downloads\ubuntu-14.04.1-desktop-amd64.iso

(This appears to be the only way to access the Windows disc image utility that so many articles mention.) The burn appears to have been successful, since an Ubuntu install window popped up when I put the CD back in the drive after labeling it.

Restarting computer now. Fingers crossed: next OS I see should be Ubuntu, not Windows.

---

Crossing fingers worked and didn't work. Ubuntu came up, but it was very glitchy:


My computer was also making loud noises while this screen was up. So, I turned it off before it could get any further. (Was it frying my parts? I didn't wait around to find out. I'll consider letting it boot fully if I get the same result again.)

I'm going to try burning another DVD, this time with the "verify after burning" checkbox checked.

---

No luck. I got the same behavior as before. This time I toughed it out, but there was no reward, just this screen, which persisted for 5 minutes or so before I decided it wasn't going to change. After trying a few keys and getting no response, I turned off my computer again.






My best guess at this point is that this version of Ubuntu (14.04.1) doesn't support my video card, which is the AMD Radeon HD 6670. At this point, I've had about enough of Linux installation attempts for the day. Linux: 2, Me: 0.

---

Fortunately, the immediate point of the Linux install was to solve a Python issue, which I now see another way to solve. Earlier I was having problems downloading large files because Chrome was crashing at the end of each large download. Now I've switched over to Firefox for the time being. So, I'll try downloading a Python installation that comes with the desired libraries already installed.

First step, uninstall Python 2.7 via the Start menu. Done

Note: Might also try uninstalling my other Python versions if this doesn't work.

Next, download Python(x,y) from here. Just like I did before from Chrome, but this time I'm in Firefox, so the download won't crash at the end and waste 20 minutes of download time.

OK, downloaded it, starting the install. Oops, it's telling me that I still have Python 2.7 installed. Maybe I need to restart the computer for the registry changes to take effect. Let's try that.

After restart, same error message. Buh. OK, let's plow through it this time with the "install anyways" button. The only other option seems to be uninstalling my other Pythons (3.3, 3.4) and I'd rather not if I can help it.

Installation completed. Moment of truth. Run Grimm's script.

GREAT SUCCESS!


OK, now I just have to combine it with the adapted example script, and I'll be done. Wow.

Rough draft:

from xml.dom import minidom
import matplotlib.pyplot as plt

doc = minidom.parse("posts.xml")

# doc.getElementsByTagName returns NodeList

viewCounts = []
scores = []

rows = doc.getElementsByTagName("row")
for row in rows:
        if (row.getAttribute("Id") == 1):
               viewCounts.append(int(row.getAttribute("ViewCount")))
                scores.append(int(row.getAttribute("Score")))
               
plt.plot(viewCounts,scores)
plt.title('StackExchange data -- ViewCount and Score')
plt.xlabel('ViewCount')
plt.ylabel('Score')

plt.show()


Result: not what was desired.



After some typecasting, still not getting results. Time to take a peek at what's going on under the hood with some print statements. Let's add a counter variable, increment it over every iteration of the for loop, and print the first 50 instances of the relevant variables.

OK, there was an issue with the attributes having null values. Fixed that by only appending the value if it was truthy (existing.)  But, still the same graph result.

Eureka. Changed "Id" to "PostTypeId" after printing the arrays and finding they each had one value in them, as opposed to the expected thousands.


Achievement unlocked/mission complete/QED, which when pronounced phonetically rhymes with bed, which is what I will go to now.

Thursday, January 15, 2015

Learning Log -- Python, XML, matplotlib, troubleshooting

I sometimes use these "Learning Logs" to help me keep my thoughts collected while I work. Feel free to check out my thought process, but don't expect a polished article.

Trying to learn how to use Python to interact with an XML file. The eventual goal is to plot some attributes of the xml file's nodes in scatter-plot fashion using a Python library called matplotlib. First, I need to learn how to work with XML through Python.

Starting here: https://docs.python.org/3/library/xml.dom.html#module-xml.dom

The page talks about something called SAX, which I know nothing about. Apparently when parsing XML, we choose between SAX and DOM. I know DOM stands for Document Object Model, but I don't really know what it means, in practical terms. So, good time to learn more. I went and found this thread, which explains the difference well:

http://stackoverflow.com/questions/6828703/what-is-the-difference-between-sax-and-dom

I guess SAX triggers events while the XML is being parsed, while the DOM parses the XML first and then triggers events.

Now that I understand a little more about XML and the DOM, time to use Python to interact with XML through the DOM. Apparently the stuff you use to interact with XML in Python comes with the base Python download, so I won't need to install any extra libraries just yet.

I'm using this video to see an example:

https://www.youtube.com/watch?v=aCksVW1YUHs

The video linked me to some source code here, which I copy-pasted and adapted into this:

from xml.dom import minidom
import matplotlib.pyplot as plt

doc = minidom.parse("staff.xml")

# doc.getElementsByTagName returns NodeList

rows = doc.getElementsByTagName("row")
for row in rows:
        if (row.getAttribute("Id") == 1):
                rid = 1
                viewCount = row.getAttribute("ViewCount")
                score = row.getAttribute("Score")

There is some confusion about whether to use Python 3.4 or 2.7, or if it matters. (I have both installed.) I think the conclusion is that matplotlib is for Python 2.7, so I'll do everything in 2.7.

Tried to run Grimm's sample code -- got error:

ImportError: No module named six

So, googled the error. Found out: This error means that matplotlib depends on a module named six and that I haven't installed the library which contains the six module.

The six module is pretty cool, being a compatibility library. I downloaded it. Now I have to figure out what to do with the thing I downloaded. Apparently there's a thing called a python wheel. By googling "Install python wheel", I found a video that explains this a little bit.


Basically, I didn't need to download the six module after all -- pip will download and install it for me when I type this into the command line and press Enter:

pip install six

So, six is now installed. I try running Grimm's code again and get this:

ImportError: matplotlib requires dateutil

Oops, looks like I didn't follow the instructions for matplotlib very well. They say that I need to install a number of python libraries. So, I'll try to use the installer tool I downloaded. pip install numpy. An installation occurs, but an error happens. It's a complicated one and something I've never dealt with before. I ignore it for now. I'll circle back to it if things aren't working after I install the rest of the libraries.

Well, I got an error message that told me the error was important, so looks like I'll have to fix it. I google the error and find this:

http://stackoverflow.com/questions/2817869/error-unable-to-find-vcvarsall-bat

Which points me to this:

http://stackoverflow.com/questions/6551724/how-do-i-point-easy-install-to-vcvarsall-bat

Which tells me that I need to have Visual Studio installed, which raises the question, "Don't I have to pay for that or something?" But I suspect that's off. So I google "Is visual studio free?" The answer seems to be NO--there's a trial version. But I'd rather just go back and install Linux finally. That'll be its own post.