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.

- 68
- 6
-
Although I answered the question already, your question can be easily separated into two different questions. First why you need to use `py -m pip` and second why you can't use `python --version`. I recommend you to research if any of these questions already exist and if not, ask them – SteapStepper69 Jun 12 '20 at 10:47
1 Answers
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.xpy -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.

- 1,247
- 10
- 22
-
2"*Pip itself is just a Python module*" `pip` is also a script. The OP asks why we need to run `py -m pip` instead of just `pip`. – phd Jun 12 '20 at 13:06
-
@phd, actually in Windows pip installs "pip.exe" instead of a text script. This is a convenience wrapper for an entrypoint script in the pip package. It contains an embedded script that imports and runs the `main` function of the pip package. The executable wrapper gets the fully-qualified path of "python.exe" from the shebang of this embedded script and runs it with the executable itself passed as a command line argument. This relies on Python's zip importer to run the script that's embedded in the executable. – Eryk Sun Jun 12 '20 at 17:08
-
Currently running via "pip.exe" does not support upgrading pip -- due to a sharing violation on "pip.exe" that causes the upgrade to fail. In principle this could be worked around in a two-step upgrade, since a running executable can be renamed even though it can't be deleted. But instead, it's simply recommended to upgrade via `py -m pip` instead of using the "pip.exe" wrapper to upgrade pip. – Eryk Sun Jun 12 '20 at 17:10