Sunday, October 31, 2021

ItsMyCode: Python pip: command not found Solution

ItsMyCode |

Pip is a recursive acronym for either “Pip Installs Packages” or “Pip Installs Python.” Alternatively, pip stands for “preferred installer program.” Basically, it is a package manager that allows you to download and install packages. If you try to install packages without pip installed, you will get an error pip: command not found.

In this article, we will look at the cause of this error and possible solutions to fix this error which you are encountering.

pip: command not found

The issue differs based on the environment and the os which you are using. Let’s understand how the pip is packaged into different environments.

Error Message from Bash:

bash: pip: command not found

Error Message from DOS command line:

'pip' is not recognized as an internal or external command,
operable program or batch file.
  1. Linux – If you have installed Python on a Linux environment, the pip does not come with Python, and you need to install pip package manager as a separate package. Hence in Linux, if you try to install a package, you will get a pip: command not found error as there is no pip package installed.
  2. Mac – On a mac, if you install the latest version of Python 3.x, you don’t have to worry about installing it separately. It comes shipped with Python distributable.
  3. Windows – On windows again, you don’t have to install the pip separately. It comes with Python distributable.

As you already know, Python 2 has reached the the end of life, which means it is no longer actively maintained and supported. If you are still using Python 2, then you should consider moving it to Python 3 and it comes with pip3.

How to check if pip is installed correctly?

The first and foremost thing to do is to check if you have already installed pip in your machine. In windows, you can check if the pip is located in the below directory. So just navigate to the directory and do check for pip.exe or pip3.exe files. If it’s not present, then you need to install it.

Check here for pip3.exe:

C:\Users\YOUR_USERNAME\AppData\Local\Programs\Python\Python36\Scripts

Note: Replace the YOUR_USERNAME with your actual username.

Installing pip the right way

1) On windows, run your Python installer once again and ensure you check the install pip checkbox in the wizard as shown in the below image.

Install pip on windowsInstall pip on windows

2) On Linux, you can install pip3 by running an apt-get command in your terminal.

sudo apt-get -y install python3-pip

Once you have run this command, you should use the pip3 package manager commands to download the packages. 

3) On Mac, pip is bundled with the Python distributable, so you need to re-install Python once again by executing the below command. Once you have re-installed Python 3, you should be able to execute pip commands.

brew install python3

Installing pip for Python 2

If you are still working on Python 2 and want to install an older version of a pip, you can install it by running the below command on your Linux machine.

sudo easy_install pip

This command installs the pip command onto your system. If you do not already have easy_install installed, install it using the following Linux command:

sudo apt-get install python-setuptools

The post Python pip: command not found Solution appeared first on ItsMyCode.



from Planet Python
via read more

No comments:

Post a Comment

TestDriven.io: Working with Static and Media Files in Django

This article looks at how to work with static and media files in a Django project, locally and in production. from Planet Python via read...