资讯动态

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

发布时间:2026/8/22 10:32:28 来源:尧图企业网站定制
{-Aaa} astral-uv UV下一代Python包管理工具的全面指南虚拟环境 (***) https://blog.csdn.net/ken2232/article/details/155854470UV : can find deactivate app in it venv/bin## In venv, The deactivate is valid.(my_venv) apc:~/my_project$ deactivate## When not in the venv, deactivate is NOT valid.apc:~/my_project$ deactivatedeactivate: 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) apc:~/my_project$ deactivate ## When not in the venv, deactivate is NOT valid. apc:~/my_project$ deactivate deactivate: command not founddeactivate 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:deactivateThis works inbash,zsh, and other Unix-like shells. It will:Restoreyouroriginal$PATHUnsetVIRTUAL_ENVResetyourshellprompttonormal2. 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/bashpython3 -m venv build-envsourcebuild-env/bin/activatepipinstallr requirements.txtpytest tests/deactivateFor guaranteed cleanup even on errors:trapdeactivateEXITsourcebuild-env/bin/activate# ...commandsThis prevents environment leakage into subsequent commands.4. Troubleshootingdeactivate: command not foundYou’reinanewshellorneveractivatedthevenvhere.Activateitfirst,thendeactivate.Prompt doesn’t change backRestarttheshellormanuallyresetPS1.Wrong Python after deactivationCheck$PATHforleftovermodifications.Best PracticesAlwaysdeactivatebeforeswitchingprojectsorupgradingglobalPythonpackages.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.

读完文章,也想定制专属网站?

尧图设计师 24 小时内与您沟通定制方案

免费获取报价