<p>I have a raspberry Pi model B with the original Pifacecad add on board</p>
<p>I recently upgraded the operating system on my raspberry pi from Wheezy (Debian 7) to Jessie (Debian 8), all seemed fine till I tried to run my Python3 project. It reported that the <code>pifacecad</code> module wasn’t present. I tried to install the module using the standard <code>apt-get</code> command given in the Pifacecad documentation. It installed OK for python 2 but It would not install for python 3 as there was a dependency issue with the <code>python-lirc</code> library. I’m guessing the upgrade broke something.</p>
<p>I installed a fresh minimal installation of raspbian Stretch (Debian 9) onto a new SD card and ran the standard installation command in the Pifacecad documentation. It all installed but there was a warning about Spi which I had forgotten to enable. I enabled this using the <code>raspi-config</code> util and rebooted the pi.</p>
<p>I then tested the installation by running the <code>sys-info.py</code> example that is mentioned in the installation documentation that comes with the pifacecad board.</p>
<p>Running this example gave a warning saying that the pifacecad hardware could not be found at this point I gave up and decided instead to run my project in python 2.</p>
<p>Of course at first the code wouldn’t run using python 2 and I had to do a bit of digging around to find out what was going wrong.</p>
<p>You may find this useful in the unlikely event that you have a project written in python 3 that you want to run in python 2, it might also be useful if you’re going in the other direction.</p>
<p>One other thing that I briefly stumbled upon was that I believe there is a tool available that attempts to convert python 2 code to python 3 I don’t know anything about it and didn’t bother looking to see if there is a tool to go in the opposite direction which is what I needed. I’ve included a link to the tool below <a href="https://docs.python.org/2/library/2to3.html" class="uri">https://docs.python.org/2/library/2to3.html</a></p>
<p>I’ve got the two versions of code loaded into the excellent graphical diff tool <code>meld</code> and I’ll just briefly cover the things that I had to change.</p>
<p>Link to meld diff tool: <a href="https://meldmerge.org/" class="uri">https://meldmerge.org/</a></p>
<p>After some mucking about I got it partially working by installing Piface module for Python 2.7</p>
<p>Had to do the following changes to get the code working in Python 2.7:</p>
<ul>
<li><p>Changed first line of code from python3 to python2 so that code was run using the correct interpreter</p></li>
<li><p>Print statement fixed by see<br />
<a href="https://stackoverflow.com/questions/32032697/how-to-use-from-future-import-print-function" class="uri">https://stackoverflow.com/questions/32032697/how-to-use-from-future-import-print-function</a></p></li>
<li>Python 3 uses the urllib.request command. For Python 3 I used</li>
</ul>
<pre><code>    urllib.request.urlopen(url).read()</code></pre>
<blockquote>
<p><a href="https://docs.python.org/3/library/urllib.request.html" class="uri">https://docs.python.org/3/library/urllib.request.html</a></p>
</blockquote>
<ul>
<li>Python 2 uses the urllib2 command. For Python 2 I used the following</li>
</ul>
<pre><code>    urllib2.urlopen(url).read()</code></pre>
<blockquote>
<p><a href="https://docs.python.org/2/library/urllib2.html" class="uri">https://docs.python.org/2/library/urllib2.html</a></p>
</blockquote>
<ul>
<li><p><code>hostname --all</code> has different output on this version of Debian, now includes mac address which I did not want.</p></li>
<li><p>Getting the wifi ESSID information. I used <code>iwconfig</code> to get this information. The path to iwconfig command changed in this version of Debian and I now had to give the full path to get it to work.</p></li>
<li><p>Python 2 and 3 seemed to handle strings differently when converting from an array to a plain string.</p></li>
<li><p>Python 3 handles input different from python 2</p></li>
<li><p>If python 2 comes across a non numeric value it quits with an exception</p>
<ul>
<li>so for python 2 I used the command</li>
</ul>
<pre><code>      raw_input()</code></pre>
<ul>
<li>for python 3 I used the command</li>
</ul>
<pre><code>      input()</code></pre></li>
</ul>
<p>Two article about incorporating future statements in Python 2<br />
<a href="https://docs.python.org/3/library/__future__.html" class="uri">https://docs.python.org/3/library/__future__.html</a><br />
</p>
<p><a href="https://simeonvisser.com/posts/how-does-from-future-import-work-in-python.html" class="uri">https://simeonvisser.com/posts/how-does-from-future-import-work-in-python.html</a></p>
<p>Related shows about my PiFaceCAD add on board for the raspberry pi</p>
<ul>
<li><a href="https://hackerpublicradio.org/eps.php?id=2933">hpr2933 :: A walk through my PifaceCAD Python code – Part 1</a></li>
<li><a href="https://hackerpublicradio.org/eps.php?id=2951">hpr2951 :: A walk through my PifaceCAD Python code – Part 2</a></li>
<li><a href="https://hackerpublicradio.org/eps.php?id=2963">hpr2963 :: A walk through my PifaceCAD Python code – Part 3</a></li>
<li><a href="https://hackerpublicradio.org/eps.php?id=2976">hpr2976 :: A walk through my PifaceCAD Python code – Part 4</a></li>
</ul>
