Python project in Visual Studio Code
1. Install VS Code and Python Extension
- Download and install VS Code from https://code.visualstudio.com/.
- In VS Code, go to Extensions (left sidebar) and install the Python extension by Microsoft.
2. Ensure Anaconda Is Installed
- Anaconda should be installed (you can verify with
conda --versionin your terminal). - Open Terminal or Anaconda Prompt and create a new conda environment if desired:
conda create -p venv python==3.13 conda activate venv
3. Open or Create Your Python Project in VS Code
- Open VS Code and select File > Open Folder to open your project directory or create a new folder.
- You can create Python files (
.py) inside this folder.
4. Select the Anaconda Environment in VS Code
- Press
Cmd+Shift+P(macOS) orCtrl+Shift+P(Windows/Linux) to open the Command Palette. - Type and select Python: Select Interpreter.
- Choose your Anaconda environment from the list (it will show paths like
/Users/yourname/anaconda3/envs/myenv/bin/python). - If your environment is not listed, you can add it manually by providing the path to the Python executable inside the conda environment.
5. Create and Activate a Virtual Environment (Optional)
- Although conda environments handle this, you can create new environments to isolate project dependencies.
- Manage dependencies via
conda install package_nameinside the activated environment.
6. Use VS Code Terminal
- Open the integrated terminal in VS Code (
View > Terminal). - It should start with the chosen conda environment activated, allowing you to run Python scripts using the selected interpreter.
7. Run and Debug Python Code
- Open a
.pyfile. - Click the Run icon or press
F5to run/debug scripts with your Anaconda Python interpreter. - VS Code handles breakpoints, variable inspection, and interactive debugging.
8. Install Required Packages
- Use the terminal in VS Code to install packages with conda or pip:
orconda install numpy pandaspip install requests
9. Optional: Use Jupyter Notebooks in VS Code
- You can open
.ipynbfiles directly in VS Code. - Jupyter support comes with the Python extension and works seamlessly within your Anaconda environments.