How to setup virtual environment for Python in VS Code?

后端 未结 12 1906
灰色年华
灰色年华 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:39

    I fixed the issue without changing the python path as that did not seem like the right solution for me. The following solution worked for me, hopefully it works for you as well :))

    1. Open cmd in windows / shell in Linux/Mac.
    2. Activate your virtualenv (using source activate / activate.bat / activate.ps1 if using power shell)

      C:\Users\\Videos\myFolder>django-project\Scripts\activate.bat (django-project) C:\Users\\Videos\myFolder>

    3. Navigate to your project directory and open vscode there.

      (django-project) C:\Users\prash\Videos\myFolder\projects>code .

    4. in VS Code, goto File --> Preferences --> Settings (dont worry you dont need to open the json file)

    5. In the setting search bar search for virtual / venv and hit enter. You should find the below in the search bar:

    Python: Venv Folders Folders in your home directory to look into for virtual environments (supports pyenv, direnv and virtualenvwrapper by default).

    1. Add item, and then enter the path of the scripts of your virtuanenv which has the activate file in it. For example in my system, it is:

      C:\Users\\Videos\myFolder\django-project\Scripts\

    2. Save it and restart VS Code.

    3. To restart, open cmd again, navigate to your project path and open vs code. (Note that your venv should be activated in cmd before you open vs code from cmd)

    Command to open vs code from cmd:

    code .
    

提交回复
热议问题