10 Steps to Setup a Comprehensive Data Science Workspace with VSCode on Windows | by Gong Na | Towards Data Science

To start a data science project, choosing an effective development environment is always the first step. Jupyter Notebook/Lab is a common choice. I like it very much. But it’s really not enough.
When I started my first professional data science project, I used many tools together: Jupyter Notebook for model training, PyCharm (free Community version) for structured Python script, Anaconda Prompt for python package management, MobaXterm for remote SSH connection, Excel for raw data review and so on. Everyday, I jump between different windows all the time.
Fortunately, I found a single tool which supports all above functions and most importantly, it’s for free: VSCode.
If you are suffering from the same problem as above, or you are a beginner in the data science field, this guide may help you build your own effective data science workspace and have a good start-point.
Work with Anaconda
Write structured and readable python scripts
Use Jupyter Notebook
Mange python packages and conda virtual environment
Work on remote server (e.g. GPU nodes) via SSH with a very user-friendly interface
View and edit different types of file (e.g. .txt, .csv, .xlsx, .png, .md, .yml, Dockerfile ...)
Use Git version control
Be flexible for future project extension such as adding a Docker-based deployment
Now, Let’s start ~🚀
Overview of ContentsStep 1: Install AnacondaStep 2: (Optional) Create a Virtualenv in Anaconda PromptStep 3: Open VSCodeStep 4: Open Your Project Folder from VSCodeStep 5: Install Python Extension in VSCodeStep 6: Enable Your Virtualenv in VSCodeStep 7: Config the VSCode Terminal for 'conda' & 'python'Step 8: Enable Jupyter Notebook in VSCodeStep 9: Connect to the Remote Server from VSCode via SSHStep 10: Do Git Push in VSCode
[following setup is based on Win10]
You can install the latest edition from here, or the archived version from here. If you are going to use the integrated terminal in VSCode, I highly recommend you to install the version of Anaconda ≥ 4.6.
After the successful installation, you have also installed Jupyter Notebook, Python and some common python packages for data science usage. And you can now find Anaconda Navigator, Anaconda Prompt, Jupyter Notebook icons in the Start Menu.
To avoid the mutual interference between different projects, it’s better to develop in an isolated virtual environment. If you really prefer to develop in the defaultbase env, you can skip this step.
Open Anaconda Prompt from Start Menu:
Check your current env list :
conda env list
Create your own virtualenv with a name and specified python version (example name: ssl):
conda create --name ssl python==3.6.4
Activate the virtualenv:
conda activate ssl
Check what packages exist in this virtualenv (python should have been installed during the virtualenv creation):
conda list
After finishing the setup in VSCode, you can directly mange your virtualenv in VSCode terminal.
For more conda environment management, please check here.
Option 1: open Anaconda Navigator > launch VSCode from the Home page.
Option 2: you can also install VSCode from the website. In this way, you can get a shortcut, then launch VSCode quickly from the desktop or your taskbar. From my own experience, this way is faster than Option 1.
Create a new project folder as your root directory in anywhere you like. Open VSCode > click the File in the top left > click Open Folder > click the target folder name. Now, you can put all your project files and scripts here.
VSCode is a source-code editor supporting a bunch of languages. In order to enable Python, we need to install the Python extension.
Click Extension icon in the left bar > search Python > click install:
Now, you can create standard python scripts simply with .py file extension:
If you also like the cute python icon in front of the helloWorld.py, you can get it by adding VSCode Great Icons extension. It can help you easily distinguish different types of file and folder:
In VSCode, press ctrl+shift+p, a Command Palette will pop up in the top middle. Click Python: Select Interpreter > you will see a list containing all your virtualenv and the base env > choose the proper virtualenv.
If you cannot see the Python: Select Interpreter, just type and search it.
Afterwards, the python interpreter with the env name will show in the bottom-left of the Status Bar:
Open a new VSCode terminal by clicking top left ‘Terminal’ or the shortcut ctrl+shift+`. The terminal will be opened in the right bottom.
Choose a default shell based on your personal preference (default: cmd):
If you want to use Linux command on Windows just like me, Powershell is a good choice for you.
After selected, just open another new terminal to catch your updates. If you have successfully selected a python interpreter in the last step, the virtualenv now will be automatically activated in your new opened terminal via conda activate. And the virtualenv name will show in () at the front:
Now, you can execute .pyfiles in the terminal by
python helloWorld.py
💢 Two common errors you may encounter:
1. Fails to run conda activate in Powershell.
Solution: conda starts to support conda activate in Powershell only from the version 4.6. So if you want to use Powershell as your default shell in VSCode, make sure that your conda version is at least 4.6 or higher (it may differ in different Windows systems)
2. Unrecognized term error when you run conda or pythonin the terminal Solution: Get your python and conda paths by running below command in a terminal
where pythonwhere conda
Copy&Paste both the python and conda paths to the Path of Environment Variable:
Install the Jupyter package which includes the notebook, qtconsole, and the IPython kernel via
pip install jupyter# orconda install -c conda-forge jupyter
Create a new jupyter notebook file: pressctrl+shif+p > search Create New Blank Jupyter Notebook > click it > save the created.ipynbfile with a name:
In a few seconds, the top right Jupyter Server will be automatically set as local, and the Kernel as the conda environment chosen in Step 5.
If not, or you want to change the kernel/env: press ctrl+shif+p > search Select Interpreter to start Jupyter server > click it > choose a proper env from the shown list:
Now, you can use Jupyter Notebook as usual:
Another awesome feature which I like the most is the remote SSH connection which supports opening any remote folder with full VSCode’s feature set.
Install Remote-SSH extension:
Then you will see a little connection icon shown in the bottom-left of the Status Bar:
Click the icon > select Remote-SSH: Connect to Host... > add the standard ssh connection command ssh username@hostname > hit Enter:
An empty window will be opened which will setup the remote SSH connection automatically. After connected, you will see the host name in the bottom-left of Status Bar with SSH:username@hostname:
Now, you can open any folder under your home directory on that connected remote machine and work on it just as you are locally:
💢 If you get the corrupted MAC on input error during the remote connection as below, you can solve it by adding the availabel MAC cryptographic algorithm in ssh . I post the detailed steps in this story.
VSCode supports Git version control in-the-box so that you can track your code in a very pleasant format and push it easily by a few clicks.
If your opened folder is under a git repository, the branch name will be shown in the bottom left with a * in VSCode. And the total number of changed files will be shown with the Source Control icon in the left bar.
In the below example, it’s in the master branch with one changed file in Untracked status.
Click the Source Control icon > click the file name > you can check the detailed code changes in a comparison view:
Stage changes by clicking + icon after the file > add a commit message in the above box > click ✔ on the above to commit:
A Synchronize Changes action will then show in the Status Bar with a little icon of 1↑ which indicates that you have 1 commit not pushed yet:
Just click it to push all committed changes. After the successful push, the 1↑ indicator will disappear:
Now, your Data Science workspace in VSCode is ready!
VSCode is far more powerful than I shared above. There are a lot of diversified extensions which support different developing requirements. If you are new about them, and feel little bit lost in the large extension pool at the beginning, the following essential extensions may help you to start. Just keep trying!
- Predawn Theme Kit  # readable code- Sublime Text Keymap and Settings Importer # readable code- Excel Viewer  # preview csv file in excel format- Prettify JSON  # parameter config- YAML  # parameter config