Python setup for Windows, Mac, Linux

Python is available for various platforms which includes Linux, Windows and Mac OS. So here we are going to understand how to setup python environment. For the local environment setup open the terminal window and type there “python” to know that it is already installed or not, if installed then which version.

  • Unix/Linux
  • Windows
  • Macintosh
  • DOS

The setup of python can be installed from the official website also for the most updated version. Here is the link

http://www.python.org/

For the documentation of python can be downloaded from the same link above.

How to install Python?

As we know python is available for various platforms, so all you need to download only the binary code which is applicable for your platform and install it. If the binary code is not available for your platform, then C compiler is required to compile the code manually.

Now we will see how to install python on different platforms:

Unix and Linux installation:

Steps required to install python on machine are:

  • Open the web browser and go to http://www.python.org/download/ .
  • Follow the link given above and download the zipped source code.
  • After downloading it extract the files.
  • Edit the Modules/Setup file if required.
  • run ./configure script
  • make
  • make install

this install python in the standard location /usr/local/bin and libraries at /usr/local/lib/pythonAA where AA is the version of python.

Now after installation we will set the path. Setting path at Unix/Linux:

The path to add the Python directory in csh shell is:

type setenv PATH “$PATH: /usr/local/bin/python” and then press Enter.

Note*: Do remember Unix is case sensitive.

The path to add Python directory in bash shell which is in Linux:

type export PATH = “$PATH: /usr/local/bin/python” and then press Enter

The path to add Python directory in sh or ksh shell:

type PATH = “$PATH: /usr/local/bin/python” and then press Enter.

 

Windows installation:

Steps required to install Python on Windows are:

  • Open the web browser and go to http://www.python.org/download/ .
  • Follow this link for the Windows installer python- ABC.msi file where ABC is the version.
  • The installer python- ABC.msi can be used when the Windows support the Microsoft Installer 2.0. Save the installer file on to your local machine and then run to make sure that your machine supports MSI.
  • Now run the downloaded file. After installing the wizard accept the default settings and wait till the installation is finished.

After installation we will set up the path in Windows. To add the python directory in windows at the command prompt:

type path %path%;

C: \Python and then press Enter. // It is the path of the python directory

Macintosh Installation

In Mac to use Python there is no need to install or configure anything else. But before installing Python you need to install GCC. GCC can be obtained by downloading XCode, Command Line Tool or OSX GCC Installer package. But if you have installed XCode then there is no requirement to install OSX-GCC installer because it can cause issues. As you perform a fresh install of XCode you will need to add the command line tools by running xcode-select –install on the terminal. As OS X consists of large number of UNIX utilities, the one who is familiar with Linux systems will notice one key component missing that is a decent package manager, Homebrew will fill this void.

Now to install Homebrew open the terminal or OS X terminal emulator and run

                     $ ruby –e “$(curl –fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)”

After installing Homebrew add the Homebrew directory on the top of your path environment variable or it can be done by

                 ~/ .profile file

 

The statement of path is

Export PATH = /usr/local/bin: /usr/local/sbin: $PATH

Now Python 2.7 can be installed.

$ brew install python

Now we will have a look on the simple program of python.

num1 = input('Enter first number: ')

num2 = input('Enter second number: ')

 

#it will add two numbers

sum = float(num1) + float(num2)

 

# display the sum

print('The sum of {0} and {1} is {2}'.format(num1, num2, sum))

 

Output:

Enter first number: 4

Enter second number: 4

The sum of 4 and 4 is 8.0

In the above code the numbers are entered by user and it displays the sum of two numbers which are entered by user. In this we have used built-in-function input ( ) to take the input from the user and it will return the string which is then converted into number which is using float ( ) function. The two numbers are added through arithmetic operator (+), we can also change the operator according to the program requirements such as subtraction, multiplication, division.

Leave A Comment

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.