Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cannot deactivate virtual environment - zsh: command not found: deactivate

I have created a basic django project within a virtual environment using VS Code on macOS. It works fine. But I cannot find anyway to deactivate the virtual environment.

I activated the virtual environment on macOS using the terminal in VS Code.

python3 -m venv .venv
source .venv/bin/activate

My problem is that I cannot close the virtual environment using deactivate. I get the error that the deactivate command is not found.

zsh: command not found: deactivate

I have tried opening a separate terminal and activating and deactivating the same virtual environment, and it works fine. But I am stuck within my project on VS Code. Simply exiting the terminal does not work.

I have done a lot of searching but cannot find a solution. All advice simply points to deactivate

What can I do? Please help!

like image 278
Mark Todman Avatar asked Jun 30 '26 03:06

Mark Todman


1 Answers

I think this is my lack of understanding of VSCode folders. But, I think I understand now.

I have installed venv in my django project folder, so when I open my django project folder in VSCode, the venv activate script runs. That way, I always work in the project's virtual environment, which avoids issues.

I cannot deactivate the virtual environment whilst this django project folder is open in VSCode, and this is where the command not found error occurs.

If I do not have the django project folder open in VSCode I can activate and deactivate the virtual environment through the terminal as expected.

like image 113
Mark Todman Avatar answered Jul 02 '26 17:07

Mark Todman



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!