Visual Studio Code is a powerful, free code editor that’s perfect for neuroscience research. This guide will get you up and running quickly with VS Code for Python development, PsychoPy experiments, data analysis, and computational modeling on macOS.
You’ll need three main components:
Easiest method: Direct download
Alternative: If you use Homebrew
brew install --cask visual-studio-code
Anaconda provides Python plus scientific packages neuroscientists commonly use.
source ~/.zshrcconda --version# Create environment with essential packages
conda create -n neuroscience python=3.11 numpy scipy pandas matplotlib jupyter -y
# Activate the environment
conda activate neuroscience
# Install neuroscience packages
pip install psychopy mne nibabel
Extensions add functionality to VS Code. Install these must-have extensions for neuroscience:
Quick install via VS Code:
Command line installation:
code --install-extension ms-python.python
code --install-extension ms-toolsai.jupyter
code --install-extension ms-python.pylance
Optional but useful:
.py)Cmd+Shift+P and type “Python: Select Interpreter”~/anaconda3/envs/neuroscience/bin/pythonThat’s it! VS Code will remember this setting.
With your neuroscience environment active:
conda activate neuroscience
pip install psychopy
experiment.py)from psychopy import visual, core, event
# Create window
win = visual.Window(size=(800, 600), fullscr=False)
# Create stimulus
text = visual.TextStim(win, text='Hello PsychoPy!', pos=(0, 0), height=0.1)
# Display stimulus
text.draw()
win.flip()
core.wait(2.0)
# Cleanup
win.close()
core.quit()
F5 or click the “Run Python File” buttonInteractive Development:
# %% to create code cells that you can run individuallyShift+Enter to run a cell and move to the next oneDebugging:
F5 to start debuggingCode Completion:
Ctrl+Space to manually trigger suggestionsVS Code has excellent built-in support for Jupyter notebooks - perfect for neuroscience data analysis.
Cmd+Shift+P → “Create: New Jupyter Notebook”Variable Explorer: See all your variables in the sidebar while working
Interactive Plots: Matplotlib and seaborn plots display inline
plt.show() in notebooksCode Cells in Python Files: Add # %% to create notebook-like cells in .py files
Shift+Enter# %%
import mne
import numpy as np
import matplotlib.pyplot as plt
# Load sample data
raw = mne.io.read_raw_fif('sample_data.fif', preload=True)
# %%
# Quick visualization
raw.plot_psd(fmax=50)
plt.show()
# %%
# Basic preprocessing
raw.filter(l_freq=1, h_freq=40)
raw.set_eeg_reference('average')
Many neuroscientists love Spyder’s interface. Here’s how to get similar functionality in VS Code:
View → Terminal → New Terminalpython to start interactive sessionVS Code will automatically recognize these patterns:
Reference: See VS Code’s Python tutorial for more shortcuts
VS Code excels at computational modeling thanks to its debugging capabilities and interactive features.
For decision-making and learning models, you’ll mainly need:
conda activate neuroscience
pip install scipy scikit-learn
pip install pymc # For Bayesian models
pip install matplotlib seaborn # For visualization
Create a new Python file for your model:
# decision_model.py
import numpy as np
import matplotlib.pyplot as plt
def drift_diffusion_model(drift_rate, threshold, n_trials=1000):
"""Simple drift diffusion model simulation"""
decisions = []
rts = []
for trial in range(n_trials):
evidence = 0
time_steps = 0
while abs(evidence) < threshold and time_steps < 1000:
evidence += np.random.normal(drift_rate, 1)
time_steps += 1
decision = 1 if evidence > 0 else 0
rt = time_steps * 0.001 # Convert to seconds
decisions.append(decision)
rts.append(rt)
return decisions, rts
# Run simulation
decisions, rts = drift_diffusion_model(drift_rate=0.5, threshold=10)
# Plot results
plt.figure(figsize=(10, 4))
plt.subplot(1, 2, 1)
plt.hist(rts, bins=30, alpha=0.7)
plt.xlabel('Reaction Time (s)')
plt.ylabel('Frequency')
plt.title('RT Distribution')
plt.subplot(1, 2, 2)
plt.bar([0, 1], [decisions.count(0), decisions.count(1)])
plt.xlabel('Decision')
plt.ylabel('Count')
plt.title('Decision Frequency')
plt.show()
Interactive Development: Use # %% cells to test model components
Debugging: Set breakpoints to inspect model behavior step-by-step
Variable Inspector: Monitor arrays and results in real-time
Integrated Plots: See results immediately without switching applications
Reference: VS Code’s Data Science tutorial covers advanced modeling workflows
VS Code can’t find Python packages
Cmd+Shift+P → “Python: Select Interpreter”~/anaconda3/envs/neuroscience/bin/pythonCmd+Shift+P → “Developer: Reload Window”PsychoPy experiments won’t run
conda activate neurosciencearch -x86_64 python experiment.pyJupyter notebooks won’t start
pip install ipykernelpython -m ipykernel install --user --name neuroscienceSlow performance with large data
**/data/** and **/*.nii.gzProject Organization:
my_experiment/
├── data/ # Raw data (never commit to git)
├── analysis/ # Analysis scripts
├── experiments/ # PsychoPy experiments
├── notebooks/ # Jupyter notebooks
└── results/ # Generated figures and results
Version Control:
.gitignore large files: *.nii.gz, *.edf, *.h5Reproducibility:
requirements.txt with package versionsnp.random.seed(42)Official Documentation:
Neuroscience-Specific:
You now have a powerful VS Code setup for neuroscience research! This configuration provides:
Start with the basics and gradually explore more advanced features as your projects grow. VS Code’s flexibility allows you to customize your environment as your research needs evolve.
Next Steps:
Cmd+Shift+P)Happy coding! 🧠🔬