Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

python alias in ~/.zshrc overrides virtual environment source

I've got a couple aliases setup in my terminal session initialization shell script ~/.zshrc

alias python=/opt/homebrew/bin/python3.9
alias pip=/opt/homebrew/bin/pip3.9

These are interfering with my virtual environment workflow:

>>> cd my_project
>>> python -m venv venv
>>> source venv/bin/activate
>>> which python
python: aliased to /opt/homebrew/bin/python3.9

You can see how the virtual environment was not activated. Any suggestions on how I can work with venv while having these aliases setup in my ~/.zshrc?

like image 314
AlexG Avatar asked Mar 26 '26 09:03

AlexG


1 Answers

Create a directory ~/bin. In that directory create two links:

ln -vs /opt/homebrew/bin/python3.9 ~/bin/python
ln -vs /opt/homebrew/bin/pip3.9 ~/bin/pip

Edit your .zshrs to include:

export PATH=~/bin:$PATH

The links will hide the normal executables. When virtualenv will be activated, the links will be hiden by the PATH set up by virtualenv.

like image 124
KamilCuk Avatar answered Mar 29 '26 00:03

KamilCuk



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!