Ole version set as default

Thomas Passin list1 at tompassin.net
Wed Mar 29 14:12:30 EDT 2023


On 3/29/2023 12:46 PM, Pranav Bhardwaj wrote:
> Dear sir,
>                 I am Pranav Bhardwaj and I stuck in a problem. My problem is
> that in my system I have python 3.11.2 but when I type python in my command
> prompt, my command prompt show that python version 2.7.13 as a default. And
> I can't be able to find python 2.7.13 in my system in any file and I tried
> various methods to set python 3.11.2 as a default but can't be able to do
> so. I tried to change environment variables, try to find and delete python
> 2.7.13 , try to set python 3.11.2 as default, but I can't be able to do so.
> So can you help me how can I solve this problem?

If you installed Python3 from python.org, then type "py". This will run 
the latest version installed on your machine.  "py" will give you the 
option of running the latest version or earlier versions by specifying 
them on the command line: "py -2" will give you Python 2+, "py -3.9" 
will run Python 3.9 if it is installed, and so on.

This will run Python3.11, but you may still get the wrong version when 
you try to run a Python-installed script from the command line.  For 
example, if you type "pip" to install packages that can be installed 
from PyPi by the Pip command, the pip program for Python 2 may run instead.

Some of these programs, like pip, are Python modules and can be run 
using the "-m" option:

py -m pip

This will run the right version of pip for whatever version of Python it 
launches. I always run pip this way, and you should too. Many or most of 
the Python scripts that were installed into the Python Scripts directory 
can be run this way too.

That leaves other cases where a script might get launched from Python2's 
Scripts directory because it is on your PATH.  The way to make Python3's 
directories get used instead of Python2's is to put them first on the 
PATH, so that they will get checked first for the target file. It would 
be too long to go into the details for changing the PATH here.  If you 
still have trouble after doing what I said above, feel free to come back 
and ask how to do it.  You can find out how to change the PATH on the 
internet, so you probably won't need to come back here.

One final possibility for getting the wrong version of Python is if you 
try to run a file whose name ends with ".py" without typing "py" before 
it. In other words, on the command line you should type "py program.py", 
not just "program.py".  The installer for Python 3.11 should have taken 
care of these file associations (as they are called in Windows) so it 
will probably not be a problem.  If it is, just make sure to include the 
"py" when you run a Python program.



More information about the Python-list mailing list