Reputation: 71
Using macOS.
I'm using VSCode 1.28.2 and I am wondering how I can force VSCode to use Python 3 instead of Python 2. Unless I use the shebang: #!/usr/bin/env python3
, I always get an ImportError or some other problem, even though the intrepreter is using Python 3.7.
Image here:
If I use the shebang, the code works and the output in the Terminal is:
<bound method Response.raise_for_status of <Response [200]>>
I am using the Python Extension by Microsoft.(https://marketplace.visualstudio.com/items?itemName=ms-python.python)
Any advice would be appreciated.
Upvotes: 6
Views: 3888
Reputation: 31
In code-runner.executorMap I updated:
"python": "python -u",
to"python": "python3 -u",
Then I reloaded my window and it worked!
Upvotes: 3
Reputation: 1323115
Check issue 2125 which mentions:
By default, a local
pipenv
environemnt is searched for and if found, is marked as the python interpreter. But it also then adds a line to settings.json indicating the path for the virtual environment which can cause issues for configs shared among a team.
That same issue includes the following workaround:
a work-around for this is to set
PIPENV_VENV_IN_PROJECT
and the extension will automatically pick up the.venv
directory that gets created.
And you can setpython.pythonPath
to${workspaceFolder}/.venv
to be consistent within your project without any hard-coded, absolute paths.
That could help set a default python version.
Upvotes: 4