Installing, configuring and running SymPy¶
The easiest way to get SymPy is to type sudo pip install sympy , which will download the latest version of the package from PyPI and install it. If you want to get the source and install it manually, visit this page and download the latest tarball from Featured Downloads section, or use the following direct link:
You will also find an installer for Windows there. An alternative way is to clone SymPy’s git repository from GitHub:
To use it, issue:
If you want SymPy to be available globally, you can install it using ./setup.py install . SymPy is available in major Linux distributions, so you can install it also using package manager of your distribution (for example in Ubuntu install python-sympy and in Gentoo install dev-python/sympy ). Note that distributions often contain very outdated versions of packages, so make sure you don’t install some ancient version of SymPy on your system.
By default, SymPy doesn’t have any dependencies besides Python. The following version of Python are supported: 2.5, 2.6, 2.7. Version 2.4 was originally supported but was dropped in SymPy 0.7.1. Support for Python 3.2+ will be added in version 0.7.2 (use git version for now). Version 0.7.2 will also support PyPy 1.6+. If you use Jython, IronPython or other interpreter, you may find out SymPy not working properly (Jython) or not importing at all (IronPython).
Certain SymPy’s modules may require additional dependencies to provide more features or improve speed of computations. For example, sympy.polys and sympy.mpmath can take advantage of gmpy library to radically improve speed of otherwise pure Python library. If gmpy is not available, those modules fall back automatically to pure Python implementation of arithmetic routines. Other optional dependencies are IPython, Matplotlib, NumPy, SciPy, Cython, Pyglet, LaTeX distribution and more.
Translating SymPy to Python 3¶
Support for Python 3.2+ was added to master branch of SymPy’s repository and will be a part of 0.7.2 release. If you use SymPy from git, then you can switch to Python 3 now. However, SymPy’s source is not compatible with Python 3 by default and you have to translate it:
Make sure you run use2to3 under Python 3.2, because Python 3.0 and 3.1 will fail translating SymPy. Although you can’t translate SymPy using Python 3.1 and this version isn’t officially supported, SymPy works very well in it, just if you run python3.1 bin/test , you will get a few harmless failures
SymPy in Python/IPython¶
Sessions in standard Python’s interpreter and IPython look very similar, just the banner and prompt look differently, for example:
Interactive SymPy ( isympy )¶
For users’ convenience, SymPy’s distribution includes a simple script called isympy (see bin/isympy ). isympy uses either IPython (if available) or standard Python’s interpreter with readline support. On startup isympy sets up the environment to make interaction with SymPy more pleasant. It enables new division, imports everything from sympy , injects a few commonly used symbols into the global namespace, and initializes the pretty printer.
Here is an example session with isympy:
Command-line arguments¶
There are a variety of command-line options supported by isympy:
-h , --help show help -c CONSOLE , --console=CONSOLE select type of interactive session: ipython , python . Default is ipython if IPython is installed, otherwise, python . -p PRETTY , --pretty=PRETTY setup pretty printing: unicode , ascii or no . Default is unicode if the terminal supports it, otherwise, ascii . -t TYPES , --types=TYPES setup ground types: gmpy , python or sympy . Default is gmpy if it’s installed, otherwise python . -o ORDER , --order=ORDER setup ordering of terms: [rev-]lex , [rev-]grlex , [rev-]grevlex or old . Default is lex . -q , --quiet print only version information at startup -C , --no-cache disable caching
Environment variables¶
Running the test suite¶
To verify that SymPy works properly on your computer, you can run SymPy’s test suite. This is done either with bin/test command or test() in an interactive session. For example, to test sympy.core issue:
This tells us that all standard tests in sympy.core ‘s pass (dots). In case of failure, . would change to F and OK to FAIL (additionally all failures would be colored in red and listed at the end of output from SymPy’s test utility). Non-standard tests are those marked with f and X characters. The former means that the test was supposed to fail and failed (XFAIL), whereas the later means that the test was supposed to fail but passed (XPASS).
To run the whole test suite issue bin/test or test() without any arguments. Running the whole test suite takes more than ten minutes on Pentium-M 1.6 GHz and less than 5 minutes on Xeon 3.0 GHz (one core).
There is another test utility in SymPy, bin/doctest , which verifies examples in docstrings and documentation. If you are going to contribute to SymPy, make sure you run both bin/test and bin/doctest before submitting a pull request.
SymPy in web browsers¶
SymPy is available in the following web applications:
- SymPy Live (http://live.sympy.org)
- Sage Notebook (http://www.sagenb.org)
SymPy Live was developed specifically for SymPy. It is a simple web shell that looks similar to isympy under standard Python’s interpreter. SymPy Live uses Google App Engine as computational backend.
Upcoming IPython Notebook (IPython 0.12+) will have native support for SymPy. If you use IPython from git, you can test this feature now by starting IPython with ipython notebook and run %load_ext sympy in an input cell. This will setup pretty printing among other things.
Installation¶
Alternatively, you can download SimPy and install it manually. Extract the archive, open a terminal window where you extracted SimPy and type:
You can now optionally run SimPy’s tests to see if everything works fine. You need pytest for this. Run the following command within the source directory of SimPy:
Upgrading from SimPy 2¶
If you are already familiar with SimPy 2, please read the Guide Porting from SimPy 2 to 3 .
What’s Next¶
Now that you’ve installed SimPy, you probably want to simulate something. The next section will introduce you to SimPy’s basic concepts.
Installation¶
The SymPy CAS can be installed on virtually any computer with Python. SymPy does require mpmath Python library to be installed first. The recommended method of installation is through Anaconda, which includes mpmath, as well as several other useful libraries. Alternatively, some Linux distributions have SymPy packages available.
SymPy officially supports Python 3.7, 3.8, 3.9, and PyPy.
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 \(\mathrm<\LaTeX>\) printing by running init_printing() .
If you already have Anaconda and want to update SymPy to the latest version, use:
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:
To update to the latest version, go into your repository and execute:
If you want to install SymPy, but still want to use the git version, you can run from your repository:
This will cause the installed version to always point to the version in the git directory.
Other Methods¶
You may also install SymPy using pip or from source. In addition, most Linux and Python distributions have some SymPy version available to install using their package manager. Here is a list of several such Python distributions:
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:
From here, execute some simple SymPy statements like the ones below:
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:
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:
before the code that imports sympy.mpmath . It is recommended to change code that uses sympy.mpmath to use mpmath directly wherever possible.
Questions¶
If you have a question about installation or SymPy in general, feel free to visit our chat on Gitter. In addition, our mailing list is an excellent source of community support.
If you think there’s a bug or you would like to request a feature, please open an issue ticket.