Hello World terminal error

Hi I was following the episode 5-Your first Python Program (1- Getting started) and I got an error on the terminal.

[Uploading:
[Uploading: Captura de pantalla 2022-09-10 a la(s) 20.20.52.jpg…]⠀
…]⠀

Looks like your upload never completed. What error did you get? Try to copy and paste the error here (rather than just uploading a screenshot).

thank you, yes! I think something happened with the image that I was uploading. Now I get the same error in the terminal. Please check this:

SyntaxError: invalid syntax

HelloWorld $python3 app.py
File “”, line 1
HelloWorld $python3 app.py
^
SyntaxError: invalid syntax

I try to use the terminal, but always I get and error. It’s so frustrating, because It stops me.

192-168-68-136:~ rbguerra$ HelloWorld $python3 app.py
sed: illegal option – r
usage: sed script [-Ealn] [-i extension] [file …]
sed [-Ealn] [-i extension] [-e script] … [-f script_file] … [file …]
bash: HelloWorld: command not found
192-168-68-136:~ rbguerra$

I continued the course and I still have the same error. I am in the 9 - Type conversion and I can’t use the terminal because say
[Uploading: error.jpg…]⠀

hi! thank you. Sorry but it is impossible upload the image. I try many times, I don’t know what happened with the format

this is what the terminal shows:

192-168-68-136:~ rbguerra$ HelloWorld $python3 app.py
bash: HelloWorld: command not found
192-168-68-136:~ rbguerra$

So about half of what you wrote there is actually just part of Mosh’s prompt in his shell. He is only typing python3 app.py (or simply python app.py)

2 Likes

ok, I think he typed “HelloWorld” to call the folder
after that he typed “$python3” because he and I, are using Mac (I don’t know what is the meaning of “$” before python3.
and finally “app.py” because that is the name of the file where we are working.

I am going to give you an example about what I want to do:

In the console I wrote
x = 1
y = 2
z = x + y

I want to see the value of the “z”, so first command+s, after I open the terminal like Mosh, I write the next sentence because I follow how Mosh do it.

HelloWorld $python3 app.py
after that I press Enter and the terminal shows me:

bash: HelloWorld: command not found
192-168-68-136:~ rbguerra$

I don’t know what is bash and also I don’t know those 11 numbers.

If you can help me will be great! Thank you!

As I said, you do not need to type “HelloWorld $” you should just type “python3 app.py” or “python app.py”. If necessary, you can first change directory into the same directory where the app.py file is located:

cd path/to/the/correct/directory
python app.py

bash is the shell you are using and the 11 numbers are probably an IP address (likely the one on your local network that your computer was assigned by DHCP on your router).

2 Likes

Yes! you were right, I wrote just python3 app.py, but now say

rbguerra$ python3 app.py
/Library/Frameworks/Python.framework/Versions/3.10/bin/python3: can’t open file ‘/Users/rbguerra/app.py’: [Errno 2] No such file or directory

In my code I wrote : x = input("x: "), so I was hoping to see something where write, but the terminal showed me the last message that I posted.

What it is mean change the directory? and How can I do that?

Thank for your help and your patience. I am not really good in this, for this reason I am doing this course

So this error means that app.py is not in your current working directory (which is /Users/rbguerra).

Think about your file navigator (which I think is called “Finder” on MacOS). There is one directory (or “folder”) that is currently open and you are looking at its contents. You can change to another directory by opening that directory. At the command line, we change directories using the cd (“change directory”) command and we can print our current (also known as “working”) directory using the pwd (“print working directory”) command.

So let us suppose your app.py file was located at /Users/rbguerra/HelloWorld/app.py and you are currently in the /Users/rbguerra directory. If we called pwd here is what we would get:

$ pwd
/Users/rbguerra

NOTE: I am using the $ character to represent whatever your prompt looks like (which is apparently "rbguerra$ " on your computer.

Now we can change directories to the HelloWorld directory and then print our current directory:

$ cd HelloWorld
$ pwd
/Users/rbguerra/HelloWorld

Then you should be able to run python3 app.py and it will find the file.

If you prefer to not change directories, you can also just specify the full path to the app.py file from wherever you happen to be. That would look like this:

$ python3 /Users/rbguerra/HelloWorld/app.py

Or you could use a relative path if you know the path from where you currently are:

$ pwd
/Users/rbguerra
$ python HelloWorld/app.py