ARTICLE DETAIL

建站实战干货

来自一线的建站与推广经验沉淀,每一条都经过真实交付验证。

学会了这30个Python库,你就是大神!

2026/9/13 19:48:06 拓冰建站 浏览量
学会了这30个Python库,你就是大神!

1. rich - 丰富的终端输出格式

from rich import printprint("[blue]Hello[/blue] [bold red]World[/bold red]!")

2. PySimpleGUI - 快速构建简单GUI  

import PySimpleGUI as sglayout = [[sg.Text('GUI Demo')], [sg.Input()], [sg.OK()]]  window = sg.Window('My GUI').Layout(layout)

3. moviepy - 视频和GIF处理

from moviepy.editor import VideoFileClipvideo = VideoFileClip("my_video.mp4")  video.subclip(50,60).to_gif() # 截取生成GIF

4. pandas_profiling - Pandas DataFrame数据概览

import pandas_profilingprofile = df.profile_report()  profile.to_file(output_file="output.html")

5. jieba - 中文分词

import jiebatxt = "我爱北京天安门"words = jieba.lcut(txt) print(words) # 精准分词

6. requests - 网络请求

import requestsres = requests.get("https://www.example.com") print(res.status_code)

7. pygame - 游戏开发

import pygamepygame.init() screen = pygame.display.set_mode((640, 480)) pygame.display.set_caption("My Game")

8. matplotlib - 数据可视化

import matplotlib.pyplot as pltx = [1,2,3,4]y = [2,4,6,8]  plt.plot(x, y)  plt.show()

9. numpy - 科学计算

import numpy as npa = np.array([1, 2, 3])  b = np.array([2, 3, 4])c = a + b  print(c) # [3 5 7]

10. sphinx - 生成文档网站 

pip install sphinxcd docssphinx-quickstart # 生成基础配置make html # 转换生成html网站

11. schedule - 定时任务调度

import scheduleimport timedef job():    print("Job running!")schedule.every(10).minutes.do(job)  while True:    schedule.run_pending()    time.sleep(1)

12. pdfplumber - PDF解析处理  

import pdfplumberpdf = pdfplumber.open("sample.pdf")page = pdf.pages[0]  text = page.extract_text()

13. selenium - 浏览器自动化

from selenium import webdriverbrowser = webdriver.Chrome()browser.get("https://www.example.com")

14. sympy - 符号数学计算

from sympy import * x = symbols('x')  integrate(cos(x), x) # sin(x)

15. tqdm - 进度条显示

from tqdm import tqdmfor i in tqdm(range(1000)):     pass # 显示进度条

16. loguru - 现代日志记录

from loguru import loggerlogger.debug("This is a debug message")  logger.info("This is info")

17. pygame_menu - 游戏菜单创建

import pygame_menumenu = pygame_menu.Menu(...)while True:   menu.update(...)   menu.draw(...)

18. pipenv - 环境和依赖管理

pipenv install  # 安装包pipenv shell # 激活虚拟环境pipenv run python main.py # 在环境中运行

19. Questionary - 交互式问答

from questionary import promptusername = prompt("Enter your name: ")  # 查询用户输入

20. pyperclip - 文本复制粘贴

import pyperclip  pyperclip.copy("Text to copy")text = pyperclip.paste()

21. wordcloud - 词云生成   

from wordcloud import WordCloudtext = "A long text..."wc = WordCloud(width=800, height=400)wc.generate(text)wc.to_image()

22. scikit-image - 图像处理

from skimage import io  from skimage.filters import threshold_otsuimg = io.imread('image.jpg')  thresh = threshold_otsu(img) bw = img > thresh # 二值化

23. fuzzywuzzy - 模糊字符串匹配

from fuzzywuzzy import fuzzfuzz.ratio("cafe", "coffee") # 93 测算匹配度

24. pyodbc - 数据库连接

import pyodbc conn = pyodbc.connect('DSN=SQL Server Native Client 11.0', ...)  cursor = conn.cursor()

25. pillow - 图像处理

from PIL import Imageimg = Image.open("image.jpg") img.show() # 展示图片img.resize((640, 480)) # 调整大小

26. mxnet - 深度学习

import mxnet as mx data = mx.sym.Variable('data')fc1 = mx.sym.FullyConnected(data, name='fc1', num_hidden=128)model = mx.mod.Module(symbol=fc1, ...)

27. flask - Web框架  

from flask import Flaskapp = Flask(__name__)@app.route('/')def index():    return 'Hello World!'if __name__ == '__main__':      app.run()

28. gevent - 异步网络框架

import geventfrom gevent import monkeymonkey.patch_all() # 猴子补丁def print_num(n):    print(n)threads = [gevent.spawn(print_num, i) for i in range(10)] gevent.joinall(threads)

29. nltk - 自然语言处理  

import nltkfrom nltk.corpus import brown brown_news = brown.words(categories='news')fdist = nltk.FreqDist(brown_news)print(fdist)

30. beautifulsoup - HTML/XML解析

from bs4 import BeautifulSoupsoup = BeautifulSoup(html, 'html.parser') soup.find_all('p') # 找到所有p标签