1

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?

1
  • How are you executing that code to check the version? Commented Jan 22, 2020 at 23:33

1 Answer 1

2

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.

Sign up to request clarification or add additional context in comments.

2 Comments

This alias python=python3 is a very bad suggestion. I believe that there is still some software that depends on Python 2. Never do such aliases!
Thanks for the suggestion. You are probably right. Updated the answer.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.