I've been writing a simple python script, and I import the GPIO library, and the time library. I have the following code.

print()'Importing GPIO library' import RPi.GPIO as GPIO print()"Importing time library" import time

Yet I get this error message: ./RUNME.py: 2: ./RUNME.py: import: not found ./RUNME.py: 4: ./RUNME.py: import: not found

I run the program with sudo, and I have version 2.7.13 of python.

What causes these errors, and what can I do to rectify them? Thanks!

  • 1
    Though that is not the problem, why put the string literals behind the ()? – Ghanima Aug 11 '18 at 22:02
  • Because whenever it string is inside the (), it gives me this message: – Ubuntu User Aug 12 '18 at 16:29
  • ./boop.py: 1: ./boop.py: Syntax error: word unexpected (expecting ")") – Ubuntu User Aug 12 '18 at 16:31
  • Though the answer down there is probably right... I'll check it out in a few minutes. – Ubuntu User Aug 12 '18 at 18:40

You haven't told the system that you want to run a Python script. It probably assumes the script is a bash shell script.

You have a number of choices.

  1. use the form python RUNME.py
  2. add a shebang as the first line of your RUNME.py script. I use #!/usr/bin/env python

For choice 2 to work you need to ensure the script is executable with

chmod +x RUNME.py

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.