beatsal
Posts: 185
Joined: Tue Mar 21, 2017 2:46 pm

“import time" gives me "bash: import: command not found".

Sat Oct 14, 2017 9:41 pm

whatever cmd i type, i get error e.g. "import time" gives me "bash: import: command not found".
please help!

gkaiseril
Posts: 679
Joined: Mon Aug 08, 2016 9:27 pm
Location: Chicago, IL

Re: Does not do anything

Sat Oct 14, 2017 9:56 pm

Have you tried to use the "man" command to find out more information about "import".

Are you trying to write a python or c program?

Are you trying to see the time in the console?

The "date" command will show the date and time.
Last edited by gkaiseril on Sat Oct 14, 2017 10:00 pm, edited 1 time in total.
f u cn rd ths, u cn gt a gd jb n cmptr prgrmmng.

W. H. Heydt
Posts: 12431
Joined: Fri Mar 09, 2012 7:36 pm
Location: Vallejo, CA (US)

Re: Does not do anything

Sat Oct 14, 2017 9:59 pm

beatsal wrote:
Sat Oct 14, 2017 9:41 pm
whatever cmd i type, i get error e.g. "import time" gives me "bash: import: command not found".
please help!
Import is a command in Python. It is not a system level command that bash can find.

beatsal
Posts: 185
Joined: Tue Mar 21, 2017 2:46 pm

Re: Does not do anything

Sat Oct 14, 2017 10:08 pm

Thanks for the replies.
I am trying to set a pin as output i.e. I type "GPIO.output(16,true)" but get the same error.
The date cmd works fine

User avatar
DougieLawson
Posts: 38883
Joined: Sun Jun 16, 2013 11:19 pm
Location: A small cave in deepest darkest Basingstoke, UK
Contact: Website Twitter

Re: Does not do anything

Sat Oct 14, 2017 10:26 pm

You need to write your python program in a file and use python filename or python3 filename to run it. Or use idle, idle3, geany or Thonny as an IDE for python.

The shell runs bash and only understand bash commands or programs it can find in your path. The shell won't run python commands.

Try reading
https://www.raspberrypi.org/magpi/issues/53/
https://www.raspberrypi.org/magpi/issue ... ames-vol1/
and
https://www.raspberrypi.org/magpi/issue ... bash-vol1/
Note: Any requirement to use a crystal ball or mind reading will result in me ignoring your question.

Criticising any questions is banned on this forum.

Any DMs sent on Twitter will be answered next month.
All non-medical doctors are on my foes list.

beatsal
Posts: 185
Joined: Tue Mar 21, 2017 2:46 pm

Re: Does not do anything

Sat Oct 14, 2017 10:42 pm

Thanks. Used canopy as IDE and tried but get error ImportError:" No module named RPi.GPIO" :

import RPi.GPIO as GPIO
import time

User avatar
DougieLawson
Posts: 38883
Joined: Sun Jun 16, 2013 11:19 pm
Location: A small cave in deepest darkest Basingstoke, UK
Contact: Website Twitter

Re: Does not do anything

Sat Oct 14, 2017 11:12 pm

sudo apt-get install python{,3}-rpi.gpio
Note: Any requirement to use a crystal ball or mind reading will result in me ignoring your question.

Criticising any questions is banned on this forum.

Any DMs sent on Twitter will be answered next month.
All non-medical doctors are on my foes list.

beatsal
Posts: 185
Joined: Tue Mar 21, 2017 2:46 pm

Re: Does not do anything

Sun Oct 15, 2017 12:50 am

Thanks for this. It did something when I keyed your link in and did not give error.
But when I did pi@raspberrypi:~ $ import rpi.gpio as gpio
bash: import: command not found

asandford
Posts: 1998
Joined: Mon Dec 31, 2012 12:54 pm
Location: Waterlooville

Re: Does not do anything

Sun Oct 15, 2017 1:08 am

beatsal wrote:
Sun Oct 15, 2017 12:50 am
Thanks for this. It did something when I keyed your link in and did not give error.
But when I did pi@raspberrypi:~ $ import rpi.gpio as gpio
bash: import: command not found
import is a python command, the command line is bash.

If you want to use python on the Pi (and there is a thing called google that helps), try here

mlepage
Posts: 95
Joined: Tue Jun 12, 2012 1:58 am

Re: Does not do anything

Sun Oct 15, 2017 1:47 am

The command line (terminal) is running a thing called bash which is a type of shell; it's a program you use to run other programs, it's how you interact with the system. Bash knows nothing about GPIOs.

The commands you are trying to run (import etc.) are not bash/system commands, they are python commands. You need to run them from within python, which is itself a program (that bash runs). There are a few ways to do this; a python IDE (integrated development environment) such as thonny is a good option.

Within python, you are trying to import a python module which allows you to talk to the GPIOs. If it's not installed, you'll have to install it (command given in an earlier post).

Once you have all that set up, the commands will work in the python script. (But not in the bash shell.)

User avatar
DougieLawson
Posts: 38883
Joined: Sun Jun 16, 2013 11:19 pm
Location: A small cave in deepest darkest Basingstoke, UK
Contact: Website Twitter

Re: Does not do anything

Sun Oct 15, 2017 7:41 am

It's annoying that the OP even hasn't bothered to read any of the links I posted viewtopic.php?p=1222837#p1222777

So I'm outta here.
Note: Any requirement to use a crystal ball or mind reading will result in me ignoring your question.

Criticising any questions is banned on this forum.

Any DMs sent on Twitter will be answered next month.
All non-medical doctors are on my foes list.

jahboater
Posts: 5680
Joined: Wed Feb 04, 2015 6:38 pm
Location: West Dorset

Re: Does not do anything

Sun Oct 15, 2017 8:25 am

"Does not do anything" is not a very helpful title.

Perhaps you are looking for the WiringPi gpio command which will work in bash.
http://wiringpi.com/the-gpio-utility/

gpio mode 16 out

Did you mean 16?

beatsal
Posts: 185
Joined: Tue Mar 21, 2017 2:46 pm

Re: Does not do anything

Sun Oct 15, 2017 6:35 pm

Thanks.
Now, I have another problem, PI does not start up properly; get msg "fixing recursive fault but reboot is needed!" Posted this in the tr"shoot forum

Return to “General discussion”