Python: Difference between revisions
From charlesreid1
(Created page with "[http://www.python.org Python] is a handy language whose syntax is easy to learn. Python is a scripting language that is similar in syntax to Matlab, but has the power of object...") |
No edit summary |
||
| Line 1: | Line 1: | ||
[http://www.python.org Python] is a handy language whose syntax is easy to learn. Python is a scripting language that is similar in syntax to Matlab, but has the power of object-oriented languages such as C++. Python is also extensible, and many libraries and packages are available for nearly every function imaginable. For example, Numpy and Scipy provide tools often used in scientific programming, such as matrix and vector objects, not inherently provided by Python. | [http://www.python.org Python] is a handy language whose syntax is easy to learn. Python is a scripting language that is similar in syntax to Matlab, but has the power of object-oriented languages such as C++. Python is also extensible, and many libraries and packages are available for nearly every function imaginable. For example, Numpy and Scipy provide tools often used in scientific programming, such as matrix and vector objects, not inherently provided by Python. | ||
= Installing Python = | |||
== Mac == | |||
Mac comes with a version of Python built-in, but this version of Python is 2.5, at least 2 major versions behind the latest. It is recommended that you install the latest version of Python 2.x, and get the binary from here: http://www.python.org/download/ (stick with 2.x, since Python 3.x makes some very major changes and probably won't work as expected). | |||
== Linux == | |||
You can use your package manager to install a binary Python, or you can download the source code from here: http://www.python.org/download/ | |||
For instructions related to building software from source, go here: [[Compiling Software]] | |||
== Windows == | |||
You can download the latest version of Python for Windows from this page: http://www.python.org/download/ | |||
It is highly recommended that you install Python in the root of your C drive: when it asks you for an install location, specify C:\Python27. | |||
You can then add folder locations to your <code>$PYTHONPATH</code> variable by editing the Windows environment variables. On Windows XP, right-click on My Computer, click the "Advanced" tab, and click the "Environmental Variables" button. On Windows 7, right-click on Computer, click the "Advanced settings..." link on the left-hand side, and click the "Environmental Variables" button. Once you're there, you'll create a new user variable: variable name <code>PYTHONPATH</code> and variable value <code>C:\Python27</code> (if you want to add other locations, separate them using a semicolon; don't delete any locations that are already there, just add locations). | |||
= Packages = | = Packages = | ||
Revision as of 17:59, 2 October 2010
Python is a handy language whose syntax is easy to learn. Python is a scripting language that is similar in syntax to Matlab, but has the power of object-oriented languages such as C++. Python is also extensible, and many libraries and packages are available for nearly every function imaginable. For example, Numpy and Scipy provide tools often used in scientific programming, such as matrix and vector objects, not inherently provided by Python.
Installing Python
Mac
Mac comes with a version of Python built-in, but this version of Python is 2.5, at least 2 major versions behind the latest. It is recommended that you install the latest version of Python 2.x, and get the binary from here: http://www.python.org/download/ (stick with 2.x, since Python 3.x makes some very major changes and probably won't work as expected).
Linux
You can use your package manager to install a binary Python, or you can download the source code from here: http://www.python.org/download/
For instructions related to building software from source, go here: Compiling Software
Windows
You can download the latest version of Python for Windows from this page: http://www.python.org/download/
It is highly recommended that you install Python in the root of your C drive: when it asks you for an install location, specify C:\Python27.
You can then add folder locations to your $PYTHONPATH variable by editing the Windows environment variables. On Windows XP, right-click on My Computer, click the "Advanced" tab, and click the "Environmental Variables" button. On Windows 7, right-click on Computer, click the "Advanced settings..." link on the left-hand side, and click the "Environmental Variables" button. Once you're there, you'll create a new user variable: variable name PYTHONPATH and variable value C:\Python27 (if you want to add other locations, separate them using a semicolon; don't delete any locations that are already there, just add locations).
Packages
Py4Sci
The Py4Sci (Python 4 Science) suite consists of 4 Python extensions, which combine to provide a Matlab-like environment. These extensions are:
- iPython - provides an enhanced Python shell
- Numpy - an extension providing numerical routines for vector and matrix objects
- Scipy - an extension providing MATLAB-like functionality (optimization, Fourier transforms, ODE solvers, etc.), typically used in conjunction with data types provided through the Numpy extension
- Matplotlib - provides 2D plotting functionality to Python
Py4Sci on Linux
This is very straightforward, given that most every distribution's package manager has the above 4 Python extensions. Use the following commands for Debian-based distributions (e.g. Ubuntu):
$ apt-get install ipython $ apt-get install numpy $ apt-get install scipy $ apt-get install matplotlib
where one may replace "apt-get" with the appropriate package manager (e.g. "yum" for Fedora).
Py4Sci on Mac
This was formerly a very difficult and frustrating process, which has since become much easier and much more streamlined.
Three links provide the information needed to install the above extensions for Python on Mac OS X.
- Read about the role of built-in Pythons and various other available Pythons on the Mac: http://www.python.org/download/mac/
- Read about the various Python distributions for Mac here: http://wiki.python.org/moin/MacPython/PythonDistributionsForMac
- Download the Python binary from here: http://www.python.org/download/releases/