Install
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.
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
usingpip
- list the installed packages
- export the environment to a cross-platform
myenv.yml
file - delete the environment
myenv
- install
-
Recreate the conda environment
myenv
from the previousmyenv.yml
file- update the Python version to its latest version.
- install
scipy
using theconda-forge
channel - export the environment to a cross-platform
myenv2.yml
file
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 Anaconda Navigator
-
(Windows) Open Start Menu (Windows key)
-
(MacOS) Open Spotlight (CMD + Space)
-
Search for and open
Anaconda-Navigator
-
Click on VSCode->Launch
# 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
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.
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.
- Install the extensions listed in .vscode/extensions.json
- Activate/Deactivate the
Multiline Comments
setting of theBetter Comments
extension
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 eitherOpen User Settings
, orOpen Settings (JSON)
,
- Per project: see settings.json.
See also guilgautier/vscode-workflow repository.
- Change the location of the VSCode sidebar left <-> right.
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 typeConfigure 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.
-
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
) filesfor idx, val in enumerate(values): print(idx, val)
All, and more, of what we experimented with git
from the command line (cf. notes/command_line.md
) can be achieved within VSCode, using