Belphegor
Belphegor

Reputation: 4766

VSCode for WSL: wrong python version of the interpreter

I am trying to use VScode for Python for Windows Subsystem for Linux (WSL). On the bottom left corner, I see that the python version is 3.6 (which is what I want):

enter image description here

However, when I check the version:

print(sys.version)

I get 2.7.17. Why I can't use Python 3 and how can I switch the interpreter to Python 3.6.9?

Upvotes: 1

Views: 1386

Answers (1)

Imre_G
Imre_G

Reputation: 2535

There are a couple of ways. The most easy one is adding a shebang on top of your script like this:

#!/usr/bin/python3

Also, did you run the code using python mycode.py or python3 mycode.py. It makes a difference.

Another way is to follow this tutorial to install and use different versions of python. https://hackersandslackers.com/multiple-versions-python-ubuntu/

Another way is to use virtual environments. That way you can define your python version on project level. There are probably more ways.

Upvotes: 2

Related Questions