Use python virtual environment
Additionally, using Python virtual environments can provide a robust solution to this error, allowing for isolated Python environments and avoiding conflicts. Virtual environments allow you to create isolated Python environments, each with its own set of packages and dependencies, without interfering with the system-wide Python installation.
When used from within a virtual environment, common installation tools such as pip will install Python packages into a virtual environment without needing of doing it explicitly.
Recent versions of Python 3 include the venv module, which can create virtual environments.
Step 1: Creating a virtual environment
Create a new virtual environment using the ‘venv’ module (Python 3.3 and later):
python3 -m venv myenv
Replace ‘myenv’ with the desired name for your virtual environment.
In the virtual environment ‘myenv,’ as depicted in the above figure, you’ll notice that the ‘bin’ folder contains both ‘pip’ and ‘pip3’. These binaries are automatically generated when creating the virtual environment.
Step 2: Activate the virtual environment
To activate the virtual environment “myenv”, we’ll use source command.
source myenv/bin/activate
When you’ve activated the virtual environment called “myenv,” the ‘pip’ command you’ll be using is located within the ‘myenv/bin’ directory.
Step 3: Installing the package using pip
You can install packages with ‘pip’ without encountering the “pip command not found” error.
pip install <package name>
To deactivate the virtual environment and return to the system-wide Python, simply run:
deactivate
How to Fix “pip command not found” in Linux
Python has become an essential tool for developers, data scientists, and system administrators due to its versatility and robust libraries. To manage Python packages, the ‘pip’ tool is widely used. However, if you’ve encountered the frustrating “pip command not found” error in your Linux system, it can be a roadblock to your workflow. Fortunately, this error can be fixed with a few straightforward steps.