How to force VSCode to use Python 3 instead of Python 2?

独自空忆成欢 提交于 2019-12-07 11:49:24

问题


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.



来源:https://stackoverflow.com/questions/53110324/how-to-force-vscode-to-use-python-3-instead-of-python-2

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!