How to leave/exit/deactivate a Python virtualenv

前端 未结 13 1636
春和景丽
春和景丽 2020-11-27 08:42

I\'m using virtualenv and the virtualenvwrapper. I can switch between virtualenv\'s just fine using the workon command.

me@mymachine:~$ workon          


        
13条回答
  •  心在旅途
    2020-11-27 09:12

    I use zsh-autoenv which is based off autoenv.

    zsh-autoenv automatically sources (known/whitelisted) .autoenv.zsh files, typically used in project root directories. It handles "enter" and leave" events, nesting, and stashing of variables (overwriting and restoring).

    Here is an example:

    ; cd dtree 
    Switching to virtual environment: Development tree utiles
    ;dtree(feature/task24|✓); cat .autoenv.zsh       
    # Autoenv.
    echo -n "Switching to virtual environment: "
    printf "\e[38;5;93m%s\e[0m\n" "Development tree utiles"
    workon dtree
    # eof
    dtree(feature/task24|✓); cat .autoenv_leave.zsh 
    deactivate
    

    So when I leave the dtree directory, the virtual environment is automatically exited.

    "Development tree utiles" is just a name… No hidden mean linking to the Illuminati in here.

提交回复
热议问题