Although virtualenv is convenient because you can freely switch the Python environment, if you are dealing with multiple projects at the same time, move to the directory one by one and execute a command such as source .venv / bin / activate
. It's a little troublesome to have to do it.
Therefore, if there is a virtualenv setting in the directory with zsh, try setting it to automatically switch the environment.
In zsh, the chpwd
function is automatically called when the directory is changed. Using this, for example, when the directory name that stores virtualenv is .venv
, set as follows.
function chpwd() {
if [ -d .venv ]; then
source .venv/bin/activate
fi
}
Now when you cd to the directory with zsh, virtualenv can be enabled automatically.
Recommended Posts