How to setup virtual environment for Python in VS Code?

后端 未结 12 1904
灰色年华
灰色年华 2020-11-29 16:29

In my project folder I created venv folder.

python -m venv venv

When I in VS Code run command select python interpreter my ven

12条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-11-29 16:56

    With a newer VS Code version it's quite simple.

    Open VS Code in your project's folder.

    Then open Python Terminal (Ctrl-Shift-P: Python: Create Terminal)

    In the terminal:

    python -m venv .venv
    

    you'll then see the following dialog:

    click Yes

    Then Python: Select Interpreter (via Ctrl-Shift-P)

    and select the option (in my case towards the bottom)

    Python 3.7 (venv) ./venv/Scripts/python.exe

    If you see

    Activate.ps1 is not digitally signed. You cannot run this script on the current system.

    you'll need to do the following: https://stackoverflow.com/a/18713789/2705777

    For more information see: https://code.visualstudio.com/docs/python/environments#_global-virtual-and-conda-environments

提交回复
热议问题