Computer >> Computer tutorials >  >> Troubleshooting >> Linux

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.

How to Fix ‘Command Not Found’ Error on Virtualenv?

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:

  1. Click on the “Spotlight Glass” in the top right corner.How to Fix ‘Command Not Found’ Error on Virtualenv?
  2. Type in “Terminal” and select the first option.How to Fix ‘Command Not Found’ Error on Virtualenv?
  3. You must have installed the program using the following command
    pip install virtualenv
  4. Type in the following command and press “Enter
    sudo /usr/bin/easy_install virtualenv
  5. 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:

  1. Click on the “Spotlight Glass” in the top right corner.How to Fix ‘Command Not Found’ Error on Virtualenv?
  2. Type in “Terminal” and select the first option.How to Fix ‘Command Not Found’ Error on Virtualenv?
  3. Type in the following command and press “Enter
    pip uninstall virtualenv
  4. After that, type in the following command and press “Enter
    sudo pip install virtualenv
  5. 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:

  1. Click on the “Spotlight Glass” in the top right corner.How to Fix ‘Command Not Found’ Error on Virtualenv?
  2. Type in “Terminal” and select the first option.How to Fix ‘Command Not Found’ Error on Virtualenv?
  3. Type in the following command and press “Enter“.
    sudo apt-get install python-virtualenv
  4. Check to see if the issue persists.