Setting up Python on macOS

·

This post is part of my series on Learning Python with ChatGPT.

While I do know some of the basics, as I’m trying to see how well ChatGPT can guide me as a student, I’m going to approach it as an absolute beginner and see how ChatGPT approaches it and teaches me.

Some of the screenshots below are parts of the conversation, but it should be enough to convey the discussion and overall feel of the session.

I tried to do that, and immediately faced an error.

matt@Matthews-MBP ~ % python --version

zsh: command not found: python

matt@Matthews-MBP ~ % which python

python not found

I copied the errors back to ChatGPT and it recommended that I install Homebrew

The output you provided indicates that Python is not installed on your Mac by default. The "command not found" message for python and which python commands suggests that there is no Python interpreter available in your system's PATH.

To install Python on your Mac, you can follow these steps:

Install Homebrew (if not already installed):

Homebrew is a package manager for macOS that makes it easy to install various software, including Python.

I had to push back a bit and get an alternative solution that I was more comfortable with, which was to download Python from the official site and install it. If you didn’t know what Homebrew was, you wouldn’t be able to push back and ask ChatGPT for an alternative solution, so that is slightly concerning.

That being said, after I did some Googling, using Homebrew did seem to be the recommended solution, so I’d say ChatGPT got that right.

After installing Python via the installer downloaded from the official site, I was still unable to check my version of Python, getting an error.

matt@Matthews-MBP ~ % python --version

zsh: command not found: python

matt@Matthews-MBP ~ %

ChatGPT suggested that I do this (amongst other things)

I apologize for any confusion. It seems that Python is not added to your system's PATH after installing it from the official website. You can try the following steps to resolve this issue:

Check Python Version:

Instead of using python --version, try running the following command to check the installed Python version:

python3 --version

It didn’t work, but I was facing a new error message, which I copied for ChatGPT to digest.

xcode-select: note: No developer tools were found, requesting install.

If developer tools are located at a non-default location on disk, use sudo xcode-select --switch path/to/Xcode.app to specify the Xcode that you wish to use for command line developer tools, and cancel the installation dialog.

ChatGPT came back with this solution

The error message you're seeing indicates that the Xcode command line tools are not installed on your Mac. These tools are required to compile and install certain software, including Python. You can resolve this issue by following these steps:

Install Xcode Command Line Tools:

Open Terminal and run the following command to install the Xcode command line tools:

bash

Copy code

xcode-select --install

After I ran through that installation process, I’m happy to say it worked!

My thoughts on this

While I’m sure I could have searched for a solution and get to the same outcome, it’s much more comfortable to have a conversation and be able to ask things back and forth this way. Not to mention I’m only dealing with an individual entity (ChatGPT), as opposed to reading different solutions from different sites and posts on the Internet and having to piece an answer together.

I always felt that one of the major obstacles to getting started in programming was getting the environment set up. Back in college you had lab computers or environments that were already set up for you. While was is practical from an efficiency point of view, it does remove the important part of learning programming, which would be getting the environment up and running.

A follow up question

While I’m writing this post, I realised that while I was trying to get Python installed, I didn’t ask why Xcode Command Line Tools were needed, and I was just blindly following the instructions (not a good thing, but it’s never too late).

After chatting with ChatGPT on many other topics on Python over several days, I decided to see if it could still remember and refer back to the issue I faced, so that I could go back ask about it in more detail. 

It remembered and I could ask it further questions. So I have to say I’m pretty happy with that. In the future, I’m still thinking I might ask it to include a number to all its responses, so that I can refer back to the past conversation in an even easier manner, but this will do for now.

After that I also asked ChatGPT to explain to me what a system PATH was, and got a very good answer. I’d give out some bonus points right there.