[SOLVED] Proper GrovePi module file location

Newbie question:

As I work through the examples in the book from the GrovePi+ product i discovered that the library module named grovepi is not on the default python library path.

Use case:
1.) Using current (jessie) raspian release in ~pi/GrovePi/
run the first example from the printed manual blink in the directory ~pi/GrovePi/Software/Python (filename is grove_led_blink.py)
It works as expected

then run the 2nd example from the printed manual:
2.) from the directory ~pi/GrovePi/Projects/LED_Fade/ use the script led_fade.py it fails to find the library grovepi
After looking around a bit, I discover why, the local directory now does not include the library.
{BTW: the picture in the hard printed manual shows connecting the rotary encoder to

    A2
(this matches sw setting) but the printed text says to connect it to
    A0
}

So my question is: where is the right place to put his library in the filesystem?

Given all the sophisticated installation setup, it seemed odd that debugging this step was not encountered by others previously.

note: I was able to copy the grovepi.py file into the CWD and that fixed the problem. I know this is a python library noob question more than a grovepi one, but
since the product and examples are geared toward beginners, thought you would have a suggestion that would be more uniform.

TIA

I am discovering that using the hard copy instructions was a bad idea.
Those instructions say to do the git from “an appropriate location” on page 7. Instead it would have been clearer if it said to do the git clone from the ~pi/Desktop directory.

The problem is that the script install.sh is hard coded to copy grove.pth from ~pi/Desktop/GrovePi/ and that the grove.pth contains the path hardcoded to be from the …Desktop directory as well.

The install.sh script error is tough to spot as it happens as nearly the last step before the install.sh script reboots the pi, unless you break out of it.

There are a couple of ways to fix the problem:
move the GrovePi directory to the Desktop and then run the …Script/install.sh again,
symbolically link ~pi/GrovePi ~pi/Desktop/GrovePi together
Switch to a DEX pi-image
-OR-
sudo cp ~pi/GrovePi/Script/grove.pth to /usr/lib/python2.7/dist-packages/grove.pth
then edit the file to the as-installed correct paths

of course, a supplement of the install.sh script to the github repo to do some error checking would be even better.
I can make some suggestions if desired. ( the test function [ -x comes to mind …as well as some sed strings to work from $PWD in case some folks like me hate having directories littered all over the desktop :slight_smile: )

Furthermore the examples from the hardcopy instructions are riddled with mistakes. My favorite so far is page 22, where the words say to use a buzzer and the rotary, but the example is about using the Ultrasonic and Relay sensors… LOL. The pictures work… However, the code for that example seems very flakey once you get it running. The sensors do not seem to work properly, but that is a whole other topic…

Anyway, I have it SOLVED for myself for now, and the next re-image I will know what to watch out for.
Trust me when I say learning how python parses the paths is not very easy. But ultimately i found that if you run python interactively on the shell,as shown below you can see the difference that the grove.pth file makes.

----Here’s the clue I got from python.org, ignore that it is python 2.3 as it’s clearly a very old man page
$ python
Python 2.2 (#11, Oct 3 2002, 13:31:27)
[GCC 2.96 20000731 (Red Hat Linux 7.3 2.96-112)] on linux2
Type “help”, “copyright”, “credits” or “license” for more information.
>>> import sys
>>> sys.path
[’’, ‘/usr/local/lib/python2.3’, ‘/usr/local/lib/python2.3/plat-linux2’,
’/usr/local/lib/python2.3/lib-tk’, ‘/usr/local/lib/python2.3/lib-dynload’,
’/usr/local/lib/python2.3/site-packages’]
>>>

After I fixed it, my actual result:
pi@barium:~ $ python
Python 2.7.9 (default, Mar 8 2015, 00:52:26)
[GCC 4.9.2] on linux2
Type “help”, “copyright”, “credits” or “license” for more information.
>>> import sys
>>> sys.path
[’’, ‘/usr/lib/python2.7’, ‘/usr/lib/python2.7/plat-arm-linux-gnueabihf’, ‘
/usr/lib/python2.7/lib-tk’, ‘/usr/lib/python2.7/lib-old’, ‘/usr/lib/python2
.7/lib-dynload’, ‘/usr/local/lib/python2.7/dist-packages’, ‘/usr/lib/python
2.7/dist-packages’, ‘/home/pi/GrovePi/Software/Python/grove_i2c_adc’, ‘/hom
e/pi/GrovePi/Software/Python/grove_rgb_lcd’, ‘/home/pi/GrovePi/Software/Pyt
hon/grove_accelerometer_16g’, ‘/home/pi/GrovePi/Software/Python/grove_barom
eter_sensors/barometric_sensor_bmp085’, ‘/home/pi/GrovePi/Software/Python/g
rove_barometer_sensors/barometric_sensor_bmp180’, ‘/home/pi/GrovePi/Softwar
e/Python/grove_i2c_digital_light_sensor’, ‘/home/pi/GrovePi/Software/Python
/grove_i2c_oled_128_64’, ‘/home/pi/GrovePi/Software/Python/grove_i2c_sunlig
ht_sensor’, ‘/home/pi/GrovePi/Software/Python/grove_i2c_touch’, ‘/home/pi/G
rovePi/Software/Python/grove_ir_receiver’, ‘/home/pi/GrovePi/Software/Pytho
n/grove_oled’, ‘/home/pi/GrovePi/Software/Python’, ‘/usr/lib/python2.7/dist
-packages/gtk-2.0’, ‘/usr/lib/pymodules/python2.7’]
>>>

Not the prettiest path environment, again, a re-write to make a single directory with the final modules would be much cleaner. Again that is a repo organization, or better yet make a clean package for grovepi might be worth a little time.

apologies if I missed that this was already documented as known issue.

Hi,
Thanks a lot for taking the time to try out the GrovePi and sending us the feedback.

Sorry for the mistakes in the printed booklet. We’ll get them corrected ASAP. The software and examples are pretty much hard-coded to work from the Desktop mostly because there are a lot of dependencies and we though that it would be easier for us to manage, debug and provide support to the customers. We have it mentioned in the website here: http://www.dexterindustries.com/GrovePi/get-started-with-the-grovepi/setting-software/ . Did you check this page before you started.

The python paths are not very clean but that is the best we were able to come up to keep them organized in examples and well as make it easy to push updates and have them reflect in the examples without running any install scripts.

Sorry for any frustrations that you had while trying out the GrovePi. We’ll try our best to improve the documentation in the future and will try to keep everything updated too. Fell free to give any other feedback about the GrovePi in general.

Thanks again,
Karan

Hi,
I am a newbie and am having the same problem. I have followed through the earlier fixes and still can’t get my program to work. I continually get “grovepi” not found. Even trying to get Python to show me the CWD fails in an error!! Help please.
Steve

SteveW152, which step in these directions:

http://www.dexterindustries.com/GrovePi/get-started-with-the-grovepi/setting-software/

Did you get through?

Did your install in step 5 throw any errors?

Karen, Do we still need to go through these steps if we are using the latest Dexter Industries image?

no file

Hi Jeff,
You don’t have to run the scripts if you are using our Raspbian for robots image.

I think you are at the wrong location to run the program. You need to be in the correct folder before you can run the program and the program has to be in the folder too. If you run ls command, you can see the contents of the that folder. Navigate to the folder using the cd command and when you are in the folder with the example files, then run it.

-Karan

I feel like I am close but…

Is this a better path ?

GOT IT! SOLVED

Hey Jeff, good to hear. What path did you use?