Enable the virtualenv Python virtual environment for Visual Studio Code

@ gtracker64 gave me an easier way. Thank you very much.

There is also a way to set around python.pythonPath or python.venvPath in VSCode settings (setting.json). https://code.visualstudio.com/docs/python/environments

Introduction

virtualenv can create a Python virtual environment for each folder. I find it very useful. Visual Studio Code is usually used for front-end development, but it is quite convenient as long as you install Plugin as a Python IDE, with Lint, automatic source formatting, etc.

However, even if I enable the virtual environment with virtualenv, when I open the source code with VSCode, I get various errors.

Is there something wrong?

The reason VS Code doesn't recognize the Python virtual environment is that I don't know VS Code for the virtualenv environment variables enabled in source env / bin / activate.

How to solve it?

All you have to do is recognize the environment variables.

In a terminal, enable Python virtual completion and then launch VS Code from that terminal.

$ cd my-python-env
$ source my-python-env/bin/activate
$ code

If VS Code doesn't start when you run code suddenly, you need to add the code command to the path. As shown below, you can use a single command in VS Code.

vscode.png

When started this way, VS Code inherits all the environment variables in the terminal, so the Python virtual environment is also enabled.

It was surprisingly easy, but I was quite addicted to it. : sweat:

Recommended Posts

Enable the virtualenv Python virtual environment for Visual Studio Code
Build Python development environment with Visual Studio Code
Settings for Python coding in Visual Studio Code
[Visual Studio Code] [Python] Tasks.json + problemMatcher settings for Python
Make Visual Studio Code autocomplete for python external libraries
Python development environment with Windows + Anaconda3 + Visual Studio Code
Python development environment with Windows + Python + PipEnv + Visual Studio Code
python memo (for myself): About the development environment virtualenv
Set up a Python development environment with Visual Studio Code
Build python virtual environment with virtualenv
[Python] Building a virtual python environment for the pyramid tutorial (summary)
Execute C ++ functions from Python with Pybind11 (for Windows & Visual Studio Code people) Environment construction
Try using virtualenv, which can build a virtual environment for Python
Try to create a python environment with Visual Studio Code & WSL
About the procedure for linking Visual Studio Code for Windows and WSL
Installation of Visual studio code and installation of python
About the virtual environment of python version 3.7
Let's create a virtual environment for Python
[Mac] Building a virtual environment for Python
Python Tools for Visual Studio Installation Guide
Prepare a Python virtual environment for your project with venv with VS Code
Create a Python development environment on Windows (Visual Studio Code remote WSL).
Python (Windows 10) Virtual Environment / Package with VS Code
Django with Python Tools 2.2 for Visual Studio (PTVS 2.2)
Build an environment to execute C ++ functions from Python with Pybind11 (for Windows & Visual Studio Code people)
Commands for creating a python3 environment with virtualenv
Work in a virtual environment with Python virtualenv.
Code for checking the operation of Python Matplotlib
I get an error when I put a Python plugin in Visual Studio Code under the pyenv environment
Create a Python development environment in 10 minutes (Mac OS X + Visual Studio Code)
I customized it with Visual Studio Code (mainly for python), so I will summarize it
python virtual environment Pipenv
virtual environment in python
Virtual environment with Python 3.6
Python environment for projects
Build a python virtual environment with virtualenv and virtualenvwrapper
Build a python virtual environment with virtualenv and virtualenvwrapper
AWS SDK for Python (Boto3) development in Visual Studio 2017
Execute C ++ functions from Python with Pybind11 (for Windows & Visual Studio Code people) Debugging
Problems and solutions for using the remote debugging environment for Linux apps in Visual Studio 2017
How to debug the Python standard library in Visual Studio
Check the operation of Python for .NET in each environment
Manage python environment with virtualenv
How to build a Python virtual execution environment using Visual Studio Code and pipenv on a Windows machine (also Jupyter notebook)
Python code memo for yourself
Python environment construction For Mac
[Visual Studio Code] [Python] [Windows] Support for garbled Japanese characters in Python in VS Code task / debug output
Python3 environment construction (for beginners)
Do something like a Python interpreter in Visual Studio Code
Install python and Visual Studio Code on windows10 (April 2020 version)
Building a Python virtual environment
I just wrote the original material for the python sample code
After enabling the python virtual environment in the batch file, run the python file
Python development in Visual Studio 2017
[Anaconda] Activate the virtual environment
venv: Python virtual environment management
Build Python3 for Windows 10 on ARM with Visual Studio 2019 (x86) on Windows 10 on ARM
[For organizing] Python development environment
[Python] Sample code for Python grammar
Python development in Visual Studio
python standard virtual environment venv