Python: syntax error with import

python, python-import

Solution

You need to add the `/home/pi/Adafruit-Raspberry-Pi-Python-Code` path to the module search path in `sys.path`:

import sys

sys.path.append('/home/pi/Adafruit-Raspberry-Pi-Python-Code')
from Adafruit_BMP085 import BMP085

or move the `Adafruit_BMP085` package to a directory already in your `sys.path`.

The directory of the script itself is also part of the `sys.path`, so you could also run:

$ cd /home/pi/Adafruit-Raspberry-Pi-Python-Code
$ cp Adafruit_BMP085/Adafruit_BMP085_example.py .
$ python Adafruit_BMP085_example.py

Problem

I have a python script technically named `/home/pi/Adafruit-Raspberry-Pi-Python-Code/Adafruit_BMP085/Adafruit_BMP085_example.py` The first line of this script is ``` from Adafruit_BMP085 import BMP085 ``` Also located in this directory is a python file named Adafruit_BMP085 that has a function BMP085. I want to create a python script in `/home/pi` that imports the same BMP085. I've tried: ``` from /home/pi/Adafruit-Raspberry-Pi-Python-Code/Adafruit_BMP085/Adafruit_BMP085 import BMP085 ``` But this just gives me a syntax error: ``` SyntaxError: invalid syntax ``` I've tried various syntax combinations of this same method, but cannot find one that works.

Original source