[PYTHON] Automatically enable virtualenv when cd to a directory with zsh

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

Automatically enable virtualenv when cd to a directory with zsh
A memorandum when I tried to get it automatically with selenium
Precautions when installing a hierarchical include directory with waf
I tried to automatically generate a password with Python3
Current directory when creating a new one with Jupyter
Apply conda's env to a specific directory with pyenv-vertualenv
Solution when you want to use cv_bridge with python3 (virtualenv)
How to return to the previous directory with the Bash cd command
I tried to automatically create a report with Markov chain
Create a Mastodon bot with a function to automatically reply with Python
[python] A note when trying to use numpy with Cython
Create a directory with python
A note I was addicted to when creating a table with SQLAlchemy
How to use virtualenv with PowerShell
When using MeCab with virtualenv python
Operate Paints Chainer with Selenium to automatically color images in the directory
I made a tool to automatically browse multiple sites with Selenium (Python)
Gist repository to use when you want to try a little with ansible
When you want to replace a column with a missing value (NaN) column by column
Create a tool to automatically furigana with html using Mecab from Python3
[Python / Pandas] A bug occurs when trying to replace a DataFrame with `None` with` replace`
I get a UnicodeDecodeError when trying to connect to oracle with python sqlalchemy
[Outlook] I tried to automatically create a daily report email with Python
Join CentOS 8.3 with SSSD to Active Directory
How to add a package with PyCharm
A workaround when installing pyAudio with pip.
How to install zsh (with .zshrc customization)
[Linux command] From moving to macintosh (top directory) with cd command to connecting vagrant ssh
When I tried to make a VPC with AWS CDK but couldn't make it
When I connect to a remote Jupyter Server with VScode, it's remote but local
When I tried to connect with SSH, I got a warning about free space.
A note I was addicted to when running Python with Visual Studio Code
A story that I was addicted to when I made SFTP communication with python
How to get a list of files in the same directory with python