0x0000
Posts: 137
Joined: Tue Aug 27, 2013 8:59 pm

ImportError: No module named quick2wire.i2c

Thu Oct 31, 2013 2:21 pm

Hello,

I have been following this tutorial to set-up my ADC Pi,

http://elinux.org/RPi_ADC_I2C_Python,

On third point of step 3, it says,
enable Python to access the API by adding
export PYTHONPATH=$PYTHONPATH:$HOME/quick2wire-python-api to the end of ~/.profile
what is meant by
~./profile
there ?

I simply typed this line in my Linux Terminal,

Code: Select all

export PYTHONPATH=$PYTHONPATH:$HOME/quick2wire-python-api
and rebooted the RPi

I then followed the step 5,

Code: Select all

Download and run the demo script
download it with: wget http://www.andrewscheller.co.uk/adc_demo.py
make it executable with: chmod +x adc_demo.py
run it with: ./adc_demo.py
But when I am running it, I am getting this error,
root@raspberrypi:/home/pi# python adc_demo.py
Traceback (most recent call last):
File "adc_demo.py", line 11, in <module>
import quick2wire.i2c as i2c
ImportError: No module named quick2wire.i2c
What am I doing wrong ?

User avatar
DeeJay
Posts: 2027
Joined: Tue Jan 01, 2013 9:33 pm
Location: East Midlands, UK

Re: ImportError: No module named quick2wire.i2c

Thu Oct 31, 2013 2:30 pm

0x0000 wrote:On third point of step 3, it says,
enable Python to access the API by adding
export PYTHONPATH=$PYTHONPATH:$HOME/quick2wire-python-api to the end of ~/.profile
what is meant by
~./profile
there ?
It is a file. The name of the file is .profile (the ' . ' is important)
It is at the 'top' level of the filespace allocated to the user running the command. (That's what ' ~/ ' means )


I simply typed this line in my Linux Terminal,

Code: Select all

export PYTHONPATH=$PYTHONPATH:$HOME/quick2wire-python-api
and rebooted the RPi
'export' does not persist over reboots - that's why you have to put it in a file to be run when you log in.

That explains the resulting errors -
root@raspberrypi:/home/pi# python adc_demo.py
Traceback (most recent call last):
File "adc_demo.py", line 11, in <module>
import quick2wire.i2c as i2c
ImportError: No module named quick2wire.i2c
What am I doing wrong ?
Not following the instructions!
How To Ask Questions The Smart Way: http://www.catb.org/~esr/faqs/smart-questions.html
How to Report Bugs Effectively: http://www.chiark.greenend.org.uk/~sgtatham/bugs.html

0x0000
Posts: 137
Joined: Tue Aug 27, 2013 8:59 pm

Re: ImportError: No module named quick2wire.i2c

Thu Oct 31, 2013 3:14 pm

It is not working yet,
I have edited the ~/.profile file,

Code: Select all

if [ "$BASH" ]; then
  if [ -f ~/.bashrc ]; then
    . ~/.bashrc
  fi
fi

mesg n
export PYTHONPATH=$PYTHONPATH:$HOME/quick2wire-python-api

I am still getting the same error even after saving the file and rebooting RPi.
When I tried to echo $PYTHONPATH, It shows nothing at all just a blank line.

User avatar
DeeJay
Posts: 2027
Joined: Tue Jan 01, 2013 9:33 pm
Location: East Midlands, UK

Re: ImportError: No module named quick2wire.i2c

Thu Oct 31, 2013 3:46 pm

I think the advice in the tutorial may be less-than-perfect, but you seem to be working from a different base copy of ~/.profile. This is on a recent (Oct 2013) install of Raspbian.

Code: Select all

less .profile
# ~/.profile: executed by the command interpreter for login shells.
# This file is not read by bash(1), if ~/.bash_profile or ~/.bash_login
# exists.
# see /usr/share/doc/bash/examples/startup-files for examples.
# the files are located in the bash-doc package.

# the default umask is set in /etc/profile; for setting the umask
# for ssh logins, install and configure the libpam-umask package.
#umask 022

# if running bash
if [ -n "$BASH_VERSION" ]; then
    # include .bashrc if it exists
    if [ -f "$HOME/.bashrc" ]; then
        . "$HOME/.bashrc"
    fi
fi

# set PATH so it includes user's private bin if it exists
if [ -d "$HOME/bin" ] ; then
    PATH="$HOME/bin:$PATH"
fi

echo "Before change - "
echo $PYTHONPATH
export PYTHONPATH=$PYTHONPATH:$HOME/quick2wire-python-api
echo "After change - "
echo $PYTHONPATH
echo "Leaving .profile... "
Results in -

Code: Select all

Last login: Thu Oct 31 15:24:28 2013 from 192.168.1.16
Before change -

After change -
:/home/pi/quick2wire-python-api
Leaving .profile...
pi@raspberrypi ~ $

It seems that the variable is initially empty or undefined, and the " : " operator gets taken as a literal rather than as an instruction to concatenate the strings.

But your .profile is different to start with, and you don't get the same result from 'echo $PYTHONPATH'

I've had a quick Google around and can't see a fix for this. As long as PYTHONPATH is initially empty then just setting it to the new value will work, but it's not futureproof.
How To Ask Questions The Smart Way: http://www.catb.org/~esr/faqs/smart-questions.html
How to Report Bugs Effectively: http://www.chiark.greenend.org.uk/~sgtatham/bugs.html

0x0000
Posts: 137
Joined: Tue Aug 27, 2013 8:59 pm

Re: ImportError: No module named quick2wire.i2c

Thu Oct 31, 2013 3:54 pm

Thank you, I didn't get everything you write, But when I export it from the command line and prints the PythonPath , it worked !

Thanks again. :P

P.S: I am still getting error in running the Python script hopefully you will help me fixing it too, :)

http://www.raspberrypi.org/phpBB3/viewt ... 86#p446386

Return to “Beginners”