In previous articles we have studied about Python Introduction and the difference between Python 2 and version 3. In this guide we’ll install Python interpreter on Windows, mac and on Linux platform and execute a simple example to verify it.
As you already know Python is a High-Level interpreted language with higher code readability closer to English. To run any python program, we need Python interpreter installed on our platform. Python has two major version 2 and 3, there is small difference between them which you can study here.
How to Install Python 3 on Windows Platform?
1. Download Python from Here. Download directly available version or select among 32 bit or 64 bit based on your system requirement.
2. Double-click on downloaded file and click on RUN to start installation process.
3. ON pop-up window change installation directory if you want or just check ‘ADD Python 3.7 to PATH’ in below options and click on Install Now.
4. Wait for minute for installation to complete and then click Close.
5. If you forget to check ‘ADD python 3.7 to PATH’, follow instructions mentioned here to add file path (
C:\Users\USERNAMEXX\AppData\Local\Programs\Python\Python37-32) to Environment variable.
6. To verify python version installed. Open command prompt and type python –version or just python or you can also check by IDLE shell installed by python. Click on start>> type python and open IDLE (Python 3.7 32bit).
C:\Users\XXXX>python Python 3.7.1 (v3.7.1:260ec2c36a, Oct 20 2018, 14:05:16) [MSC v.1915 32 bit (Intel)] on win32 Type "help", "copyright", "credits" or "license" for more information. >>>
C:\Users\XXXX>python --version Python 3.7.1 C:\Users\XXXX>
Example using both CMD and Python shell:
1. Copy below program to notepad and save it with python_example.py extension. I saved file on desktop folder python.
2. Open Command prompt and type below commands.
C:\Users\XXXX>cd desktop/python C:\Users\XXXX\Desktop\python>python python_example.py hellocodies.com C:\Users\XXXX\Desktop\python>
1. Open IDLE (Python 3.7 32bit) and enter below line of code and hit enter.
>>>print(“hellocodies.com”) hellocodies.com >>>
How to Install Python 3 on Mac OS X?
Mac comes with Python 2.7.x preinstalled on it. You can check it by typing
python --version command on terminal.
yourmacxxx: ~username$ python Python 2.7.15 (default, Jun 17 2018, 12:46:58) [GCC 4.2.1 Compatible Apple LLVM 9.1.0 (clang-902.0.39.2)] on darwin Type "help", "copyright", "credits" or "license" for more information. >>>
yourmacxxx: ~username$ python --version Python 2.7.15
To install Python 3.7.x follow below instructions.
1. Visit Link and download python.
2. Open the downloaded file, an installation process starts. Change directory if you want or leave it to default. Click three times continue.
3. Agree to terms of license and click Install.
4. Enter password and click on Install Software. Wait for installation to complete than click on close.
5. To verify open terminal and enter
yourmacxxx: ~username$ python3 --version Python 3.7.0
yourmacxxx: ~username$ python3 Python 3.7.0 (default, Jun 29 2018, 20:13:13) [Clang 9.1.0 (clang-902.0.39.2)] on darwin Type "help", "copyright", "credits" or "license" for more information. >>>
Try an Example:
1. Open TextEdit and copy below line and save it as example.py on desktop.
2. Now enter following command on terminal
yourmacxxx:~ username$ cd desktop yourmacxxx: Desktop username$ python example.py hellocodies.com
How to Install Python 3 on Linux?
Use following command to install prerequisites for Python before installing it. Linux comes with 2.x version preinstalled.
User@ubuntuxx:~$ sudo apt-get install build-essential checkinstall sudo apt-get install libreadline-gplv2-dev libncursesw5-dev libssl-dev \ libsqlite3-dev tk-dev libgdbm-dev libc6-dev libbz2-dev
1. Download File using following command from python official site.
cd /usr/src sudo wget https://www.python.org/ftp/python/3.7.1/Python-3.7.1.tgz
2. Now extract the package with commands.
sudo tar xzf Python-3.7.0.tgz
3. Compile python source code using
altinstall used to prevent replacing the default python binary file /usr/bin/python.
cd Python-3.7.1 sudo ./configure --enable-optimizations sudo make altinstall
4. To verify latest version use below command.
User@ubuntuxx:~$ python3.7 -V Python-3.7.1
Try an Example
1. Open a new document and copy below code save to desktop with .py extension (ex. example.py).
2. Now again open Terminal enter following commands.
user@ubuntuxx: ~$ cd Desktop user@ubuntuxx: ~/Desktop$ python example.py hellocodies.com
We have completed our tutorial on how to install python on windows, Linux, Mac and also executed a simple example. Next tutorials will be installing required Python IDE’s and their configuration for larger programs.
Leave your feedback and questions in comment section.