Python project in Visual Studio Code

TrackJava to Python Journey
Current SectionSetup
Progress3 of 19

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 --version in 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) or Ctrl+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_name inside 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 .py file.
  • Click the Run icon or press F5 to 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:
    conda install numpy pandas
    
    or
    pip install requests
    

9. Optional: Use Jupyter Notebooks in VS Code

  • You can open .ipynb files directly in VS Code.
  • Jupyter support comes with the Python extension and works seamlessly within your Anaconda environments.