Explain Codes LogoExplain Codes Logo

'pip' is not recognized as an internal or external command

python
venv
pip
python-3.x
Anton ShumikhinbyAnton Shumikhin·Oct 18, 2024
TLDR

To fix the pip not recognized issue, you need to add the pip executable's path to your PATH environment variable. Follow these steps for Windows:

  1. Locate your Python Scripts path (C:\Python39\Scripts for instance).
  2. Press Win + R, type sysdm.cpl, hit Enter.
  3. Navigate to Advanced > Environment Variables.
  4. Under System variables, edit the Path.
  5. Click New and paste the Scripts path.
  6. Apply changes, don't forget to restart your command line!

Then finally:

pip --version

If pip shows its version, it means it's now in the PATH!

Just tripping over a pitfall?

Sometimes it's a simple misstep causing the pip not recognized issue. Here are some common ones:

An identity crisis: Python 2.x or 3.x?

If you have both Python 2.x and Python 3.x installed, the correct Scripts folder should be in the PATH. If the pip command isn't recognized, you may be trying Python 2.x pip with Python 3.x and vice versa. Keep them straight!

Did you refresh the shell?

This is akin to "Have you tried turning it off and on again?" After running setx to update the PATH, you need to start a fresh command shell. Try this:

setx PATH "%PATH%;C:\Python39\Scripts"

Remember, much like how refreshing a webpage gives updates, restarting your shell lets you pip away!

Quick spots fix with full paths

Temporary workarounds may get you moving. You can invoke pip with its full path:

C:\Python39\Scripts\pip.exe install 'I_desire_more_knowledge' # or whatever package you want

Yes, it's a bit longer, but gets the job done!

Diving deeper into the configuration

If the simple fixes don't work, don't worry. We can get our hands a bit more dirty:

Working in a bubble with Virtual Environments

Virtual environments encapsulate dependencies, giving you a 'personal bubble' to work in. Once you activate the environment, pip should work if the PATH is set correctly within it, offering a safe and relaxed coding environment.

python -m venv myenv myenv\Scripts\activate

Upgrading to boss level: Administrator rights

Sometimes, even making changes to environment variables requires boss level rights, i.e., running CMD as administrator. This is especially true when using setx. So be the boss and wield the setx command like a boss!

The nuclear option: Reinstall it all

If everything else fails, resort to the scorched earth policy: reinstall Python and pip. During installation, ensure you tick the box that says "Add Python to PATH" this time to avoid going nuclear again!

Ensuring pip access consistently

Ensuring that pip is consistently accessible is crucial. Here are a few tricks to ensure that:

Is the PATH traveled, the right one?

Checking your PATH is crucial when troubleshooting pip issues. A simple echo %PATH% can reveal which paths are recognised by your system.

Should I call you pip or pip3?

Python is a well-mannered language and it differentiates between its versions. If you're using Python 3.x, it's polite to use pip3 instead of pip. Python appreciates good manners!

pip3 install 'manners_matter'

Thank you, Scott, you're a legend!

Scott Bartell's advice of using setx to handle PATH issues have been a life-saver for many. On behalf of the whole Python community, thanks for being awesome, Scott!

Keep in touch with the Official Docs

The official installation guide from the Python Packaging Authority (PyPA) is a goldmine. It should be your first line of defense against any pip problems.

Knowledge is power, keep learning

Stay ahead of the curve by having the latest pip version. Use pip install --upgrade pip regularly and be part of Python forums to learn more.