-3

i just started using python and i use VS Code.

When i do

python --verion

i get python version 2

py --version

i get python version 3

i wanted to install networkx which turned out to only work with python version 3. I did multiple things to change python version to 3 but could not.

So i decided to uninstall python and went to control panel and uninstalled

python
python launcher

and restarted the computer.

But when i run

python --version

it still shows up python 2.7.18

and this is my where python output

enter image description here

can anyone please help me to understand whats going on and how can i get python 3 to my system.

enter image description here

My solution:

I had already tried putting the python 3.1 path (default added by python when you click add path option while installing) above all path but had no intended outcome.

What i did:

installed python again and this time added the path by myself and moved it to top.

Now when i run

where.exe python it shows me three path, i don't know much but looks like there are two/three python in the system but it started showing python 3 for now.

my where.exe python output:

enter image description here

uninstalled

desertnaut
  • 57,590
  • 26
  • 140
  • 166
Pravin Poudel
  • 1,433
  • 3
  • 16
  • 38
  • What does `where python` print? – SuperStormer Sep 11 '22 at 03:05
  • it print nothing – Pravin Poudel Sep 11 '22 at 03:09
  • do you have correct environment variable set? – Gahan Sep 11 '22 at 03:11
  • Oh, you're using powershell - run `where.exe python` instead. – SuperStormer Sep 11 '22 at 03:12
  • ok, nice i get output this time, my output are: C:\xampp\htdocs\Computing_Elevated_Lab\depot_tools\python.bat C:\Users\pravin\AppData\Local\Microsoft\WindowsApps\python.exe – Pravin Poudel Sep 11 '22 at 03:14
  • Do you still need whatever the top folder has? If you don't, delete it (or remove it from PATH). Otherwise, you'll need to move it to the end of the PATH variable. – SuperStormer Sep 11 '22 at 03:18
  • Why not just use `py` rather than `python` for the executable: you should be able to configure it in your IDE to change the executable name. – Alex Huszagh Sep 11 '22 at 03:21
  • There's a pretty detailed list of examples [here](https://stackoverflow.com/questions/48135624/how-can-i-change-the-python-version-in-visual-studio-code), for changing executables, Python versions, etc. in VS Code. But most IDEs or text editors (like Sublime Text) should allow you to do the same. – Alex Huszagh Sep 11 '22 at 03:22
  • one thing i want to know is that though i unstalled python and python launcher from the control panel, how can i get python still on system – Pravin Poudel Sep 11 '22 at 03:25
  • @SuperStormer why is where.exe python returning two location? – Pravin Poudel Sep 11 '22 at 03:38
  • @pravinpoudel why don't you share your environment variables as well so that we can see any glitch from your end which you may be ignoring. – Gahan Sep 12 '22 at 05:28

1 Answers1

0

In windows If you do not have correct environment variable set then this is likely to cause the problem.

On your Powershell if you type $env:path or on command prompt echo %PATH%

you shall see your environment variable path which you have set,

where-in, either you may not have path to directory of Python 3 or you have it appended after Python2.

i.e.:

if your result show up as (... could be other paths in your variable) then only you will get python.exe to be pointing to your Python3 path:

...
C:\Python38\Scripts;C:\Python38;
...
C:\Python27\Scripts;C:\Python27\;
...

Update:

Based on OP comment it looks like there is misunderstanding with how environment variable works.

If you are still looking for why question then follow below steps:

  1. List down all paths which are under environment variable PATH

  2. Now go over each path and check contents of the directory. One of the directory would be having the python which is throwing you the version which you find mystery.

Gahan
  • 4,075
  • 4
  • 24
  • 44
  • no i already uninstalled the python from control panel but it is still showing python why? – Pravin Poudel Sep 11 '22 at 03:32
  • py --version no longer works but python --version is still returning python 2.7.18 – Pravin Poudel Sep 11 '22 at 03:33
  • In that case you should share what is your environment variables in question so that we can answer appropriately! – Gahan Sep 12 '22 at 05:27
  • 1
    @pravinpoudel Overall, this issue is because you have screwed up environment variables. You should first know how environment variables are use... (i.e. `PATH` - it's to shorthand the usage of avoiding full path with only the name of utility file itself, because your system will know from where it should look in to). – Gahan Sep 12 '22 at 05:30