PiSupply / Bright-Pi

Bright Pi
29 stars 10 forks source link

Import Error From Terminal Only #13

Closed BeeCoughs closed 4 years ago

BeeCoughs commented 4 years ago

I'm having some trouble figuring out how to get my script to run from terminal.

I tried brightpi-test.py and it works fine. Running my code from the Thonny editor also works. However, when I run my script from the terminal I get an error: ImportError: No module named brightpi

The line I get the error on is taken directly from the example (from brightpi import *)

Based on my googling, it seems possible that brightpi is installed locally and not for all users, but I'm not sure how to install for all users without sudo pip. I tried adding a sudo before the call to curl but it didn't seem to change anything. I also checked python --version and I'm running 2.7.16.

tvoverbeek commented 4 years ago

Look at the description of search path in https://docs.python.org/2/tutorial/modules.html. If your script and brightpi.py are in the same directory (and it is your current working directory) your script should find it. Anyway, if you installed brightpi with the command given in https://github.com/PiSupply/Bright-Pi#auto-installation you should not get an error. Note that the installation now only works for python3 (not python2). Use python3 for your scripts.

BeeCoughs commented 4 years ago

Moving them to the same directory and running in python3 did the trick! Thanks for the help.