Download from Anaconda Official Website. Here, Anaconda3-2020.02-Windows-x86_64.exe is used.
Run the installer to install Anaconda. There are no particular points to note, but here the settings are as follows.
This is not required, but By default, the Anaconda virtual environment is created under the Anaconda installation destination. If you want to create it in a different directory, add the environment variable "CONDA_ENVS_PATH". Here, "D: \ CondaEnvs" is specified.
Launch Anaconda Navigator from the Start menu.
Select Environments → Create.
Specify the following and click "Create" to create the virtual environment.
item | Specified value |
---|---|
Name | Python37 * Optional |
Location | D:\CondaEnvs\Python37 * Environment variable "CONDA"_ENVS_The above is automatically specified by the "PATH" setting and the "Name" specified value. |
Packages | Python 3.Select 7 |
Install the following packages for code formatting, Lint.
Specifically, follow the steps below.
Here, in addition to the above package, the following is added for the sample source.
Select "Selected" to check the packages to be installed, and then click "Apply" to install.
Cut a directory of your choice and open it with VS Code. Here, it is "D: \ Temp \ conda-test".
Add the following extensions.
The conda command doesn't 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",
}
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 Anaconda virtual environment.
"python.venvPath": "${env:CONDA_ENVS_PATH}/Python37",
"python.autoComplete.extraPaths": [
"${env:CONDA_ENVS_PATH}/Python37/Lib/site-packages",
],
//Python command path. Created python under Anaconda virtual environment.Specify the exe.
"python.pythonPath": "${env:CONDA_ENVS_PATH}/Python37/python.exe",
//The path of the conda command.[Anaconda installation destination]/condabin/conda.Specify bat.
"python.condaPath": "C:/ProgramData/Anaconda3/condabin/conda.bat",
//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,
}
When launching VSCode from Anaconda Navigator The Anaconda virtual environment is automatically activated, so I don't think it is necessary to set the Python path or virtual environment path in the above. If you open the project directly from Explorer etc., it will not be activated, so the above settings are required.
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.