🐍 Using VS Code with Anaconda: A Clear Setup Guide for Data Analysts
If you're using **Anaconda** as your Python distribution and want to write Python or PySpark code in **VS Code**, getting it set up properly is crucial — especially when working with tools like **Microsoft Fabric**.
In this post, I'll walk you through the exact steps I used to:
Set up Anaconda with VS Code
Create and manage Conda environments
Persist environments using `.yml` files
Reactivate environments reliably
Understand the impact on tools like Microsoft Fabric
---
✅ Step 1: Add Anaconda to Your PATH
When Anaconda is first installed, it doesn't always add itself to your system PATH (especially if you unticked that option during installation).
➤ Check if Conda is available
Open a **Command Prompt** and run:
conda --version
If you get an error like `'conda' is not recognized`, you'll need to add it to PATH.
➤ Add these to your PATH:
Replace `` with your Windows username:
C:\Users\\Anaconda3
C:\Users\\Anaconda3\Scripts
C:\Users\\Anaconda3\Library\bin
You can add them in:
Start Menu → Search “Environment Variables”
Click **Environment Variables**
Edit the `Path` variable under **User variables**
🚨 Restart your computer after making these changes.
---
✅ Step 2: Select the Conda Python Interpreter in VS Code
Once `conda` is available, tell VS Code to use it.
1. Open VS Code
2. Press `Ctrl+Shift+P` → Type: **Python: Select Interpreter**
3. Choose an interpreter like:
base (C:\Users\\Anaconda3) [conda]
If it's not listed:
Click **Enter interpreter path**
Browse to: `C:\Users\\Anaconda3\python.exe`
---
✅ Step 3: Set the Terminal to Command Prompt (Optional but Safe)
Some environments like PowerShell don't always activate Conda properly.
1. Open a terminal in VS Code (`Ctrl + \``)
2. Click the dropdown arrow ▼ at the top of the terminal
3. Choose **Command Prompt**
4. (Optional) Press `Ctrl+Shift+P` → **Terminal: Select Default Profile**
---
✅ Step 4: Create and Activate a Conda Environment
I recommend creating a dedicated environment for Fabric and PySpark:
conda create -n fabricenv python=3.10 pandas pyspark
conda activate fabricenv
Once created, VS Code should detect this automatically when selected via the interpreter menu.
---
✅ Step 5: Save Your Environment to a `.yml` File
This helps with reproducibility and sharing across projects:
conda env export > environment.yml
You can re-create this environment on any machine with:
conda env create -f environment.yml
---
✅ Step 6: Reactivate Conda Automatically on Restart
If you reopen VS Code later, your terminal may not auto-activate your conda environment.
To manually reactivate:
conda activate fabricenv
To make it automatic, add this to your VS Code workspace settings (`.vscode/settings.json`):
{
"python.defaultInterpreterPath": "C:\\Users\\\\Anaconda3\\envs\\fabricenv\\python.exe"
}
---
🧪 Will This Impact Python in Microsoft Fabric?
> **No — not directly.**
Microsoft Fabric uses its own runtime (hosted kernel), so your local Anaconda install **doesn’t interfere**.
But:
If you export your environment and want to reproduce it **in Fabric**, you’ll need to install the same packages manually with `%pip install`
You can use `environment.yml` as documentation for your Fabric setup
---
💡 Bonus: Create a Starter Notebook
In VS Code or Fabric, include these checks at the top of your notebooks:
import sys
import os
print("Python Version:", sys.version)
print("Environment Path:", sys.executable)
print("Conda Env:", os.environ.get("CONDA_DEFAULT_ENV", "Not in Conda"))
---
📦 Summary
| Task | Command or Tip |
|--------------------------------------|--------------------------------------------------|
| Check Conda is working | `conda --version` |
| Create new env | `conda create -n fabricenv python=3.10` |
| Activate env | `conda activate fabricenv` |
| Save env | `conda env export > environment.yml` |
| Reuse env | `conda env create -f environment.yml` |
| Select Python in VS Code | `Ctrl+Shift+P` → Python: Select Interpreter |
| Run Fabric with same packages | Use `%pip install` inside notebook |
---
✨ Tags
Tags: `Python`, `VSCode`, `Anaconda`, `Fabric`, `DataEngineering`, `Conda`, `Setup`