Steps to create a Python virtual environment with VS Code on Windows

0. Lastly

I'm new to Python. As the title suggests, when running Python on Windows, I settled on the environment with VS Code through various trials and errors, so I will record the procedure. The OS is windows10.

1. Download and install Python and VS Code

1-1. Download Python

  1. Go to www.python.org.
  2. Go to Python> Downloads> Windows.
  3. The list of download links is lined up, so look for a newer version.
  4. Select Windows x86-64 executable installer from among multiple installer types.

In this article, I downloaded 3.8.2.

** Install Python **

  1. Run the installer (.exe).
  2. I don't think there is any particular problem, so I will omit it.

1-2. Download VS Code

  1. Go to code.visualstudio.com. 2.Window (Windows)|Penguins (Linux)|Pictures of apples (Mac) are lined up.
  2. Select Windows ʻUser Installer` and download.

In this article, I downloaded 64bit.

** Install VS Code **

  1. Run the installer (.exe).
  2. I don't think there is any problem, so I will omit it.

Next, we will create a virtual environment.

2. Create a Python virtual environment on VS Code

2-1. Add an extension

2-1-1. Japanese localization

  1. Start VS Code
  2. Use Ctrl + Shift + X to display the extension
  3. Search for and install the Japanese Language Pack for Visual Studio Code
  4. Menu becomes Japanese

After this, I will explain that the VS Code menu is in Japanese.

2-1-2. Python

  1. Use Ctrl + Shift + X to display the extension
  2. Search for Python
  3. There will be various extensions, so choose the Microsoft extension (probably the first one listed)

This is an extension for running Python on VS Code.

2-2. Prepare a folder for Python

Here, it is described as the procedure to create the following document structure on a Windows PC.

C:\Users\\[user]\Documents\Python\dev01 (The [user] part is the user name)

2-2-1. Create a Python folder

  1. Open PC> Documents>
  2. Create a new folder called Python

We will prepare a folder called dev01 under this, but please do not create it yet. From here, we will operate on VS Code.

2-3. Create a virtual environment with VS Code

2-3-1. Open the folder

  1. Start VS Code
  2. Select File> Open Folder
  3. Select the Python folder you created earlier
  4. Explorer appears

In this, we will create a virtual environment called dev01.

2-3-2. Venv with Powershell

  1. Select Display> Terminal
  2. The terminal screen will appear and you will see " powershell ".

Powershell is a Windows tool that operates with commands. You can manipulate this from VS Code.

On the last line of the terminal screen PS C:\Users\\[user]\Documents\Python > There is a character string called. After this, enter the command.

  1. Type python -m venv dev01 and ʻEnter`
  2. A development environment called dev01 is created.

It is OK if you can see the following folders under dev01 in Explorer.

About venv

I have just created a Python virtual environment with a command called venv. It feels like I created scripts and libraries to run Python in a folder called dev01. Although it is set to dev01, it is assumed that another environment such as dev02 and dev03 will be created if necessary.

3. Preferences

I don't know if there is a fixed procedure for setting the environment, Make the necessary settings while actually creating a Python file (.py) on a random basis.

3-1. Create a Python file

3-1-1. Creating a new file

  1. Select File> New File in VS Code
  2. A new file will appear.
  3. You can save it as it is, but since it's a big deal, code "hello world!".

work_00_hello.py


print('Hello World!')

3-1-2. Save as a Python file

  1. Save with Ctrl + S
  2. The save folder is under dev01.
  3. Name the file work_00_hello.py.
  4. By saving as .py, it will be recognized as a Python file even on VS Code, and a message prompting you to install the extension will be displayed, so install them.

3-2. Various installations

3-2-1. pylint

  1. You may see a message such as "Linter pylint is not installed.".
  2. It is recommended to install the missing extension, so press the install button.

3-2-2. pip upgrade

  1. You may see a message in your terminal such as " You should consider upgrading via the'python -m pip install --upgrade pip' command. ".
  2. Let's update pip, so let's enter this command next.
  3. Select Terminal> Python
  4. Probably it's in Python now
  5. Run the py file and the terminal will be Python
  6. Type python -m pip install --upgrade pip and ʻEnter`
  7. The latest version of pip will be installed

3-3. Selection of interpreter

The interpreter is a mechanism that allows you to translate and execute Python code. I use an interpreter called python.exe, which sometimes exists in multiple directories. Of the multiple Python.exe, set the meaning of specify Python.exe in the dev01 environment.

  1. Press Ctrl + Shift + P to display the command palette
  2. Type select in the box that appears and press ʻEnter`
  3. One or more Python interpreters will be displayed
  4. Select Python 3. \ *. \ * 64-bit ('dev01': venv)

The interpreter for the dev01 environment you just created is now selected.

3-4. Checking the environment

The current environment is displayed at the bottom left of VS Code. Python 3.*.* 64-bit ('dev01':venv) Is displayed, it is OK.

3-5. Creating a workspace

Now, I think that a folder called PYTHON is opened on VS Code Explorer. Save this state as a workspace.

  1. File>Save workspace as
  2. Save to: Select directly under Document> Python
  3. Name: Here, save it as the workspace name Python.
  4. The Python.code-workspace is saved in the Python folder.

This completes the environment settings.

  1. Hello World! Let's move the first Python file we created earlier.

  2. Open work_00_hello.py from Explorer

  3. Press the play button at the top right of the editor (the open Python file will be executed)

  4. When "Hello World!" Is displayed in the terminal, it is OK.

With the above, the virtual environment of Python is completed with VS Code of Windows. I've tried it several times, but it may be a different procedure depending on the environment and version.

Thank you very much.

5. The site that I referred to

Qiita About python environment preparation (python3 + vscode)

@markIT Visual Studio Code Settings "Cheat Sheet": Python Edition What you need to do to Python with VS Code

visualstudiocode Getting Started with Python in VS Code

python venv --- Create Virtual Environment

Recommended Posts

Steps to create a Python virtual environment with VS Code on Windows
Python (Windows 10) Virtual Environment / Package with VS Code
Create a Python virtual development environment on Windows
Create a Python environment for professionals in VS Code on Windows
[Python] Create a virtual environment with Anaconda
Creating a python virtual environment on Windows
Try to create a python environment with Visual Studio Code & WSL
Create a simple Python development environment with VS Code and Docker
How to create a Python virtual environment (venv)
Create a virtual environment with conda in Python
Steps to create a Twitter bot with python
[Venv] Create a python virtual environment on Ubuntu
Build a python execution environment with VS Code
Python with VS Code (Windows 10)
Prepare a Python virtual environment for your project with venv with VS Code
I was addicted to creating a Python venv environment with VS Code
Create a comfortable Python 3 (Anaconda) development environment on windows
Create a decent shell and python environment on Windows
When I tried to create a virtual environment with Python, it didn't work
Create a Python environment on Mac (2017/4)
Building a virtual environment with Python 3
Create a Linux environment on Windows 10
Create a python environment on centos
How to build a new python virtual environment on Ubuntu
How to use VS Code in venv environment on windows
Create a VS Code + Docker development environment on a Linux VM
Create a virtual environment for python on mac [Very easy]
Build a Python environment with WSL + Pyenv + Jupyter + VS Code
I tried to build an environment with WSL + Ubuntu + VS Code in a Windows environment
Steps to quickly create a deep learning environment on Mac with TensorFlow and OpenCV
Until you create a machine learning environment with Python on Windows 7 and run it
Create a python environment on your Mac
Let's create a virtual environment for Python
Building a Python 3.6 environment with Windows + PowerShell
Steps to install Python environment on Ubuntu
Create a virtual environment with Python_Mac version
Create a Linux virtual machine on Windows
Build a python virtual environment with pyenv
Add a Python virtual environment to VSCode
I tried to create a server environment that runs on Windows 10
Create a Python execution environment for Windows with VScode + Remote WSL
Build a 64-bit Python 2.7 environment with TDM-GCC and MinGW-w64 on Windows 7
How to build Python and Jupyter execution environment with VS Code
Everything from building a Python environment to running it on Windows
Simply build a Python 3 execution environment on Windows
How to build a Python virtual execution environment using Visual Studio Code and pipenv on a Windows machine (also Jupyter notebook)
Build a python environment with ansible on centos6
Unable to import packages installed in virtual environment with Anaconda on Windows 10
Create a python3 build environment with Sublime Text3
Work in a virtual environment with Python virtualenv.
Use Python in Anaconda environment with VS Code
Create a Python environment
Create a Python3 environment with pyenv on Mac and display a NetworkX graph
From Python environment construction to virtual environment construction with anaconda
Create a Python execution environment on IBM i
Build Linux on a Windows environment. Steps to install Laradock and migrate
Virtual environment with Python 3.6
Make your Python environment "easy" with VS Code
How to debug a Python program by remotely connecting to a Docker container in WSL2 environment with VS Code
Easy Python data analysis environment construction with Windows10 Pro x VS Code x Docker
[Python] How to create a local web server environment with SimpleHTTPServer and CGIHTTPServer