(Sponsors) Get started learning Python with DataCamp's free Intro to Python tutorial. Learn Data Science by completing interactive coding challenges and watching videos by expert instructors. Start Now!
Installing Python 3 on Windows/Linux/Mac
To install Python 3 on Windows, Linux and Mac systems, follow the instructions below:
- Installing Python on Windows
- Installing Python on Linux
- Installing Python on Mac
Installing Python 3 on Windows #
Windows OS doesn't come with Python pre-installed, so you will have to install it manually.
Open your favorite browser and visit https://www.python.org/. Find the Download link for Python 3.X.
[]
At the time of writing the current version was 3.8.0. If you see any newer version of Python, don't worry! Just download the latest version you see on the page.
Once the download is complete, double-click the file to start the installation wizard.
When you see a screen like this:
[]
tick the box saying "Add Python 3.8 to PATH" and click the "Install Now" button.
Adding Python to PATH
environment variable allows you to run python.exe
from any working directory in the command-line or PowerShell.
Once the installation is finished, the wizard screen will look like this:
[]
You have made through the installation part. Now, its time to check the Python installation.
Verifying Python Installation on Windows #
Open Command prompt by pressing Ctrl+R and typing "cmd" in the run window.
[]
[]
You can also get to the Command prompt by typing "cmd" in the Start menu.
[]
To verify you can run Python from the command-line type python --version
and you will be displayed the version of the Python installed on your system.
[]
Installing Python 3 on Mac #
Python may be already installed on your Mac. To check follow these steps:
- Activate Spotlight by pressing
Cmd+Space
- Type
terminal
and hit enter - In the terminal window type
python3 --version
.
[]
On this machine, I have Python 3.5, which is fine for our purposes. If you have any other version of Python 3, thats fine too.
If you don't have Python installed or have an older version of it. Either way, start your browser and point it to https://python.org. Look for the download button for Python 3.X and click on it.
[]
At the time of writing the latest Python version was 3.8.0. Don't be put off if you see some different version. Just go ahead with the latest version.
When the download is complete. Start the installation wizard by double-clicking on it.
[]
Hit the continue
button several times and go through the regular onscreen instructions.
[]
Once the installation wizard is done you will get a screen like this:
[]
Verifying Python Installation on Mac #
Python 3 is now installed on your Mac. To verify that you can run Python from the command-line, start a new terminal session and type python3 --version
.
[]
Installing Python 3 on Linux #
Unlike, Windows and Mac, Linux comes pre-installed with with both Python 2 and 3.
Use the following commands to check for existing Python installation.
1 2 3 4 5 6 7 | $
$ python3 --version # check Python 3 version
Python 3.6.8
$
$ python --version # check Python 2 version
Python 2.7.15+
$
|
The system on which I ran these commands had Python 3.6.8 installed, which is fine for our purposes. If you have any other version of Python 3, thats fine too.
However, if want to work with the latest version of Python then you will have to install it manually.
There are several ways to install the latest version of Python on Linux:
Update the system
Some Linux distributions automatically update to latest version of Python when you update the system. The only issue with this approach is that Linux distributions use different commands for installing packages which makes it harder to nail down just one way of doing something. For example, the following command updates Ubuntu or Ubuntu based distributions like Linux Mint, Kubuntu, Xubuntu etc.
sudo apt-get update && sudo apt-get upgrade
The command to update Red hat based distributions like Fedora, CentOS is as follows:
sudo dnf update
After updating the system, restart it and check the latest version of the Python by typing
python3 --version
in the terminal.Install Python from source
Installing Python from source is quite straight forward provided you have installed all the dependencies. Unfortunately, this is again where things starts to get ugly, as commands varies from distribution to distribution.
The following command installs all the packages required to build Python from source on Ubuntu and its derivatives.
1 2 3 4 5 6
sudo apt install build-essential \ \ libssl-dev zlib1g-dev \ libncurses5-dev libncursesw5-dev \ libreadline-dev libsqlite3-dev \ libgdbm-dev libdb5.3-dev libbz2-dev \ libexpat1-dev liblzma-dev tk-dev libffi-dev
Once all the prerequisites are installed building Python is quite trivial.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
# download the Python 3.8.0 source wget https://www.python.org/ftp/python/3.8.0/Python-3.8.0.tar.xz # extract the archive tar -xvf Python-3.8.0.tar.xz # change current working directory to Python-3.8.0/ cd Python-3.8.0/ # build python ./configure make make install # create shortcut sudo ln -s /usr/local/bin/python3.8 /usr/bin/python3.8
!At the time of writing the latest version of Python was 3.8.0. So, you will have to update the commands accordingly with newer versions of Python.
Congratulations, you have successfully installed Python 3.
In the next lesson, we create and run our first Python program.
Check #
Start a new terminal session by pressing Cmd
, Space
to activate and spotlight search, type terminal and hit enter.
Start a new terminal session by pressing Cmd
, Space
and enter the following
To start terminal, activate spotlight search by pressing Cmd, Space, then type terminal and hit enter.
If you facing a dilemma whether you have already installed Python or have some old version of it. Use the following commands to find out whether you have Python installed or not.
Other Tutorials (Sponsors)
This site generously supported by DataCamp. DataCamp offers online interactive Python Tutorials for Data Science. Join over a million other learners and get started learning Python for data science today!
View Comments