かすみん日記

暇なときに何か喋ります

【Python】pympyのインストールとテスト

目的

pythonのライブラリ sympypip でインストールする。

環境

  • macOS Catalina
  • Python 3.7.7
  • pip 20.0.2 from /usr/local/lib/python3.7/site-packages/pip (python 3.7)

sympy のインストール

sympy がインストール済みか確認;

% pip show sympy
WARNING: Package(s) not found: sympy

まだされていない。

sympypip でインストール。

pip install sympy

mpmath というのも一緒にインストールされた。

確認;

% pip show sympy
Name: sympy
Version: 1.5.1
Summary: Computer algebra system (CAS) in Python
Home-page: https://sympy.org
Author: SymPy development team
Author-email: sympy@googlegroups.com
License: BSD
Location: /usr/local/lib/python3.7/site-packages
Requires: mpmath
Required-by: 

sympy のテスト

pythonを起動。

% python
Python 3.7.7 (default, Mar 23 2020, 17:21:07) 
[Clang 11.0.0 (clang-1100.0.33.17)] on darwin
Type "help", "copyright", "credits" or "license" for more information.

sympy をインポートして、使ってみる。

>>> from sympy import *
>>> x = Symbol('x')
>>> limit(sin(x)/x, x, 0)
1
>>> integrate(1/x, x)
log(x)

とりまオーケー。

参考