Python Programming/Getting Python
In order to program in Python you need the Python interpreter. If it is not already installed or if the version you are using is obsolete, you will need to obtain and install Python using the methods below:
Python 2 vs Python 3[edit | edit source]
In 2008, a new version of Python (version 3) was published that was not entirely backward compatible. Developers were asked to switch to the new version as soon as possible, but many of the common external modules are not yet (as of Aug 2010) available for Python 3. There is a program called 2to3 to convert the source code of a Python 2 program to the source code of a Python 3 program. Consider this fact before you start working with Python. Now we are in the era of Python3.6
The latest version of Python 2, i.e. Python 2.7.x, was officially discontinued on 1 January 2020.
Installing Python in Windows[edit | edit source]
In order to run Python from the command line, you will need to have the python directory in your PATH. Alternatively, you could use an Integrated Development Environment (IDE) for Python like DrPython, eric, PyScripter, or Python's own IDLE (which ships with every version of Python since 2.3).
The PATH variable can be modified from the Window's System control panel. To add the PATH in Windows 7 :
- Go to Start.
- Right click on computer.
- Click on properties.
- Click on 'Advanced System Settings'
- Click on 'Environmental Variables'.
- In the system variables select Path and edit it, by appending a ';' (without quote) and adding 'C:\python27'(without quote).
If you prefer having a temporary environment, you can create a new command prompt short-cut that automatically executes the following statement:
If you downloaded a different version (such as Python 3.1), change the "27" for the version of Python you have (27 is 2.7.x, the current version of Python 2.)
Cygwin[edit | edit source]
By default, the Cygwin installer for Windows does not include Python in the downloads. However, it can be selected from the list of packages.
Installing Python on Mac[edit | edit source]
Users on Apple Mac OS X will find that it already ships with Python 2.3 (OS X 10.4 Tiger) or Python 2.6.1 (OS X Snow Leopard), but if you want the more recent version head to Python Download Page follow the instruction on the page and in the installers. As a bonus you will also install the Python IDE.
Installing Python on Unix environments[edit | edit source]
Python is available as a package for some Linux distributions. In some cases, the distribution CD will contain the python package for installation, while other distributions require downloading the source code and using the compilation scripts.
Gentoo Linux[edit | edit source]
Gentoo is an example of a distribution that installs Python by default — the package management system Portage depends on Python.
Ubuntu Linux[edit | edit source]
Users of Ubuntu will notice that Python comes installed by default, only it sometimes is not the latest version. To check which version of Python is installed, type
into the terminal.
Arch Linux[edit | edit source]
Arch Linux does not come with Python pre-installed by default, but it is easily available for installation through the package manager to pacman. As root (or using sudo if you've installed and configured it), type:
pacman -S python
This will be update package databases and install Python 3. Python 2 can be installed with:
pacman -S python2
Other versions can be built from source from the Arch User Repository.
Source code installations[edit | edit source]
Some platforms do not have a version of Python installed, and do not have pre-compiled binaries. In these cases, you will need to download the source code from the official site. Once the download is complete, you will need to unpack the compressed archive into a folder.
To build Python, simply run the configure script (requires the Bash shell) and compile using make.
Other Distributions[edit | edit source]
Python, which is also referred to as CPython, is written in the C Programming language. The C source code is generally portable, that means CPython can run on various platforms. More precisely, CPython can be made available on all platforms that provide a compiler to translate the C source code to binary code for that platform.
Apart from CPython there are also other implementations that run on top of a virtual machine. For example, on Java's JRE (Java Runtime Environment) or Microsoft's .NET CLR (Common Language Runtime). Both can access and use the libraries available on their platform. Specifically, they make use of reflection that allows complete inspection and use of all classes and objects for their very technology.
Python Implementations (Platforms)
|Jython||Java Version of Python||Jython|
|IronPython||C# Version of Python||IronPython|
Integrated Development Environments (IDE)[edit | edit source]
CPython ships with IDLE; however, IDLE is not considered user-friendly. For Linux, KDevelop and Spyder are popular. For Windows, PyScripter is free, quick to install, and comes included with PortablePython. The best py used GUI Builder is actually Boa Constructor, but has suffered from bit rot significantly, so it is best to be used in conjunction with LiClipse.
Some Integrated Development Environments (IDEs) for Python
|ActivePython||Highly flexible, Pythonwin IDE||ActivePython|
|Eclipse (PyDev plugin)||Open-source IDE||Eclipse|
|Eric||Open-source Linux/Windows IDE.||Eric|
|KDevelop||Cross-language IDE for KDE||KDevelop|
|Ninja-IDE||Cross-platform open-source IDE.||Nina-IDE|
|PyScripter||Free Windows IDE (portable)||PyScripter|
|Spyder||Free cross-platform IDE (math-oriented)||Spyder|
|VisualWx||Free GUI Builder||VisualWx|
The Python official wiki has a complete list of IDEs.
There are several commercial IDEs such as Komodo, BlackAdder, Code Crusader, Code Forge, and PyCharm. However, for beginners learning to program, purchasing a commercial IDE is unnecessary.
Trying Python online[edit | edit source]
You can try Python online, thereby avoiding the need to install. Keywords: REPL.
Keeping Up to Date[edit | edit source]
Python has a very active community and the language itself is evolving continuously. Make sure to check python.org for recent releases and relevant tools. The website is an invaluable asset.
Public Python-related mailing lists are hosted at mail.python.org. Two examples of such mailing lists are the Python-announce-list to keep up with newly released third party-modules or software for Python and the general discussion list Python-list. These lists are mirrored to the Usenet newsgroups comp.lang.python.announce & comp.lang.python.