hp-win
Posts: 4
Joined: Mon Nov 24, 2014 2:55 pm

How do i Import Libraries into Python?

Tue Nov 25, 2014 5:08 pm

hi, i am using OS raspbian and the programming software is Python. i am struggling to import a LCD library that i have downloaded into the Import library.

apologies if this seems poor.

thanks

User avatar
B.Goode
Posts: 10356
Joined: Mon Sep 01, 2014 4:03 pm
Location: UK

Re: How do i Import Libraries into Python?

Tue Nov 25, 2014 5:15 pm

I can think of at least 3 ways - this is a 'live' sample from a working python script:

Code: Select all

#!/usr/bin/env python

## import some things
import re, sys
import RPi.GPIO as rpi
from smbus import SMBus
from time import sleep
from math import sin, fabs

Case is significant. And the module must either be in your working directory or in the path that python searches.

Reference documentation here: https://docs.python.org/3.2/reference/s ... -statement

hp-win
Posts: 4
Joined: Mon Nov 24, 2014 2:55 pm

Re: How do i Import Libraries into Python?

Tue Nov 25, 2014 5:27 pm

thanks,
what i have done is download the library onto the desktop, but don't i need to place it in a import library folder?

DirkS
Posts: 10371
Joined: Tue Jun 19, 2012 9:46 pm
Location: Essex, UK

Re: How do i Import Libraries into Python?

Tue Nov 25, 2014 8:51 pm

hp-win wrote:thanks,
what i have done is download the library onto the desktop, but don't i need to place it in a import library folder?
Basically, you can put it anywhere you want. You just have to make sure you
I wouldn't leave them on the desktop though. You could use e.g. a folder inside your home directory.

See http://www.raspberrypi.org/forums/viewt ... 32&t=92049 for some info on how to make sure Python can find your modules.

Gr.
Dirk.

Return to “Python”