Maddog64
Posts: 7
Joined: Fri Feb 14, 2014 12:27 am

Adafruit Raspberry Pi Python Code TabError in v3.2

Thu Mar 06, 2014 8:02 pm

Hi

Still a newbie (just less newbie than a fortnight ago!) and just trying to learn about using GPIO and the Adafruit Cobbler. I've downloaded the code from http://github.com/adafruit/Adafruit-Ras ... n-Code.git. Two issues:

1. Unless I'm in the specific directory for a module, the import won't work. If I echo $PYTHONPATH I get a blank line returned. The code has several directories for each of the modules so do I have to add every one to the PYTHONPATH? What's the easiest way to add paths?

2. If I use Python3.2 (which is what started on) I get a TabError importing the Adafruit_CharLCD.py module but I don't get the error if I use Python2.7. I'm assuming this will happen with other modules and I'm guessing 3.2 is stricter on the indentation rules. How can I get the modules to import without error in 3.2? Do I need to edit every module to get the indentation right!?

Sorry if these are dumb questions but struggling a bit now!

Cheers

Rob

User avatar
Douglas6
Posts: 4874
Joined: Sat Mar 16, 2013 5:34 am
Location: Chicago, IL

Re: Adafruit Raspberry Pi Python Code TabError in v3.2

Thu Mar 06, 2014 8:32 pm

1. Python will search the directories that are listed in the sys.path variable for imported modules. I like to put common modules like the Adafruit ones in 'site-packages'. You can get a list for your environment by:

Code: Select all

>>> import sys
>>> sys.path
2. If I recall, Python3 will not allow a mixture of tabs and space indents. So yes, i think you'll need to clean up 2.7 code for Python3. You may also run across differences in the print() syntax. There may be a utility to help with the conversions; me I'm sticking with 2.7

Maddog64
Posts: 7
Joined: Fri Feb 14, 2014 12:27 am

Re: Adafruit Raspberry Pi Python Code TabError in v3.2

Thu Mar 06, 2014 10:45 pm

Hi Douglas

Many thanks - makes sense to move all the Adafruit modules into one directory and then add that to the PYTHONPATH - why didn't I think of that!!

I guess still being new to this, I'll not notice any difference between 2.7 and 3.2 so for now I'll stick with 2.7 as well.

Thanks for the swift reply,

Rob

Return to “Python”