Skip to content
Advertisement

Why in my Windows machine I have to write command as “py -m pip install “module-name” instead of just writing “pip install “module-name”?

I am working on python on a windows 8.1 machine. I am a beginner and when I want to install a module or look at the version, I have to write the command such as py -m pip install module-name, instead of just writing pip install module-name. If I have to check for python version I have to writepy --version instead of python --version. Why is this happening in my machine and what is the cause? Please explain.

Advertisement

Answer

Pip itself is just a Python module, that’s why you can execute pip with the -m flag like this: python -m pip.

Now to the solution for your problem:

Any command that is accessible from the console is just any executable file somewhere on your disk. The environment variable called “PATH” contains all paths to those executable files. Python go added to this “PATH” variable, but the pip module lies in a different directory that is not in your “PATH”.

So you can just keep running pip like this: py -m pip, it’s literally the same as directly executing pip. Otherwise you can add the following path to your “PATH”:

some/dir/to/your/python/installation/Scripts

The Scripts directory contains the pip executable. After you have added the directory to your “PATH”, you can run pip simply by typing pip into your console.


For your second problem regarding the usage of py and python, the first is a new tool introduced with Python 3.x. It more or less replaces the python command and can be used to run different version of Python:

  • py -2 will start Python 2.x
  • py -3 will start Python 3.x

Not specifying any verson will default to latest installed. The same is stated in this answer to another question.

User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement