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.

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.
    Spotlight Glass in the top right corner
  2. Type in “Terminal” and select the first option.
    Opening Terminal
  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.
    Clicking on the spotlight glass
  2. Type in “Terminal” and select the first option.
    Terminal Opened MacOS
  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.
    Spotlight Glass in the top right corner
  2. Type in “Terminal” and select the first option.
    MacOS Terminal
  3. Type in the following command and press “Enter“.
    sudo apt-get install python-virtualenv
  4. Check to see if the issue persists.

Related Read:  Best macOS Terminal Commands to Get The Most Out of Your Mac in 2023

ABOUT THE AUTHOR

Kevin Arrows


Kevin Arrows is a highly experienced and knowledgeable technology specialist with over a decade of industry experience. He holds a Microsoft Certified Technology Specialist (MCTS) certification and has a deep passion for staying up-to-date on the latest tech developments. Kevin has written extensively on a wide range of tech-related topics, showcasing his expertise and knowledge in areas such as software development, cybersecurity, and cloud computing. His contributions to the tech field have been widely recognized and respected by his peers, and he is highly regarded for his ability to explain complex technical concepts in a clear and concise manner.