Nooby Python folders question.
Moderators: adafruit_support_bill, adafruit

Forum rules
Talk about Adafruit Raspberry Pi® accessories! Please do not ask for Linux support, this is for Adafruit products only! For Raspberry Pi help please visit: http://www.raspberrypi.org/phpBB3/

Nooby Python folders question.

by Krisduck on Fri Oct 25, 2013 1:39 am

This feels like a silly question, but I'll ask anyway.

After installing my LED Backpack and finally getting my clock working the way I want, I'm left with one minor annoyance.

The library installed to /home/me/Adafruit-Raspberry-Pi-Python-Code/Adafruit_LEDBackpack but all my other python scripts are in /home/me/. If I copy the clock.py file to /home/me, it complains about not finding the proper files. My other scripts don't have a problem being in the home folder. Can I move the Adafruit files somewhere that it can find them? In searching, people talk about changing the default paths and stuff, it just shouldn't be that complicated... or should it?

Thanks in advance,

Kris
Krisduck
 
Posts: 5
Joined: Wed Oct 23, 2013 10:55 pm

Re: Nooby Python folders question.

by adafruit_support_mike on Fri Oct 25, 2013 12:14 pm

It isn't particularly complicated, it's just a matter of providing enough information. If I were to say, "libraries work just fine where I put them", your obvious response would be, "yeah, but where do you put them?"

The Python interpreter has basically the same problem when you run a script that wants to import an external file. It's smart enough to look in the same folder as the script itself, then has a list of other folders to check if that doesn't work. If you don't want to store files in any of those places, you need to tell it the location you've chosen.
When you void a product warranty, you give up your right to sue the manufacturer if something goes wrong and accept full responsibility for whatever happens next. And then you truly own the product.
User avatar
adafruit_support_mike
 
Posts: 10090
Joined: Thu Feb 11, 2010 2:51 pm

Re: Nooby Python folders question.

by Krisduck on Sun Oct 27, 2013 11:20 pm

adafruit_support_mike wrote:It isn't particularly complicated, it's just a matter of providing enough information. If I were to say, "libraries work just fine where I put them", your obvious response would be, "yeah, but where do you put them?"

The Python interpreter has basically the same problem when you run a script that wants to import an external file. It's smart enough to look in the same folder as the script itself, then has a list of other folders to check if that doesn't work. If you don't want to store files in any of those places, you need to tell it the location you've chosen.


I DO want to store them where it defaults to looking. Installing the Module put it in my home folder, not one of the python module folders. Every other python module I've installed seems to place the libraries somewhere I can access them. Can I move the Adafruit Backpack module there too? Or do I just point to the folder in the script?

Thanks again.
Krisduck
 
Posts: 5
Joined: Wed Oct 23, 2013 10:55 pm

Re: Nooby Python folders question.

by Krisduck on Tue Oct 29, 2013 11:38 pm

After some more searching, I came across the suggestion including the sys.path.append addition. Though I seem to be doing it wrong again..

Code: Select all | TOGGLE FULL SIZE
import time
import datetime
import os, sys
CURRENT_DIR = os.path.dirname(os.path.abspath('home/raspberrypi/Adafruit-Raspberry-Pi-Python-Code/Adafruit_LEDBackpack'))
sys.path.append(os.path.dirname(CURRENT_DIR))
from Adafruit_7Segment import SevenSegment


This gives me an error "ImportError: No module named Adafruit_7Segment". I tried including an __init__.py in the folder as per someone's suggestion, but I'm obviously missing something important here.

Thanks again.
Krisduck
 
Posts: 5
Joined: Wed Oct 23, 2013 10:55 pm

Re: Nooby Python folders question.

by adafruit_support_mike on Wed Oct 30, 2013 4:53 am

All you need is:

Code: Select all | TOGGLE FULL SIZE
sys.path.append("/home/me/Adafruit-Raspberry-Pi-Python-Code/Adafruit_LEDBackpack")
When you void a product warranty, you give up your right to sue the manufacturer if something goes wrong and accept full responsibility for whatever happens next. And then you truly own the product.
User avatar
adafruit_support_mike
 
Posts: 10090
Joined: Thu Feb 11, 2010 2:51 pm



cron