Newbie Help: Terminal Can't Find Python

Newbie help! (Mac OS 11.1) I’ve downloaded Python 3.9 and PyCharm and have been working through a “Great Courses” video, but I’m stuck. Terminal does not find 3.9. When I put “python —version” into the Command line, what comes back is “Python 2.716.” I have run “Install Certificates” in Terminal. What am I missing? (Enjoying learning at 81!)

Try python3

Thanks, but it did not work. Because of this problem, I cannot use pip to install piglet, etc. etc.

How did you download Python 3.9 and did you actually install it as well

or just download?

Apple OS has modus as admin for to install packages ? Not ?
Avoid to be admin for to install packages. It depends on installation of 11.1 if this
is a full-featured OS, where you have rights as admin or as normal developer. Get sure 11.1 is updated. (click on apple icon top left corner and actualize your os). then in terminal you should install like described here :

Be patient and read careful. I think it is not necessary to install as admin.
Here is description for Python older version :
search query about apple how to install python

And here is description for Python3 :
search query about apple how to install python3

No offense - these queries work with firefox - not sure if safari allows that. However you already have “Big Sur” - I have not seen this yet.

In case of doubt you use these search terms in safari :
how to install python3 in terminal (big sur apple)

Cheers.

Howdy Stefan,

step one: find your Python 3.9 directory…

I would recommend to have a look into /Applications as well as into /Library/Frameworks as well as into /System/Library/Frameworks as well as into /usr/bin as well as into /usr/local/bin first.

If you do not find said Python directory there, you can search for the executable:

Press CMD + F in a Finder window
Select "This Mac" (default)
Select "Filename" "begins with" "python"

If this leads to too much matches, you also can try “pythonw” instead. Note that “python” also might start with an uppercase. It might also be a good idea to search for “Python.app”.

Even better might be using the terminal command ‘find’ (in a terminal):

find / -perm +111 -type f -iname "python" 2>/dev/null

Or alike… All ways lead to Rome…

I personally prefer the last version (the command line ‘find’ command) - it does not lead to many false positives in my experience…

As soon as you have found it or even several ones, come back to us with the result :sunglasses:

Cheers, Dominik

In terminal one can use also which with -a flag (all). So to see what python or python3 are installed one can use:

> which -a python3   # or just python

which is for locating a program file(s) in the user’s path. If this does not return any results then there are two possibilities: (a) no python3 installed, (b) python3 installed but not on the path

1 Like

Is there actually a pythonw on Mac? I thought that was just a Windows
thing.

Is there actually python on Windows? I thought that was just a *nix like thing :laughing:

1 Like

Well, I double-clicked on it, and there is now a Python 3.9 folder in my Applications folder. I also ran the “Install Certificates Command” in Terminal, and I have been using PyCharm to code the exercises for this course. Is there more to it than that?

That results in “/usr/bin/python3”. What does that tell us?

It is - although I do not know whether it comes with every installation.

To be honest, I am not sure what the actual difference between python and pythonw is, as there are different explanations out there (and they seem to have changed over the time) and I did not care until yet…

See e.g. this:

python vs pythonw - Python (bytes.com)

Does anybody have a precise, up to date explanation true for all platforms?

Cheers, Dominik

Unfortunately there is some truth in that… :crazy_face:

At least package managers alike pip -and everything coming with that- are very *nix like, if you ask me…

Cheers, Dominik

Try to execute the Python executable (whatever you find there) in that directory in a terminal using the full path, e.g.:

/usr/bin/python3/python3 -i

and/or

/usr/bin/python3/python -i

and/or

/usr/bin/python3/pythonw -i

and/or…

If that works, you get into interactive mode - where you can see the version of Python in the startup message or you then can use the Python commands:

import sys
sys.version

(you alternatively also can run python with the --version option instead of -i, but I prefer the -i as I feel, that you also verify that python REALLY is capable of running… Just a personnel thing maybe:)

Is this the Python version you want to run?

Cheers, Dominik

It should tell that python3 is installed and should be usable. From terminal, if you enter python3 on prompt something like this should happen:

+ > python3
Python 3.9.4 (v3.9.4:1f2e3088f3, Apr  4 2021, 12:32:44)
[Clang 6.0 (clang-600.0.57)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>>

Good…

I am not using PyCharm, so I have no experience in how to choose the Python interpreter / environment there, but maybe the following link can help you with that:

Configure a system interpreter | PyCharm (jetbrains.com)

Cheers, Dominik

Ah, thanks for the link. That explains the difference.

Here’s the word of god from the official documentation:

https://docs.python.org/3/using/mac.html#running-scripts-with-a-gui

The oldest version of that doc I have been able to find is here:

https://docs.python.org/2.6/using/mac.html#running-scripts-with-a-gui

And here is the man page:

So prior to version 2.5, the regular python executable was not
linked to the Aqua window manager and so could not run GUI
applications. Hence the pythonw. Since 2.5 and beyond, the name
pythonw has been left for backwards compatibility.

On Windows, python will open a console in another window, which some
people find distracting. So pythonw runs as a background task so that
there is no console.

1 Like

Yes, there is Python on Windows. Microsoft is possibly the biggest
sponsor of Python development, Guido works for them, and they offer
Python for free through the Windows App Store.