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
Download from Python official website. Here, python-3.8.2-amd64.exe is used.
Run the installer to install Python. Please note the following.
Start a command prompt and do the following:
Install PipEnv
pip install pipenv
By default, PipEnv stores installed packages under your home. By adding the following environment variable, it will be stored in the project directory.
Add the following extensions.
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",
}
Cut a directory of your choice and open it with VS Code. Here, it is "D: \ Temp \ python-test".
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
When executed, the following will be created directly under the project.
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,
}
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
Create a Python source file as you like.
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.
If you want to run it, open the Run panel and Select "Create a launch.json file"-> "Python File".
.Vscode / launch.json will be created without permission, and the execution configuration for Python will be set.
After that, open the source to be executed and press the F5 key to execute it.
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__