1

I'd like to install the pygame package through IPython but when I try the command suggested here,

!pip install pygame

I get the following error:

'pip' is not recognized as an internal or external command, operable program or batch file.

What should I do? If it helps, I'm on Windows 10 and Python 3.6.1. Thanks!

  • `pip` is for Python 2.x. `pip3` is for Python 3.x. You have Python 3.6.1. Which command should you use? – ForceBru May 20 '18 at 20:15
  • On Windows, [as explained here](https://packaging.python.org/guides/installing-using-pip-and-virtualenv/#windows) as well as in the official docs, it's usually recommended to use `py -m pip` (or `python -m pip` if you're not using the `py.exe` launcher, or `C:\path\to\specific\python -m pip`, etc.). – abarnert May 20 '18 at 20:21
  • @ForceBru That's usually not true on Windows. `pip` will either be accessible on the PATH as `pip`, or not at all, even for 3.x. – abarnert May 20 '18 at 20:22

1 Answers1

1

As the Python Packaging Authority docs on Installing packages using pip explain, on Windows, you usually don't want to use pip directly. It may not be on your PATH, or it may be on your PATH but not match the same version as the py.exe launcher.

Usually, you want to use that py.exe launcher for everything:

py -m pip install pygame

If you're not using py.exe for some reason, the answer is usually one of these:

python -m pip install pygame
D:\path\to\specific\python -m pip install pygame

The official docs mention the python version first, and only mention py for when you're dealing with multiple Python versions. But you're probably better off always using py, as the PyPA suggests. See PEP 397 for why the launcher is useful.)


Of course if you want to do this from inside IPython instead of directly at the shell, prefix any of those with !.


As a side note: Notice that the same page pretty strongly recommends using virtualenv (or the builtin venv, but the documentation is all for virtualenv). You should consider doing so, but if you have a good reason not to, it's not mandatory or anything.

abarnert
  • 354,177
  • 51
  • 601
  • 671