# The python Utility

> "Python is a programming language that lets you work quickly and integrate systems more effectively" - [Python Website](https://www.python.org/)

Before you can execute Python programs on your computer, you'll first need to install the Python command-line utility.

Over the past few years there has been a shift in the community from Python Version 2 to Python Version 3. But these days we assume everyone is using Python 3, and this semester we will be using Python 3, exclusively. We might use different minor versions of Python 3 (like 3.7 or 3.8), depending on their compatibility with specific third-party packages we may be using on a given project.

Anaconda provides a command-line utility called `conda` to help us manage different versions of Python. Before proceeding, please take a moment to [install Anaconda and get familiar with the `conda` utility](https://prof-rossetti.gitbook.io/intro-to-python/notes/clis/conda).

When you are ready, either use the Anaconda default "base" environment, or create and activate a new Anaconda environment, and within the environment execute the commands below.

## Detecting Installations

To see if Python is already installed, and if so where:

```bash
# Mac Terminal:
which python

# Windows Command Prompt or Git Bash:
where python
```

If you see a filepath output, it means Python is installed at the location specified, so you can advance to the version detection instructions below. Otherwise, if you see an empty result or an error message, that usually means Python is not installed.

## Detecting Versions

Let's see which version of Python is installed:

```bash
python --version
```

If you see a result here like "Python 3.8.3" (or some other 3.x version), it means the specified version of Python is installed, so you can advance to the usage instructions below. Otherwise, if you see an empty result, error message, or 2.x version, that usually means Python is not installed (properly).

## Usage

After Python is installed, you should be able to execute Python commands.

### Interactive Console

```bash
# Mac Terminal:
python

# Windows Git Bash:
python -i # for interactive
```

If you type `python` on Mac Terminal (or `python -i` on Windows Git Bash) and press "enter", you will enter into an interactive Python console where you can evaluate Python statements and expressions. When you are done using the Python console, you can shut it down by typing `exit()` and pressing "enter".

![a screenshot of using the python console to perform a simple calculation (2+2 = 4)](https://2741866142-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-Lxirt-fOkHNRdT9uASu%2F-LxyAjPAv2RY6Fzg9ag1%2F-LxyAwcR8ARWVwGI9XWd%2Fpython-console.png?generation=1578370078133223\&alt=media)

### Executing Scripts

You can alternatively use the `python` utility to execute a pre-written Python program, by specifying its filepath. To test this out yourself, follow the instructions in the [Hello World (Local) Exercise](https://prof-rossetti.gitbook.io/intro-to-python/exercises/hello-world/local).

```bash
python path/to/my_script.py
```

![a screenshot of the output resulting from running a python script from the command-line. the hello message is printed in the terminal](https://2741866142-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-Lxirt-fOkHNRdT9uASu%2F-LxyAjPAv2RY6Fzg9ag1%2F-LxyAwcTEpUqxj3m4C18%2Frunning-python-scripts.png?generation=1578370078428255\&alt=media)


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://prof-rossetti.gitbook.io/intro-to-python/notes/clis/python.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
