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
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/
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/
- adafruit_support_mike
- Posts: 67454
- Joined: Thu Feb 11, 2010 2:51 pm
Re: Nooby Python folders question.
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.
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.
- krisduck
- Posts: 5
- Joined: Wed Oct 23, 2013 10:55 pm
Re: Nooby Python folders question.
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?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.
Thanks again.
- krisduck
- Posts: 5
- Joined: Wed Oct 23, 2013 10:55 pm
Re: Nooby Python folders question.
After some more searching, I came across the suggestion including the sys.path.append addition. Though I seem to be doing it wrong again..
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.
Code: Select all
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
Thanks again.
- adafruit_support_mike
- Posts: 67454
- Joined: Thu Feb 11, 2010 2:51 pm
Re: Nooby Python folders question.
All you need is:
Code: Select all
sys.path.append("/home/me/Adafruit-Raspberry-Pi-Python-Code/Adafruit_LEDBackpack")
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/
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/