安装#
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.8, 3.9, 3.10, and PyPy.
Python#
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:
conda update sympy
吉特#
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 https://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:
python -m pip install -e .
这将导致安装的版本始终指向git目录中的版本。
其他方法#
您也可以使用pip或从源代码安装SymPy。此外,大多数Linux和Python发行版都有一些SymPy版本,可以使用它们的包管理器进行安装。下面是几个这样的Python发行版的列表:
运行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 Introductory 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
以确保已安装。
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.
问题#
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.