在 PyCharm 中管理虚拟环境(Virtual Environment)非常方便,主要有创建、切换、删除、查看依赖等操作。下面按常见场景给你梳理一下。
New ProjectPython Interpreter 处选择:
New Virtual Environmentvenv)CreateFile → Settings(macOS:PyCharm → Settings)Project: xxx → Python InterpreterAddVirtualenv EnvironmentNew environmentSettings → Python InterpreterAddVirtualenv Environment → Existing environmentvenv/bin/python # macOS / Linux
venv\Scripts\python.exe # Windows
Settings → Python InterpreterShow All 管理多个环境Settings → Python Interpreter+ 安装包- 卸载确保使用的是当前虚拟环境:
pip install requests
pip freeze > requirements.txt
PyCharm 本身不直接删除 venv 文件夹
venv 文件夹Settings → Python Interpreter → Show All 中移除解释器| 类型 | PyCharm 支持 | 说明 |
|---|---|---|
| venv | ✅ | Python 官方,最常用 |
| virtualenv | ✅ | 老牌方案 |
| conda | ✅ | 数据科学常用 |
| pipenv | ⚠️ | 需手动配置 |
| poetry | ⚠️ | 需插件/手动 |
✅ 每个项目一个 venv
✅ 提交 requirements.txt,不提交 venv/
✅ 用 PyCharm 的 Terminal 自动激活环境
如果你愿意,可以告诉我:
我可以给你更具体的配置示例。
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。