Python Guide: How to set up VSCode for increased productivity

Assumed audience: You are a TechLabs student pursuing the Data Science track who uses MacOS. If you're not then you can still follow this guide but you may have to Google a few things yourself.

Extensions

Navigate to the Extensions Tab. It's the one highlighted in white.

test

You will see a search bar that looks like this:

test

In this screenshot I used a filter. It's that weird little icon on the right. But you can just type in the gray box and look for extensions.

Find and install:

  • Python
  • Python Extension Pack
  • Path Intellisense
  • Pylance
  • Jupyter

The first package, Python language support, might already be installed.

Path Intellisense

You'll often need to refer to file on disk or import a Python package. It can be a pain to figure out relative file paths. Path Intellisense limits that pain.

Open settings with CMD + , and add these two lines somewhere appropriate:

"typescript.suggest.paths": false,
"javascript.suggest.paths": false,
// otherwise it won't function correctly

I'll show you how this works.

Let's say that I need a text file called test.txt with some lines of text in them. Here I type out the path and then hit Tab to autocomplete the path to the file.

test

Pylance

Pylance provides you with early error detection in your code, parameter suggestions, type checking, semantic highlighting and much more.

Python Extension Pack

Installs a bunch of popular packages for Python. It helps you indent Python code correctly, provides AI support, generates docstrings to comment on what your code is supposed to do, and comes with a Python Environment Manager.

Super-charge your productivity

Jupyter notebooks are very convenient tools but getting used to writing plain code is important. You should practice. I wanted the best of both worlds and thankfully that's possible thanks to VSCode.

On your Mac navigate to Code > Preferences > Settings in the Menu bar or find the gear icon in the lower left corner of your screen. Then type in "Jupyter" and look for the setting below.

test

Now you can write Python code in normal Python files and run the code in a Jupyter code book right next to it. This helps you visualise the flow of your program and allows for fast debugging.

You can inspect any part of it by selecting your code with your mouse or keyboard and hit "shift + Enter" and it will run in a Jupyter notebook instead of your terminal.

I'll show you.

Let's take a simple exercise from Introduction to Python Programming about Strings.

I copied the exercise from the Jupyter notebook to a simple Python file and named it strings.py.

test

Magic.

If you've never done this before VSCode will ask you to select a Python kernel to connect to. Select the one you want.

Now imagine being able to visualise your data any way you want whenever you want without ever leaving your development environment.

Enjoy your new powers.

Tip

Go back to the Extensions Tab and click on the Filter icon. Then select Category, then Data Science and you'll find lots more extensions that might prove useful.

test

Install Anaconda

# on Mac
brew install --cask anaconda 

And don't forget to add anaconda to your path.

export PATH="/usr/local/anaconda3/bin:$PATH"

Now you can use conda commands.

curating the best of the web -

come explore!

media garden about ethos home