Can't work with pyFirmata

I'm working on a project that involves experimenting with Arduino Mega and I'm learning about it from this book Python Programming for Arduino - Pratik Desai - Google Books

I'm in stage where I need to import pyfirmata library but for whatever reason it keeps throwing an import error.

I installed the library using pip3 and when that didn't help I built it from source therefore I'm quite confident that I've got it in my system. I even got a file path where it is installed. Within my Python site-packages directory.

The book is favouring Python 2.7 but I figured I can make this work in Python 3 as well. I tried import pyfirmata, from pyfirmata import Arduino and in both cases I get import error.

It shouldn't be that hard to get this to work. What should I try ?

#!/usr/bin/python
# Import required libraries
import  pyfirmata
from time import sleep

I also tried replacing the first line with the exact file path of the directory but no effect.

Your scrip is running Python 2 not 3 try…

#!/usr/bin/env python3

I had a similar issue that turned out to be my Raspberry Pi setup was incomplete. I had not run the pyfirmata setup for Python3:

sudo apt-get install python-pip python-serial
sudo pip install pyfirmata {yo, note lower-case f}

then navigate to pyfirmata folder: (probably cd pyfirmata)
sudo python3 setup.py install

James