惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

T
Tenable Blog
P
Privacy International News Feed
L
LINUX DO - 热门话题
T
Threatpost
Latest news
Latest news
C
Cybersecurity and Infrastructure Security Agency CISA
Cisco Talos Blog
Cisco Talos Blog
Cyberwarzone
Cyberwarzone
Spread Privacy
Spread Privacy
Recent Announcements
Recent Announcements
C
CXSECURITY Database RSS Feed - CXSecurity.com
The Register - Security
The Register - Security
MongoDB | Blog
MongoDB | Blog
NISL@THU
NISL@THU
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
G
GRAHAM CLULEY
K
Kaspersky official blog
L
Lohrmann on Cybersecurity
V
Vulnerabilities – Threatpost
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
Last Week in AI
Last Week in AI
Google DeepMind News
Google DeepMind News
Y
Y Combinator Blog
博客园 - 三生石上(FineUI控件)
WordPress大学
WordPress大学
H
Help Net Security
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
C
Cisco Blogs
Security Latest
Security Latest
博客园 - 叶小钗
博客园 - Franky
The Hacker News
The Hacker News
Engineering at Meta
Engineering at Meta
Scott Helme
Scott Helme
S
Securelist
The GitHub Blog
The GitHub Blog
云风的 BLOG
云风的 BLOG
博客园 - 【当耐特】
A
About on SuperTechFans
C
Cyber Attacks, Cyber Crime and Cyber Security
博客园_首页
B
Blog RSS Feed
D
Darknet – Hacking Tools, Hacker News & Cyber Security
月光博客
月光博客
有赞技术团队
有赞技术团队
T
The Blog of Author Tim Ferriss
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
H
Hackread – Cybersecurity News, Data Breaches, AI and More
T
Tor Project blog
A
Arctic Wolf

博客园 - 星河赵

LangChain AI 客服 Agent 项目学习笔记 海外stripe 聚合支付 ffmpeg 介绍 AE中制作带可替换屏幕的视频模版 记录|AI超写实短视频制作流程+提示词 服务端部署Vue 在Pycharm 中使用 Python Module 方式启动 uvicorn Conda 虚拟环境完整指南 CentOS / OpenCloudOS 服务器如何安装远程桌面 Python 项目模块导入问题解决方案 2026 谷歌 Antigravity 最新安装教程! Vscode 常用配置 如何修改 Redis 数据存放路径 Vue 后台项目 Nginx 部署笔记(SPA / Vite 构建) Ubuntu 上安装 MongoDB 并启用事务的完整流程 mac 微信双开新方法 nginx 对静态资源进行压缩 HMAC-SHA256 请求签名与验签实践(Python 可直接复用) python fast api websocket 连接事例 在 Flask 中并发执行任务 Vscode 配置快捷键和JetBrains(pycharm)一样 Linux 服务器的 SSH 登录端口号 从默认的 22 改掉 配置 Docker 镜像加速器 python fast api 部署
Python -m 用法(极简版)
星河赵 · 2025-12-18 · via 博客园 - 星河赵

是什么?

按“模块名”运行代码,不是按文件路径


标准写法

python -m 包名.子包名.模块名

  • ❌ 不写 .py

  • ❌ 不用 /

  • ✅ 用 .


为什么用 -m

  • 自动把项目根目录加入 sys.path

  • 和 FastAPI / Gunicorn / pytest 的 import 行为一致

  • 避免 ModuleNotFoundError


对比

python xxx.py # 容易找不到项目包(不推荐) python -m pkg.mod # 正确、稳定(推荐)


运行位置

cd 项目根目录 python -m app_ads_svr.models.developer


一句话记忆

只要 import 以项目名开头,就用 python -m

posted on 2025-12-18 09:58  星河赵  阅读(23)  评论(0)    收藏  举报