The Windows py command can select a specific Python runtime, making it especially useful when several versions are installed.
Understanding the Concept
The modern Install Manager accepts py -V:3.15 followed by a script or normal Python options. The shorter py -3.15 form may also work for an official CPython runtime, but the explicit tagged form is clear. Commands such as py list and py install are manager actions, not Python language statements. The older legacy launcher has some similar version-selecting behavior but is not the same tool.
When and Why You Would Use This
You can check version, execute a source file, or run a standard-library module using the same version selector. This avoids changing the computer-wide default interpreter simply to complete one project.
Practical Example
py -V:3.15 --version
py -V:3.15 hello.py
py -V:3.15 -m pip --version
Understanding the Example
The commands check the selected runtime, run hello.py in the current folder, and inspect pip for that runtime. Run the second only after creating hello.py. A missing file produces a file-path error, not an installation error.
Try It Yourself
Create hello.py and run it once with py -V:3.15 hello.py and once from PyCharm. Compare the output.
Common Beginner Mistakes
- Writing
pycommands inside Python source files rather than a shell. - Confusing
py listwith Python’s built-in list() constructor. - Using unqualified
pipand inadvertently installing into another Python version.
Key Takeaways
- The
pylauncher can target Python explicitly. - Version selection works with scripts and
-mmodules. - Use the matching interpreter when installing project dependencies.