简体   繁体   中英

How can I get stub files for `matplotlib`, `numpy`, `scipy`, `pandas`, etc.?

I know that the stub files for built-in Python library for type checking and static analysis come with mypy or PyCharm installation. How can I get stub files for matplotlib , numpy , scipy , pandas , etc.?

Type stubs are sometimes packaged directly with the library. Otherwise there can be some external libraries to provide them.

Numpy

Starting with numpy 1.20 type stubs will be included in numpy. See this changelog and this PR adding them

Before that they could added with the library https://github.com/numpy/numpy-stubs

Pandas and Matplotlib

There is no official support for these libraries stubs but you can find unofficial stubs in this project: https://pypi.org/project/data-science-types/

You can either install this library as a dependency or copy only the relevant part in the type stubs folder of your project.

If you are using VSCode and Pylance extension with strict type checking enabled, you can generate stub files automatically by just pressing quickfix option and press "Create Type Stub for " module " "

在此处输入图像描述

As of July 2022 there are official pandas stubs: https://github.com/pandas-dev/pandas-stubs

This is the home for pandas typing stubs supported by the pandas core team. The stubs are likely incomplete in terms of covering the published API of pandas.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM