Computer >> Hướng Dẫn Máy Tính >  >> Lập Trình >> Python

Kiểm tra version module Python

Khi cài Python, bạn cũng có pip – Python package manager. Dùng pip lấy version module. Muốn list tất cả module đã cài kèm version:

$ pip freeze

Output:

asn1crypto==0.22.0
astroid==1.5.2
attrs==16.3.0
Automat==0.5.0
backports.functools-lru-cache==1.3
cffi==1.10.0
...

Để tìm version riêng lẻ, grep output trên *NIX. Ví dụ:

$ pip freeze | grep PyMySQL
PyMySQL==0.7.11

Windows dùng findstr thay grep. Ví dụ:

PS C:\> pip freeze | findstr PyMySql
PyMySQL==0.7.11

Muốn biết version module trong Python script, dùng attribute __version__ của module. Lưu ý không phải module nào cũng có __version__. Ví dụ:

>>> import pylint
>>> pylint.__version__
'1.7.1'