Activate/deactivate conda virtualenvs on entering/leaving directories

后端 未结 1 1759
轮回少年
轮回少年 2021-01-23 13:24

pyenv-virtualenv offers a nice way of activating the environment on the very instant of entering or leaving the directory which contains a .python-version text file

1条回答
  •  离开以前
    2021-01-23 13:46

    As mentioned in my comment, this is currently not supported. There is however an open issue on conda's GitHub asking for this feature.

    In the meantime you could use autoenv, a small tool that'll automatically run the code in a .env file when entering a directory and that in a .env.leave when leaving the directory (supports bash/zsh and a couple others).

    A simple example taken from their readme which illustrates the feature quite nicely:

    $ echo "echo 'whoa'" > project/.env
    $ cd project
    whoa
    

    To load a conda environment your .env would simply look like this:

    conda activate 
    

    Note 1: Check out the Configuration section of their GitHub readme before you start using it.

    Note 2: The author of autoenv actually suggests trying direnv instead. However I've never used it, so I can't comment on it.

    From autoenv's readme:

    you should probably use direnv instead. Simply put, it is higher quality software. But, autoenv is still great, too. Maybe try both? :)

    0 讨论(0)
提交回复
热议问题