Flexiple Logo
  1. Home
  2. Blogs
  3. Python
  4. pip Command Not Found – Mac and Linux Error (Solved)

pip Command Not Found – Mac and Linux Error (Solved)

Author image

Mayank Jain

Software Developer

Published on Tue Mar 05 2024

The error "pip: command not found" indicates a situation where the system is unable to recognize the 'pip' command. This typically happens when Python's package manager, pip, is not installed on the system, or if it's installed but not added to the system's PATH. Pip is essential for managing software packages written in Python, allowing users to install, uninstall, and manage package dependencies. If the system cannot locate pip, it means any commands that attempt to use pip to manage Python packages will fail. This error is common on both Mac and Linux operating systems where pip may not come pre-installed or might be improperly configured. To resolve this issue, one must ensure pip is installed and correctly set up in the system's environment.

How to troubleshoot the error pip: command not found

To troubleshoot the error "pip: command not found," follow these step-by-step instructions:

  1. Check if Python is Installed: Pip is bundled with Python versions 2.7.9+ and 3.4+. Open a terminal and type python --version or python3 --version to verify Python's installation. If Python is not installed, you must install it first.
  2. Install Pip: If Python is installed but pip is missing, install pip by downloading the get-pip.py script. Run curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py to download the script, then execute it with python get-pip.py or python3 get-pip.py for Python 3.
  3. Verify Pip Installation: After installation, check pip is installed correctly by typing pip --version or pip3 --version. This command should return the pip version installed.
  4. Add Pip to PATH: If pip is installed but the system can't find it, it's likely not in your PATH. For Mac, you can add it to your PATH by editing your .bash_profile or .zshrc file with export PATH="$PATH:/path/to/pip". On Linux, the file to edit might be .bashrc or .profile. Replace /path/to/pip with the actual path to pip's installation directory.

Example: If pip is installed in /usr/local/bin/pip, you would add export PATH="$PATH:/usr/local/bin" to your .bash_profile or .zshrc, then run source ~/.bash_profile or source ~/.zshrc to refresh your environment.

  1. Use the Correct Command: Be aware that Python 2 and Python 3 have different pip commands (pip for Python 2, pip3 for Python 3). Ensure you are using the correct version for your Python scripts.
  2. Reinstall Python and Pip: If all else fails, reinstalling Python (making sure to install a version that includes pip) might be necessary. When installing Python from the official website, ensure the option to install pip is selected.

By following these steps, you should be able to resolve the "pip: command not found" error and use pip to manage Python packages on your system.

How to use pip

To use pip, follow these guidelines to effectively manage Python packages:

  1. Installing Packages: To install a package, use the command pip install package_name. For example, to install the requests library, you would run pip install requests. This command downloads the package from PyPI (Python Package Index) and installs it on your system.
  2. Upgrading Packages: To upgrade an existing package to the latest version, use pip install --upgrade package_name. For instance, pip install --upgrade requests will update the requests library to its latest version.
  3. Listing Installed Packages: To see a list of all installed packages and their versions, use pip list. This command provides a quick overview of the current packages that are installed in your Python environment.
  4. Uninstalling Packages: To remove a package, use pip uninstall package_name. For example, pip uninstall requests will remove the requests library from your system. You will be asked to confirm the uninstallation process before it proceeds.
  5. Searching Packages: If you're looking for a package but don't know its exact name, pip search search_query can help find it by searching the PyPI repository. However, note that the pip search functionality may be deprecated or limited in some versions of pip; alternative methods include searching directly on the PyPI website.
  6. Checking for Outdated Packages: To check which packages are outdated and can be upgraded, use pip list --outdated. This command lists all installed packages that have newer versions available on PyPI.

Example: Installing a specific version of a package requires appending the version number after the package name, like so: pip install package_name==version_number. For instance, pip install requests==2.18.4 installs version 2.18.4 of the requests library, regardless of whether newer versions are available.

By mastering these basic pip commands, you can manage Python packages efficiently, ensuring your projects have the right dependencies and are up-to-date.

Conclusion

Encountering the "pip: command not found" error on Mac and Linux systems can be a common issue for developers. However, by following the troubleshooting steps outlined in this article, you can quickly resolve the problem and make pip available for managing Python packages. Understanding how to install pip, add it to your system's PATH, and use its basic commands are essential skills for any Python developer. With pip correctly set up, you can easily install, upgrade, and manage the Python packages required for your projects, ensuring a smoother development process.

Related Blogs

Browse Flexiple's talent pool

Explore our network of top tech talent. Find the perfect match for your dream team.