当前位置: 首页 > news >正文

deactivate: command not found, You’re in a new shell or never activated the venv here.

{-Aaa} astral-uv UV:下一代Python包管理工具的全面指南;虚拟环境 (***) https://blog.csdn.net/ken2232/article/details/155854470

  • UV : can find "deactivate" app in it venv/bin

## In venv, The "deactivate" is valid.

(my_venv) a@pc:~/my_project$ deactivate

## When not in the venv, "deactivate" is NOT valid.

a@pc:~/my_project$ deactivate
deactivate: command not found

# install sudo apt install python3.10-venv # 创建并使用虚拟环境 # 创建项目目录 mkdir my_project cd my_project # 创建虚拟环境 python -m venv my_venv # 激活虚拟环境 source my_venv/bin/activate # macOS/Linux # 或 my_venv\Scripts\activate # Windows # 安装包 pip install flask # 退出虚拟环境 deactivate ## ================== ## In venv "deactivate" is valid. (my_venv) a@pc:~/my_project$ deactivate ## When not in the venv, "deactivate" is NOT valid. a@pc:~/my_project$ deactivate deactivate: command not found

deactivate NOT in the my_venv/bin. It is in the RAM ?

After activated, then in the venv can "deactivate" caommand.

$ tree my_venv/bin my_venv/bin ├── activate ├── activate.csh ├── activate.fish ├── Activate.ps1 ├── pip ├── pip3 ├── pip3.10 ├── python -> /usr/bin/python ├── python3 -> python └── python3.10 -> python 0 directories, 10 files

​​Deactivate Python venv on macOS​​

When working with Python virtual environments on macOS, deactivating them ensures you return to the system’s default Python environment and avoid accidental package installations inside the venv.

1. Deactivate the EnvironmentOnce your venv is active (you’ll see its name in your terminal prompt), simply run:

deactivate

This works inbash,zsh, and other Unix-like shells. It will:

  • Restoreyouroriginal$PATH
  • UnsetVIRTUAL_ENV
  • Resetyourshellprompttonormal

2. Alternative: Close the Terminal SessionIf you forget to rundeactivate, closing the terminal tab or window will also end the venv session automatically.

3. Automating Deactivation in ScriptsWhen using venvs in shell scripts or CI/CD pipelines, always ensure cleanup:

#!/bin/bash

python3 -m venv build-env

sourcebuild-env/bin/activate

pipinstallr requirements.txt

pytest tests/

deactivate

For guaranteed cleanup even on errors:

trap"deactivate"EXIT

sourcebuild-env/bin/activate

# ...commands

This prevents environment leakage into subsequent commands.

4. Troubleshooting

  • deactivate: command not foundYou’reinanewshellorneveractivatedthevenvhere.Activateitfirst,thendeactivate.
  • Prompt doesn’t change backRestarttheshellormanuallyresetPS1.
  • Wrong Python after deactivationCheck$PATHforleftovermodifications.

Best Practices

  • AlwaysdeactivatebeforeswitchingprojectsorupgradingglobalPythonpackages.
  • Keepvenvdirectoriesvenv,.venv,etc.)outofversioncontrolbyaddingthemto.gitignore.
  • Useconsistentnamingforeasierautomation.

By following these steps, you can cleanly exit your Python virtual environment on macOS and maintain a predictable development setup.

http://www.jsqmd.com/news/509380/

相关文章:

  • gte-base-zh离线环境部署:无外网服务器下Xinference+gte-base-zh完全离线安装
  • 如何用MCP彻底重构VS Code开发体验?一线架构师压箱底的6项自动化调试技巧
  • LangGraph 多步推理:State + Node + 条件路由,手写 StateGraph
  • LiquidCrystalWired:面向工业级应用的HD44780 LCD驱动库
  • 百考通:AI赋能答辩PPT,智能生成优质内容,让学术展示更高效从容
  • 苍穹外卖01学习整理
  • 零基础掌握PowerShell脚本编译:Win-PS2EXE可视化工具全指南
  • 【独家首发】MCP 2.0 2026安全白皮书未公开附录A:NIST SP 800-193兼容性测试失败TOP5根因及热修复补丁(限首批200名开发者领取)
  • QMC音乐解密工具:让加密音频文件重获自由的实用指南
  • 4个方面带你掌握EB Garamond 12开源复古字体的全面应用
  • DIVERSEVUL数据集详解:为什么它是目前最全面的漏洞检测数据集?
  • InternLM2-Chat-1.8B赋能Java开发:面试题解析与八股文知识库构建
  • ESP32 IDF5 HTTPS服务器:轻量级嵌入式Web服务开发指南
  • 免费无限生成!Asian Beauty Z-Image Turbo本地化部署与使用全解析
  • ComfyUI-KJNodes插件实战指南:AI工作流优化的终极解决方案
  • 飞阁回澜:青岛栈桥,一座城市的百年守望
  • 卷积神经网络原理与PyTorch实现:环境准备到模型训练
  • AI工程进入Harness时代:新范式核心技术深度解析(非常详细),从入门到精通,收藏这一篇就够了!
  • 自动驾驶中的点云处理:PointPillars算法详解与KITTI数据集实战
  • LongCat-Image-Edit V2案例分享:如何用一句话给图片换主体、加文字
  • 调参实战:在PyTorch和TensorFlow里,epoch、batch size和iterations到底怎么设?看损失曲线说话
  • oss自定义域名+cdn跨域问题解决
  • 2026年电容器厂家最新推荐:高压动态无功补偿发生装置/高压无功补偿/高压电力电容器/高压电容器/选择指南 - 优质品牌商家
  • OctoPrinter:Arduino轻量级OctoPrint通信库
  • Linux设备驱动核心接口函数体系详解
  • ColorsUtils嵌入式RGB色彩处理库深度解析
  • 2026年时序分类综述论文阅读
  • Pixel Dimension Fissioner实战落地:政务公开文案亲和力提升裂变方案
  • 手机号查QQ号终极指南:3分钟找回遗忘的QQ账号
  • 墨语灵犀入门必看:33语种语言识别(LID)模块与翻译路由决策逻辑