Import command not working?

In many projects, the import command is in the set code. But is it now not working? I tried it on my moniter, and it said it couldn’t find the command. I updated the software and firmware and it was still not working. In the project I’m doing(whos at the door), the import is in the code and I’m not sure if there is a directery that I have to go to or what

2 Likes

@jadenjozefsouza
What product are you programming (GoPiGo3, BrickPi, GrovePi, none of these)?

What operating system are you using?

What is the command you are using to start your program?

What is the first line of your code file?

Note: the most common reason “command import not found” is

  • attempting to execute a Python script in a bash terminal window, that does not have this as the first line:

Or

  • not invoking it with “python3 myprogram.py”
1 Like

Hi. Thanks so much for responding so quickly. I apreciate that. I am using the GrovePi and I am using Microsoft as my operating system. The first command it says import GrovePi and after that it said that to enable it I have to do import smtplib, subprocess, string, time. I did that command and it said again import command not found. When I typed in#!/usr/bin/env python3 it said nothing, it was just like I had pressed enter for a new line and I typed in the import command and it still said command not found. I typed in python3 myprogram.py but it said that it couldn’t open the file myprogram.py and no such file or directory exists. Again, thanks for responding so fast
Thanks in advance
Jaden

2 Likes

Please create a file named example.py with the following lines in it: (either type them very carefully or copy paste into the file)

And then in the terminal type:

That first line is not used when you run the program with that command in the terminal. There are alternative ways to invoke the program that need that first line to know this is a python3 program.

By the way, this is for real?

You have Windows IoT tech preview running on a Raspberry Pi 3B or 3B+?

Please give a link to the guide you are using, (I’m pretty sure you missed a step):

1 Like

Hi. Thank you for responding so fast. I did this and created a new file and double checked to see if it was typed correctly and when in the terminal i did python3 example.py, it said what it was supposed to say (import grovepi succeeded sleeping for 5 seconds dont bother me and done. Exiting. After that, it returned to the original format and I typed in import grovepi and it still says command not found. I’m not sure where to check my Raspberry Pi official version but on the desktop, it said that my version was Version 9.
I am trying to build the project using these set of instructions:

Thank you for responding so fast
Jaden

1 Like

That is a program that you will need to edit and run with Python. It probably is on your computer already at ~/Dexter/GrovePi/Projects/Whos_at_the_Door/whos_at_the_door.py which you need to copy to your working folder, edit in your email id, and run with

But you should be starting with a simpler program to learn your way around the operating system, and how to write and run python programs, and how to use the GrovePi to just read the button.

The example.py program proved the GrovePi software is installed and the computer is functioning perfect.

1 Like

Hi, thanks for responding so fast. Your right. When I type it in files it works. However, when I got to line 26, I ran it, and it said
File whos_at_the_door.py line 27
syntax error: unexpected EOF while parsing
so I typed 2 more lines into it and it said the same thing except for line 27 replaced with line 29.
Thanks

2 Likes

Here is a trick instead of typing:

wget https://raw.githubusercontent.com/DexterInd/GrovePi/master/Projects/Whos_at_the_Door/whos_at_the_door.py

what do you suggest doing with this link

1 Like
  1. ls
  2. (if already have a file whos_at_the_door.py): mv whos_at_the_door.py my_file.py
  3. select the whole command from wget ... to ...py, right click, copy
    paste into your Raspberry Pi terminal, press return

Voila, you have the file exactly typed for you.

1 Like