Search code examples
pythonpython-3.xpython-2.7visual-studio-codeimporterror

How could I change my Interpreter from Python 3.8 to Python 3.9 in Visual Studio Code? [Resolved with answer]


I know this is a many times questions but I still couldn't find the easiest way to resolve my question:

Recently I have got a import error for 'lxml' and I found that this error only occur when I use Visual Studio Code (VSC) but the script can execute perfectly fine when using 'python3' command in terminal
enter image description here

After I read several post from the forum, seems my questions is I should change my VSC parameter by using Python 3.9 instead of 3.8.

Demonstration in Terminal - Python3 works enter image description here

Demonstration in VSC using 'Run Without Debugging' enter image description here Error: ImportError: cannot import name 'etree' from 'lxml' (/Users/LSH/Library/Python/3.8/lib/python/site-packages/lxml/init.py)

When I check with my VSC, I could see that in the left bottom is using Python3.8.2 64 Bit. So I am wonder once I change it to Python 3.9, then my current issue would be resolved?

enter image description here

Or should I update the python file?enter image description here As I open the /usr/bin/python3, it is Python 3.8.2 enter image description here

Hope I could get the right answer soon :) Thanks all.

@Update: After below suggestion, I tried to "Select Interpreter" by clicking Command + Shift + P, however, it shows the below options which I couldnt see Python 3.9, do you know where is the exact Python3.9 interpreter? (As all options point to /usr/bin/python3 which should be 3.8.2) enter image description here


Solution

  • Do it like this- First click on Python 3.8.2 (your 4th picture). Then you will get an option to configure your python interpreter. Select the required version.