Here, we detail the installation of Python on multiple platforms – Linux, Windows, and Mac OS X.
If you're using Linux, Python most probably came pre-installed. If you're not sure, type the following at the command prompt:
which python
Python is likely to be found in one of the following folders on Linux depending upon your distribution and particular installation:
/usr/bin/python
/bin/python
/usr/local/bin/python
/opt/local/bin/python
You can determine which particular version of Python is installed, by typing the following in the command prompt:
python --version
In the rare event that Python isn't already installed, you need to figure out which flavor of Linux you're using, then download and install it. Here are the install commands as well as links to the various Linux Python distributions:
sudo apt-get install python2.7 sudo apt-get install python2.7-devel
Debian Python page at https://wiki.debian.org/Python.
sudo yum install python sudo yum install python-devel
Fedora software installs at http://bit.ly/1B2RpCj.
sudo zypper install python sudo zypper install python-devel
More information on installing software can be found at http://en.opensuse.org/YaST_Software_Management.
Slackware
: For this distribution of Linux, it may be best to download a compressed tarball and install it from the source as described in the following section.If none of the preceding methods work for you, you can also download a compressed tarball (XZ or Gzip) and get it installed. Here is a brief synopsis on the steps:
#Install dependencies sudo apt-get install build-essential sudo apt-get install libreadline-gplv2-dev libncursesw5-dev libssl-dev libsqlite3-dev tk-dev libgdbm-dev libc6-dev libbz2-dev #Download the tarball mkdir /tmp/downloads cd /tmp/downloads wget http://python.org/ftp/python/2.7.5/Python-2.7.5.tgz tar xvfz Python-2.7.5.tgz cd Python-2.7.5 # Configure, build and install ./configure --prefix=/opt/python2.7 --enable-shared make make test sudo make install echo "/opt/python2.7/lib" >> /etc/ld.so.conf.d/opt-python2.7.conf ldconfig cd .. rm -rf /tmp/downloads
Information on this can be found at the Python download page at http://www.python.org/download/.
Unlike Linux and Mac distributions, Python does not come pre-installed on Windows.
The standard method is to use the Windows installers from CPython's team, which are MSI packages. The MSI packages can be downloaded from here: http://www.python.org/download/releases/2.7.6/.
Select the appropriate Windows package depending upon whether your Windows version is 32-bit or 64-bit. Python by default gets installed to a folder containing the version number, so in this case, it will be installed to the following location: C:Python27
.
This enables you to have multiple versions of Python running without problems. Upon installation, the following folders should be added to the PATH
environment variable: C:Python27
and C:Python27ToolsScripts
.
There are a couple of Python tools that need to be installed in order to make the installation of other packages such as pandas easier. Install Setuptools and pip. Setuptools is very useful for installing other Python packages such as pandas. It adds to the packaging and installation functionality that is provided by the distutils
tool in the standard Python distribution.
To install Setuptools, download the ez_setup.py
script from the following link: https://bitbucket.org/pypa/setuptools/raw/bootstrap.
Then, save it to C:Python27ToolsScripts
.
Then, run ez_setup.py
: C:Python27ToolsScriptsez_setup.py
.
The associated command pip
provides the developer with an easy-to-use command that enables a quick and easy installation of Python modules. Download the get-pip
script from the following link: http://www.pip-installer.org/en/latest/.
Then, run it from the following location: C:Python27ToolsScriptsget-pip.py
.
For reference, you can also go through the documentation titled Installing Python on Windows at http://docs.python-guide.org/en/latest/starting/install/win/.
There are also third-party providers of Python on Windows that make the task of installation even easier. They are listed as follows:
Python 2.7 comes pre-installed on the current and recent releases (past 5 years) of Mac OS X. The pre-installed Apple-provided build can be found in the following folders on the Mac:
/System/Library/Frameworks/Python.framework
/usr/bin/python
However, you can install your own version from http://www.python.org/download/. The one caveat to this is that you will now have two installations of Python, and you have to be careful to make sure the paths and environments are cleanly separated.
Python can also be installed using a package manager on the Mac such as Macports or Homebrew. I will discuss installation using Homebrew here as it seems to be the most user-friendly. For reference, you can go through the documentation titled Installing Python on Mac OS X at http://docs.python-guide.org/en/latest/starting/install/osx/. Here are the steps:
ruby -e "$(curl -fsSL https://raw.github.com/mxcl/homebrew/go)"
You then need to add the Homebrew folder at the top of your PATH
environment variable.
brew install python