To install SymPy in Python, simply run the following command in your shell:
pip install sympy
This works for all major operating systems (MacOS, Windows, Linux). A preliminary is to have the pip package manager installed.
(Confused by all the libraries, modules, pip, and virtual environments? Read the ultimate library guide on my blog.)
To check whether it has installed correctly, simply run the following command in your Python shell:
>>> help(sympy) Help on package sympy: NAME sympy DESCRIPTION SymPy is a Python library for symbolic mathematics. It aims to become a full-featured computer algebra system (CAS) while keeping the code as simple as possible in order to be comprehensible and easily extensible. SymPy is written entirely in Python. It depends on mpmath, and other external libraries may be optionally for things like plotting support. See the webpage for more information and documentation: https://sympy.org PACKAGE CONTENTS abc algebras (package) assumptions (package)
The output validates that the sympy package has installed correctly.
What’s SymPy Anyway?
SymPy is a Python library for symbolic computation. So instead of approximating the result of the square root of 2, it keeps the square root intact—using a symbolic representation. This helps in further processing and can lead to situations where Python has introduced a floating point precision error without need. Here’s a basic example:
import sympy print(sqrt(3)) # sqrt(3)
The result is NOT an approximated square root of 3 like in the math package:
import math print(math.sqrt(3)) # 1.7320508075688772
Where to go from here?
Are you tired of reading boring programming books? Get your “Coffee Break Python” now! It’s a Leanpub #1 bestseller in the category Python.
While working as a researcher in distributed systems, Dr. Christian Mayer found his love for teaching computer science students.
To help students reach higher levels of Python success, he founded the programming education website Finxter.com that has taught exponential skills to millions of coders worldwide. He’s the author of the best-selling programming books Python One-Liners (NoStarch 2020), The Art of Clean Code (NoStarch 2022), and The Book of Dash (NoStarch 2022). Chris also coauthored the Coffee Break Python series of self-published books. He’s a computer science enthusiast, freelancer, and owner of one of the top 10 largest Python blogs worldwide.
His passions are writing, reading, and coding. But his greatest passion is to serve aspiring coders through Finxter and help them to boost their skills. You can join his free email academy here.