In this section, we will be learning about the installation of Python on different platforms, such as Linux and Windows.
Python installation
Installation on the Linux platform
Most Linux distributions have Python 2 in their default installations. Some of them also have Python 3 included.
To install python3 on Debian-based Linux, run the following command in the Terminal:
sudo apt install python3
To install python3 on centos, run the following command in the Terminal:
sudo yum install python3
If you are unable to install Python using the preceding commands, download Python from https://www.python.org/downloads/ and follow the instructions.
Installation on the Windows platform
For installing Python in Microsoft Windows, you'll have to download the executable from python.org and install it. Download python.exe from https://www.python.org/downloads/ and choose the Python version that you want install on your PC. Then, double-click on the downloaded exe and install Python. On the installation wizard, there's checkbox that says Add Python to the path. Check this checkbox and then follow the instructions to install python3.
Installing and using pip to install packages
In Linux, install pip as follows:
sudo apt install python-pip --- This will install pip for python 2.
sudo apt install python3-pip --- This will install pip for python 3.
In Windows, install pip as follows:
python -m pip install pip
Installation on Mac
To install python3, first we must have brew installed on our system. To install brew on your system, run the following command:
/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
By running the preceding command. brew will get installed. Now we will install python3 using brew:
brew install python3
Installing Jupyter notebook
For installing the Jupyter Notebook, download Anaconda.
Install the downloaded version of Anaconda and follow the instructions on the wizard.
Install Jupyter using pip:
pip install jupyter
In Linux, pip install jupyter will install Jupyter for python 2. If you want to install jupyter for python 3, run the following command:
pip3 install jupyter
Installing and using the virtual environment
Now we will see how to install the virtual environment and how to activate it.
To install the virtual environment on Linux, perform the following steps:
- First check whether pip is installed or not. We are going to install pip for python3:
sudo apt install python3-pip
- Install the virtual environment using pip3:
sudo pip3 install virtualenv
- Now we will create the virtual environment. You can give it any name; I have called it pythonenv:
virtualenv pythonenv
- Activate your virtual environment:
source venv/bin/activate
- After your work is done, you can deactivate virtualenv by using following command:
deactivate
In Windows, run the pip install virtualenv command to install the virtual environment. The steps for installing virtualenv are same as with Linux.
Installing Geany and PyCharm
Download Geany from https://www.geany.org/download/releases and download the required binaries. Follow the instructions while installing.
Download PyCharm from https://www.jetbrains.com/pycharm/download/#section=windows and follow the instructions.