How to Use Python 3 to Run Python Scripts
Step 1: Verify Python 3 Installation
First, ensure that Python 3 is installed on your system. Open a terminal and type the following command:
python3 --version
You should see an output similar to this:
Python 3.x.x
If Python 3 is not installed, follow the instructions for your operating system to install it.
Step 2: Running a Python Script with Python 3
To run a Python script using Python 3, use the following command format:
python3 your_script.py
For example, if your script is named mc_client.py
, you would run:
python3 mc_client.py
Step 3: Setting Python 3 as the Default Version
If you want to ensure that you are always using Python 3 when you type python
, you can create an alias in your shell configuration file (e.g., .bashrc
or .bash_profile
).
-
Open your shell configuration file in a text editor. For example, to open
.bashrc
:nano ~/.bashrc
-
Add the following line to the file:
alias python='python3'
-
Save the file and exit the text editor.
-
Refresh your shell configuration by running:
source ~/.bashrc
or
```bash
source ~/.bash_profile
```
Now, typing python
will use Python 3 by default.