How to force VSCode to use Python 3 instead of Pyt

2019-05-12 01:51发布

问题:

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.

回答1:

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 set python.pythonPath to ${workspaceFolder}/.venv to be consistent within your project without any hard-coded, absolute paths.

That could help set a default python version.