Skip to content

Latest commit

 

History

History
171 lines (111 loc) · 7.61 KB

anaconda-vscode.md

File metadata and controls

171 lines (111 loc) · 7.61 KB

Define your project environments

Requirements

Install

Python Virtual environment with conda

A virtual environment is a self-contained directory tree that contains a Python installation for a particular version of Python, plus a number of additional packages.

It is always good practice to work in a virtual environment, isolated from your other Python projects.

In this course, we will use conda, both as

See also the conda cheat sheet.

Exercise 1

In your terminal

  • list the conda environments currently available on your machine

  • For the base environment

    • list the installed packages
    • what were the channels used to install the different packages?
  • Create a conda environment called myenv with Python 3.8.2

    • install numpy
    • install matplotlib using pip
    • list the installed packages
    • export the environment to a cross-platform myenv.yml file
    • delete the environment myenv
  • Recreate the conda environment myenv from the previous myenv.yml file

    • update the Python version to its latest version.
    • install scipy using the conda-forge channel
    • export the environment to a cross-platform myenv2.yml file

Integrated Development Environment - VSCode

Visual Studio Code (VSCode) is recommended to ease your coding experience.

Important: Use the command palette ( CMD/CRTL + Maj + P ).

See also

Tip: You may also consider synchronizing your settings, in order to keep the same setup each time you use VSCode (even from a different machine).

Launch VSCode

From Anaconda Navigator

Launch Anaconda Navigator

  • (Windows) Open Start Menu (Windows key)

  • (MacOS) Open Spotlight (CMD + Space)

  • Search for and open Anaconda-Navigator

  • Click on VSCode->Launch

From the command line

# cd path-to-your-projet
code . # open VSCode and define a workspace from current directory
code README.md  # open README.md in VSCode

See also

Per project configuration

The .vscode directory, placed at the root of your project workspace, contains a list of suggested extensions together with the corresponding settings, code snippets, etc. You can share the .vscode directory with your collaborator, e.g., using git/GitHub, to make sure you have some common setup.

Note: This configuration only applies in the current workspace and has precedence over global user settings, see also Settings and Snippets.

Extensions

All registered extensions are available on VSCode's Marketplace. Extensions can also be installed locally from your VSCode window, see the documentation.

The .vscode/extensions.json file contains a list of suggested extensions that will greatly simplify your coding workflow.

Exercise 2

  • Install the extensions listed in .vscode/extensions.json
  • Activate/Deactivate the Multiline Comments setting of the Better Comments extension

Settings

VSCode settings You can configure Visual Studio Code to your liking through its various settings. Nearly every part of VSCode's editor, user interface, and functional behavior has options you can modify.

To do so, you can either define settings

  • Globally: Open the Command Palette ( CMD/CRTL + Maj + P ) and type either
    • Open User Settings, or
    • Open Settings (JSON),
  • Per project: see settings.json.

See also guilgautier/vscode-workflow repository.

Exercise 3

  • Change the location of the VSCode sidebar left <-> right.

Snippets

Code snippets are templates that make it easier to enter repeating code patterns, such as loops or conditional-statements.

Many language-specific extensions already provide some useful snippets. While some of them exactly match your needs, some others might be missing or you may not remember how to trigger them.

For these reasons you may create your own snippets to increase your productivity. To do so, you can either define snippets

  • Globally: Open the Command Palette ( CMD/CRTL + Maj + P ) and type Configure User Snippets and choose to create
    • language-specific snippets,
    • generic snippets that can be triggered in different scopes.
  • Per project: see workspace.code-snippets

See also guilgautier/vscode-workflow repository.

Exercise 4

  • Create your own mygithub snippet and make it available only in Markdown (.md) files.

  • Create an forenum Python snippet, that displays when triggered in Python (.py) files

    for idx, val in enumerate(values):
        print(idx, val)

Version control within VSCode

All, and more, of what we experimented with git from the command line (cf. notes/command_line.md) can be achieved within VSCode, using