一、查看程序包(Packages / Library)的當前版本和路徑(Pandas爲例)
終端命令
pip 命令:
- 列出所有已安裝的程序包:
pip list
或pip freeze
- 檢查已安裝程序包的詳細信息:
pip show <package-name>
conda 命令:conda list
pip show pandas
# Name: pandas
# Version: 1.0.1
# Summary: Powerful data structures for data analysis, time series, and statistics
# Home-page: https://pandas.pydata.org
# Author: None
# Author-email: None
# License: BSD
# Location: /Users/Lemon/opt/anaconda3/lib/python3.7/site-packages
# Requires: python-dateutil, pytz, numpy
# Required-by: statsmodels, seaborn
Python腳本、Jupyter
pd.__version__
獲取Pandas版本號,其他程序包也適用
pd.__path__
獲取安裝路徑
pd.show_versions()
輸出詳細信息,包括Python版本和相關程序包以及操作系統類型
import pandas as pd
print(pd.__version__)
# '1.0.1'
print(pd.__path__)
# ['/Users/Lemon/opt/anaconda3/lib/python3.7/site-packages/pandas']
print(pd.show_versions())
# INSTALLED VERSIONS
# ------------------
# commit : None
# python : 3.7.6.final.0
# python-bits : 64
# OS : Darwin
# OS-release : 19.4.0
# machine : x86_64
# processor : i386
# byteorder : little
# LC_ALL : None
# LANG : zh_CN.UTF-8
# LOCALE : zh_CN.UTF-8
# pandas : 1.0.1
# numpy : 1.18.1
# pytz : 2019.3
# dateutil : 2.8.1
# pip : 20.0.2
# setuptools : 46.0.0.post20200309
# Cython : 0.29.15
# pytest : 5.3.5
# hypothesis : 5.5.4
# sphinx : 2.4.0
# blosc : None
# feather : None
# xlsxwriter : 1.2.7
# lxml.etree : 4.5.0
# html5lib : 1.0.1
# pymysql : None
# psycopg2 : None
# jinja2 : 2.11.1
# IPython : 7.12.0
# pandas_datareader: None
# bs4 : 4.8.2
# bottleneck : 1.3.2
# fastparquet : None
# gcsfs : None
# lxml.etree : 4.5.0
# matplotlib : 3.1.3
# numexpr : 2.7.1
# odfpy : None
# openpyxl : 3.0.3
# pandas_gbq : None
# pyarrow : None
# pytables : None
# pytest : 5.3.5
# pyxlsb : None
# s3fs : None
# scipy : 1.4.1
# sqlalchemy : 1.3.13
# tables : 3.6.1
# tabulate : None
# xarray : None
# xlrd : 1.2.0
# xlwt : 1.3.0
# xlsxwriter : 1.2.7
# numba : 0.48.0
二、查看Python版本
終端命令
python --version
# Python 3.7.6
python -V
# Python 3.7.6
python -VV
# Python 3.7.6 (default, Jan 8 2020, 13:42:34)
# [Clang 4.0.1 (tags/RELEASE_401/final)]
python3 -V
# Python 3.7.6
Python腳本
sys.version
返回字符串,包括Python解釋器的版本號以及有關內部版本號和使用的編譯器的其他信息sys.version_info()
返回元組形式的Python版本號sys.version_info[0]
或sys.version_info.major
查看是Python2還是Python3platform.python_version()
返回字符串形式的Python版本號platform.python_version_tuple()
返回元組形式的Python版本號
import sys
print(sys.version)
# 3.7.6 (default, Jan 8 2020, 13:42:34)
# [Clang 4.0.1 (tags/RELEASE_401/final)]
print(sys.version_info)
# sys.version_info(major=3, minor=7, micro=6, releaselevel='final', serial=0)
print(sys.version_info[0])
print(sys.version_info.major)
# 3
import platform
print(platform.python_version())
# 3.7.6
print(platform.python_version_tuple())
# ('3', '7', '6')
參考:
Check the version of Python package / library
Check Python version from command line / in script