… install pip in versions of Python prior to Python 3.4? … install packages just for the current user? … install scientific Python packages? … work with multiple versions of Python installed in parallel? Common installation issues. Installing into the system Python on Linux; Pip not installed; Installing binary extensions; Python HOWTOs
First, the lesson said to simply type, python, into terminal to start coding in python (I don't know if this is the way to say that, or if that just gives you the ability to run python code?)
What happens when you type a program name into terminal is that it basically executes the program, and if it has a GUI, the GUI window will pop up onto the screen. If it only has a command-line interface (like ) the program will be executed inside the terminal.python
In the case of running , what it does is actually to load a python interpreter inside your terminal. If you notice, the command-line interface would have changed quite a bit (I am on Windows so I am not sure how it looks like exactly on Mac). So instead of something likepython
YourName@USER ~/Path/to/your/exercise/files
$ _
at the start of the line, you would have encountered the below instead:
# Bunch of text describing your python version and other things
>>> _
That is actually the python interpreter's command line. You can only execute python codes here.
Then, it said to type in:
python hello.pyWhich was supposed to return:
Hello WorldHowever, all I keep getting is :
SyntaxError: Invalid Syntax
I suspect when you are running the command , you were still inside the python interpreter program, which is why it return the python hello.py error, because it is not a valid python syntax.InvalidSyntax
What does (if you were to run it in your terminal instead) is to execute the python interpreter, supplying your python hello.py file as the code for the interpreter to interpret and execute. So it is as if you run hello.py and entering the codes you wrote inside python into the python interpreter. So,hello.py
I was thinking maybe it's due to me downloading python again when it was already installed, if it even was?
nope, it was not. It was because of the reasons I explained above.
Hope it helps!
Edit
A little bit of extra info, to properly exit the python interpreter command line, you can type or exit(). Ctrl+D works too, as a shortcut.quit()
You need python installed on your system. Then you can run this in the terminal in the correct directory:
python gameover.py
If you want to override the command, you can set your python variable correctly, e.g. in your PATH:~/.bash_profile
export PATH=/path/to/python/:$PATH
That said, for managing different versions of components that are also provided by Mac OS X, I suggest to use a package manager such as Homebrew.
Use python3
If it doesn't work you probably don't have Python 3 installed. I recommend installing Homebrew on your macOS. https://brew.sh/
Then you can easily install Python 3 using this command:
And additionally if you need pip3 too: brew install python3brew install python3-pip
Installing packages using brew is almost the same as installing packages on Linux.
This is a common mistake. First save your python file in a folder, and make sure that you have a .py at the end. Then go to terminal, and type in the address without adding users. For example, my .py file is saved in a folder named Python, on my desktop. My python file is called read. It will work:)
python ~/Desktop/Python/read.py
Then click enter in terminal, and your file should execute.