How to Fix ‘Command Not Found’ Error on Virtualenv?
Virtualenv is used to create isolated python environments. The tool creates a folder that consists of the necessary executables that would need to be launched during a python project. The tool is necessarily used to create a virtual environment for python projects.
However, quite recently, a lot of reports have been coming in of users who are unable to run the Virtualenv commands on MacOS and the “Command Not Found” error is seen while trying to do so.
What Causes the ‘Command Not Found’ Error on Virtualenv in Python?
After receiving numerous reports from multiple users, we decided to investigate the issue and devised a set of solutions to fix it completely. Also, we looked into the reasons due to which the error is triggered and listed them as follows:
- Wrong Directory: If the program has been installed by running a particular “pip” command, it puts it into a different directory than the “/usr/local/bin”. This triggers the error because it needs to be installed in the “/usr/local/bin” directory in order for it to work properly.
- Administrative Privileges: The program needs to be installed with administrative or “Superuser” privileges in order for it to be installed in the right directory and for the command to be recognized. If it isn’t installed with those privileges, this error might be triggered.
Now that you have a basic understanding of the nature of the problem, we will move on towards the solutions. Make sure to implement these in the specific order in which they are presented to avoid conflict.
Solution 1: Changing Directory
If the program hasn’t been installed in the correct directory, this error might be triggered. Therefore, in this step, we will be changing its directory. For that:
- Click on the “Spotlight Glass” in the top right corner.
Spotlight Glass in the top right corner - Type in “Terminal” and select the first option.
Opening Terminal - You must have installed the program using the following command
pip install virtualenv
- Type in the following command and press “Enter”
sudo /usr/bin/easy_install virtualenv
- This will now place the program in the appropriate directory, check to see if the issue persists.
Solution 2: Installing with Administrative Privileges
It is possible that the program has been installed as a normal user and root privileges haven’t been granted due to which the error is being triggered. Therefore, in this step, we will be granting the root privileges while installing the program. For that:
- Click on the “Spotlight Glass” in the top right corner.
Clicking on the spotlight glass - Type in “Terminal” and select the first option.
Terminal Opened MacOS - Type in the following command and press “Enter”
pip uninstall virtualenv
- After that, type in the following command and press “Enter”
sudo pip install virtualenv
- This will install the program with administrative privileges, check to see if the issue persists.
Solution 3: Installing with APT-GET Method
In some cases, installing with the “pip” command doesn’t yield positive results. Therefore, in this step, we will be installing “virtual env” with the “APT-GET” Command. For that:
- Click on the “Spotlight Glass” in the top right corner.
Spotlight Glass in the top right corner - Type in “Terminal” and select the first option.
MacOS Terminal - Type in the following command and press “Enter“.
sudo apt-get install python-virtualenv
- Check to see if the issue persists.
Related Read: Best macOS Terminal Commands to Get The Most Out of Your Mac in 2023