zsh

How to Fix ‘zsh: command not found: virtualenv’ on Mac

Encountering the ‘zsh: command not found: virtualenv’ error in Virtualenv is a common issue that can arise when trying to activate a virtual environment, but the system cannot locate the appropriate command. This error prevents you from properly managing and utilizing virtual environments for your Python projects. However, there are various reasons behind this error and several steps you can take to fix it. This guide will cover all the necessary methods required to help you fix the issue.

What are the Reasons for the ‘zsh: command not found: virtualenv’

There are multiple reasons for the ‘zsh: command not found:virtualenv’ error in macOS, which are given below:

1: Missing Virtualenv Installation on Zsh

The ‘zsh: command not found: virtualenv’ error can occur because of a missing Virtualenv installation on your Mac system.

2: Virtualenv Not in PATH

The PATH environment variable is a crucial factor that could become a reason for generating the command not found error. If your Virtualenv executable directory is not present in the system’s PATH environment variable, you will experience the error.

How to Fix ‘zsh: command not found: virtualenv’ on Mac

To fix the ‘zsh: command not found:virtualenv’ issue, the only way to do this is to install Virtualenv on your Mac system.

Install Virtualenv on Mac

The easiest way to install Virtualenv on Mac is through the Python Package Manager called (pip). You should open the Zsh shell and run the following command to install Virtualenv on macOS.

pip3 install virtualenv

In most cases, after performing this step, the error will be resolved. As in my case, after installing Virtualenv through pip, I immediately run the following command to ensure no error occurs now.

virtualenv --version

If you still getting the ‘zsh: command not found: virtualenv’, you can try uninstalling it first from the system using the following command:

sudo uninstall virtualenv

Then reinstalling it again with sudo privileges.

sudo pip3 install virtualenv

Conclusion

The ‘zsh: command not found: virtualenv’ error in Virtualenv can be frustrating, but you can resolve it easily by installing the Virtualenv on your macOS from the pip install command. Once, you managed to install it on your system, there is hardly any chance of error occurring after that. If you still encounter an error, you can try installing it with sudo privileges to fix the issue and effectively manage virtual environments for your Python projects.

About the author

Awais Khan

I'm an Engineer and an academic researcher by profession. My interest for Raspberry Pi, embedded systems and blogging has brought me here to share my knowledge with others.