Python development environment with Windows + Anaconda3 + Visual Studio Code

■ Environment

■ Installing Anaconda

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.

Anaconda-Install_1.png Anaconda-Install_2.png Anaconda-Install_3.png

■ Anaconda settings

● Setting environment variables

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.

Anaconda-EnvVar.png

● Creating an Anaconda virtual environment

Launch Anaconda Navigator from the Start menu.

Anaconda-Start.png

Select Environments → Create.

AnacondaNavigator-CreateEnv_1.png

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

AnacondaNavigator-CreateEnv_2.png

● Package installation

Install the following packages for code formatting, Lint.

Specifically, follow the steps below.

  1. Select "Not installed"
  2. Enter the package name in the search field
  3. Check the check box of the search result

AnacondaNavigator-AddPackage_1.png

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.

AnacondaNavigator-AddPackage_2.png

■ Visual Studio Code settings

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

VSCode-OpenVSCode.png

● Addition of extensions

Add the following extensions.

VSCode-PythonExtension.png

● settings.json settings

・ User settings

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",
}

・ Workspace setting

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.

● 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

Recommended Posts

Python development environment with Windows + Anaconda3 + Visual Studio Code
Python development environment with Windows + Python + PipEnv + 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).
Prepare Python development environment with Mac + Windows + VisualStudio Code (Windows version)
Prepare Python development environment with Mac + Windows + VisualStudio Code (Mac version)
Try to create a python environment with Visual Studio Code & WSL
Python (Windows 10) Virtual Environment / Package with VS Code
Use Python in Anaconda environment with VS Code
Execute C ++ functions from Python with Pybind11 (for Windows & Visual Studio Code people) Environment construction
Python with VS Code (Windows 10)
Install Python environment with Anaconda
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
Preparing to use Tensorflow (Anaconda) with Visual Studio Code
Create a comfortable Python 3 (Anaconda) development environment on windows
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)
Anaconda python environment construction on Windows 10
[Python3] Development environment construction << Windows edition >>
Install Python development environment on Windows 10
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
[Python] Building an environment with Anaconda [Mac]
Python (anaconda) development environment construction procedure (SpringToolsSuites) _2020.4
Change Python 64bit environment to 32bit environment with Anaconda
python windows environment
[Python] Create a virtual environment with Anaconda
Building a Python 3.6 environment with Windows + PowerShell
Build Python environment with Anaconda on Mac
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
Steps to create a Python virtual environment with VS Code on Windows
Python environment construction (Anaconda + VSCode) @ Windows10 [January 2020 version]
Building an Anaconda environment for Python with pyenv
Building a Python environment with WLS2 + Anaconda + PyCharm
Install OpenCV 4.0 and Python 3.7 on Windows 10 with Anaconda
Django with Python Tools 2.2 for Visual Studio (PTVS 2.2)
Settings for Python coding in Visual Studio Code
From Python environment construction to virtual environment construction with anaconda
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 starting with Windows 7
Use Python 3.8 with Anaconda
About Python development environment
Python environment with docker-compose
python2.7 development environment construction
Development environment in Python