Python development environment with Windows + Python + PipEnv + Visual Studio Code

I wrote the following article a long time ago, but it seems that the situation has changed with the update, so Update the content and repost.

Python development environment with Windows + Python 3.6 + PipEnv + Visual Studio Code

■ Environment

■ Python installation

Download from Python official website. Here, python-3.8.2-amd64.exe is used.

Run the installer to install Python. Please note the following.

Python_Install-1.png Python_Install-2.png Python_Install-3.png

■ Installing PipEnv

Start a command prompt and do the following:

Install PipEnv


pip install pipenv

● Add environment variables

By default, PipEnv stores installed packages under your home. By adding the following environment variable, it will be stored in the project directory.

■ VS Code initial settings

● Extensions

Add the following extensions.

VSCode-PythonExtension.png

● User settings.json settings

The activate command may not work well with PowerShell (?) It seems that it does not work well again with the workspace setting (?), So Add the following in your custom settings.json to make the command prompt the default.

[User home]\AppData\Roaming\Code\User\settings.json


{
    "terminal.integrated.shell.windows": "C:/WINDOWS/System32/cmd.exe",
}

■ From VS Code project creation to execution

● Create project folder & create PipEnv environment

Cut a directory of your choice and open it with VS Code. Here, it is "D: \ Temp \ python-test".

VSCode-OpenVSCode.png

Open a terminal in View-> Integrated Terminal and run the PipEnv command. Change the arguments according to the version of Python you are using.

Create PipEnv environment


pipenv --python 3.8

VSCode-ExecutePipEnv.png

When executed, the following will be created directly under the project.

● Workspace settings.json settings

Set the path for the virtual environment, formatter, and Lint.

json:[Workspace folder]\.vscode\settings.json


{
    //Activate the Python environment in the terminal when the extension loads.
    "python.terminal.activateEnvInCurrentTerminal": true,
    //Virtual environment path. Specify the created virtual environment.
    "python.venvPath": "{$workspaceFolder}/.venv",
    "python.autoComplete.extraPaths": [
        "{$workspaceFolder}/.venv/Lib/site-packages",
    ],
    //Formatter settings. Specify autopep8.
    "python.formatting.provider": "autopep8",
    "python.jediEnabled": false,
    //Lint settings. Enable flake8 and mypy.
    "python.linting.flake8Enabled": true,
    "python.linting.mypyEnabled": true,
    "python.linting.pylintEnabled": false,
    //The following is your choice.
    "editor.formatOnSave": true,
    "python.autoComplete.addBrackets": true,
}

● Package installation

The package is installed in the virtual environment created by using the pipenv command on the terminal. Install the following packages for the code format Lint. Add the --dev option for use only in the development environment.

Installation of autopep8, flake8, mypy


pipenv install autopep8 flake8 mypy --dev

Here, in addition to the above package, the following is added for the sample source.

Installation of numpy and matplotlib


pipenv install numpy matplotlib

● Execution

Create a Python source file as you like.

VSCode-NewSource.png

test.py


import numpy as np
import matplotlib.pyplot as plt

x = np.linspace(-np.pi, np.pi)
y = np.sin(x)
plt.plot(x, y)
plt.show()

If the settings are correct, document viewing, code completion, formatter, and Lint should work.

VSCode-ShowDocument.png VSCode-CodeAssist.png

If you want to run it, open the Run panel and Select "Create a launch.json file"-> "Python File".

VSCode-Create-launch.json.png

.Vscode / launch.json will be created without permission, and the execution configuration for Python will be set.

VSCode-Create-launch.json-3.png

After that, open the source to be executed and press the F5 key to execute it.

VSCode-Execute.png

If you want to specify the execution argument, add the setting of "" args "" to .vscode / launch.json.

        {
            "name": "Python: Current File",
            
            "args": [
                "hoge",
                "fuga",
                "piyo"
            ]
        },

■ .gitignore

/.venv
/.mypy_cache
/Pipfile.lock
/tmp
/**/__pycache__

Recommended Posts

Python development environment with Windows + Python + PipEnv + Visual Studio Code
Python development environment with Windows + Anaconda3 + Visual Studio Code
Build Python development environment with Visual Studio Code
Set up a Python development environment with Visual Studio Code
Create a Python development environment on Windows (Visual Studio Code remote WSL).
Try to create a python environment with Visual Studio Code & WSL
Python (Windows 10) Virtual Environment / Package with VS Code
Execute C ++ functions from Python with Pybind11 (for Windows & Visual Studio Code people) Environment construction
Python with VS Code (Windows 10)
Use Jupyter Notebook with Visual Studio Code on Windows 10 + Python + Poetry + pyenv-win
Python development in Visual Studio 2017
Python development in Visual Studio
Create a Python development environment in 10 minutes (Mac OS X + Visual Studio Code)
Build an environment to execute C ++ functions from Python with Pybind11 (for Windows & Visual Studio Code people)
Java with Visual Studio Code (Part 2)
[Python3] Development environment construction << Windows edition >>
Install Python development environment on Windows 10
pytorch @ python3.8 environment construction with pipenv
Prepare Python development environment with Atom
Enable the virtualenv Python virtual environment for Visual Studio Code
Install python and Visual Studio Code on windows10 (April 2020 version)
Build Python3 for Windows 10 on ARM with Visual Studio 2019 (x86) on Windows 10 on ARM
Execute C ++ functions from Python with Pybind11 (for Windows & Visual Studio Code people) Debugging
Installation of Visual studio code and installation of python
[Ubuntu 18.04] Python environment construction with pyenv + pipenv
[Development environment] Python with Xcode [With screen transition]
Example of building python development environment on windows (wsl2, vscode, pipenv)
python windows environment
Building a Python 3.6 environment with Windows + PowerShell
Create a simple Python development environment with VS Code and Docker
Windows + gVim + Poetry python development environment construction
Build jupyter notebook environment with Visual Studio Code (VS Code) Mac version
How to build a Python virtual execution environment using Visual Studio Code and pipenv on a Windows machine (also Jupyter notebook)
Steps to create a Python virtual environment with VS Code on Windows
[Python] Build a Django development environment with Docker
Django with Python Tools 2.2 for Visual Studio (PTVS 2.2)
Image Processing with Python Environment Setup for Windows
Use Python in Anaconda environment with VS Code
Settings for Python coding in Visual Studio Code
Create a Python virtual development environment on Windows
[Visual Studio Code] [Python] Tasks.json + problemMatcher settings for Python
Make your Python environment "easy" with VS Code
Build a python execution environment with VS Code
Get a quick Python development environment with Poetry
python windows environment construction
Python development environment construction
python virtual environment Pipenv
Python starting with Windows 7
About Python development environment
Python environment with docker-compose
python2.7 development environment construction
Development environment in Python
Virtual environment with Python 3.6
Character code for reading and writing csv files with python ~ windows environment ver ~
Python local development environment construction template [Flask / Django / Jupyter with Docker + VS Code]
Easy Python data analysis environment construction with Windows10 Pro x VS Code x Docker
I customized it with Visual Studio Code (mainly for python), so I will summarize it
A note I was addicted to when running Python with Visual Studio Code
Build a local development environment with WSL + Docker Desktop for Windows + docker-lambda + Python
Virtualize (isolate) IBM i python development environment with chroot
Build a GVim-based Python development environment on Windows 10 (3) GVim8.0 & Python3.6