Installation

The SymPy CAS can be installed on virtually any computer with Python 2.6 or above. SymPy does require mpmath Python library to be installed first. The current recommended method of installation is through Anaconda, which includes mpmath, as well as several other useful libraries. Alternatively, executables are available for Windows, and some Linux distributions have SymPy packages available.

You do not need to install SymPy to try it. You can use the online shell at http://live.sympy.org. You can just use the SymPy Live Sphinx extension to run the code blocks in the browser. For example, click on the green “Run code block in SymPy Live” button below


>>> from sympy import *
>>> x = symbols('x')
>>> a = Integral(cos(x)*exp(x), x)
>>> Eq(a, a.doit())

The SymPy Live shell in the bottom corner will pop up and evaluate the code block. You can also click any individual line to evaluate it one at a time.

The SymPy Live shell is a fully interactive Python shell. You can type any expression in the input box to evaluate it. Feel free to use it throughout the tutorial to experiment.

To show or hide the SymPy Live shell at any time, just click the green button on the bottom right of the screen.

By default, the SymPy Live shell uses \(\LaTeX\) for output. If you want the output to look more like the output in the documentation, change the output format to Str or Unicode in the settings.

If you wish to modify an example before evaluating it, change the evaluation mode to “copy” in the SymPy Live settings. This will cause clicking on an example to copy the example to the SymPy Live shell, but not evaluate it, allowing you to change it before execution. You can also use the up/down arrow keys on your keyboard in the input box to move through the shell history.

Anaconda

Anaconda is a free Python distribution from Continuum Analytics that includes SymPy, Matplotlib, IPython, NumPy, and many more useful packages for scientific computing. This is recommended because many nice features of SymPy are only enabled when certain libraries are installed. For example, without Matplotlib, only simple text-based plotting is enabled. With the IPython notebook or qtconsole, you can get nicer \(\LaTeX\) printing by running init_printing().

If you already have Anaconda and want to update SymPy to the latest version, use:

conda update sympy

Git

If you wish to contribute to SymPy or like to get the latest updates as they come, install SymPy from git. To download the repository, execute the following from the command line:

git clone git://github.com/sympy/sympy.git

To update to the latest version, go into your repository and execute:

git pull origin master

If you want to install SymPy, but still want to use the git version, you can run from your repository:

setupegg.py develop

This will cause the installed version to always point to the version in the git directory.

Other Methods

An installation executable (.exe) is available for Windows users at the downloads site. In addition, various Linux distributions have SymPy available as a package. You may also install SymPy from source or using pip.

Run SymPy

After installation, it is best to verify that your freshly-installed SymPy works. To do this, start up Python and import the SymPy libraries:

$ python
>>> from sympy import *

From here, execute some simple SymPy statements like the ones below:

>>> x = Symbol('x')
>>> limit(sin(x)/x, x, 0)
1
>>> integrate(1/x, x)
log(x)

For a starter guide on using SymPy effectively, refer to the SymPy Tutorial.

Mpmath

Versions of SymPy prior to 1.0 included mpmath, but it now depends on it as an external dependency. If you installed SymPy with Anaconda, it will already include mpmath. Use:

conda install mpmath

to ensure that it is installed.

If you do not wish to use Anaconda, you can use pip install mpmath.

If you use mpmath via sympy.mpmath in your code, you will need to change this to use just mpmath. If you depend on code that does this that you cannot easily change, you can work around it by doing:

import sys
import mpmath
sys.modules['sympy.mpmath'] = mpmath

before the code that imports sympy.mpmath. It is recommended to change code that uses sympy.mpmath to use mpmath directly wherever possible.