

Auto activate and deactivate python venv using zsh
source link: https://dev.to/moniquelive/auto-activate-and-deactivate-python-venv-using-zsh-4dlm
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.


Posted on Dec 17
Auto activate and deactivate python venv using zsh
When I found out about python venv (apt-get install python3-venv
) I became an instant addict. It's clean, it's built-in and it's explicit.
Now every time I create a new project folder I automatically run python3 -mvenv venv && source ./venv/bin/activate
.
But typing ./venv/bin/activate
and then deactivate
is too much work for my lazy programmer head.
So I decided to finally invest 10 minutes to free me from activating and deactivating python's env every time I enter or leave a folder with my standard ./venv
folder:
#---------------------------------------------- chpwd pyvenv ---
python_venv() {
MYVENV=./venv
# when you cd into a folder that contains $MYVENV
[[ -d $MYVENV ]] && source $MYVENV/bin/activate
# when you cd into a folder that doesn't
[[ ! -d $MYVENV ]] && deactivate > /dev/null 2>&1
}
autoload -U add-zsh-hook
add-zsh-hook chpwd python_venv
python_venv
Enter fullscreen mode
Exit fullscreen mode
edit: just figured out that deactivating was working because of other stuff installed in my shell. Now it's a bit more agressive but works 100%
Recommend
-
21
使用指南 - @Livid - 比如这样的:https://www.v2ex.com/t/519424欢迎大家举报类似的其他水贴。---关于 Deactivate 是什么:https://ww
-
11
要不我们还是用回 virtualenv/venv 和 pip 吧 5条回复这篇文章没什么新东西,只是介绍古老又靠谱的 Python 虚拟环境和依赖管理方式:virtualenv/venv+pip。...
-
11
Python Link to External Project in Venv To re-use my Django code, I have been writing Django Apps. Usually, I push an app to Digital Ocean, then use pip to pull it and install it in my projects. Sometimes I want to tw...
-
13
Armin's BlogPython虚拟环境——venvMay 04, 2016venv 是 python 3.3 以后自带的虚拟环境,在不同虚拟环境里,能够独立安装不同版本的库,互不干扰。 本文将在 venv 中安装 tensorflow。在虚拟环境中...
-
7
Quickly activate or deactivate AirDrop using Control Center [Pro tip]There's no need to fi...
-
9
How do I activate or deactivate the button according to the value of the variable? advertisements I use pure javascript. I have this row in my...
-
8
Trying to activate / deactivate a contraction player with javascript in HTML advertisements So I'm trying to learn some HTM...
-
6
Python3.10.4激活venv环境失败解决方法 精选 原创 环境 python -m venv venv
-
5
How to know I'm using venv Python Jul 26, 2023 Solution 1: use sys.prefix that points to the Python directory Solution 2 (the better way): VIRTUAL_EN...
-
2
Using Virutal Environment in Python with venv2023-10-11Python249 words 2 mins read 43 times readUsing a virtual environme...
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK