Python in VS Code on MacOS
Posted: 2024-06-18
Tags: Python, MacOS, Jupyter, VS Code
Xcode is not a good IDE for Python. It can be done1, but VS Code is a better plan.
Actionable Takeaways
- Python is installed along with the Xcode command line tools:
xcode-select --install - Download VS Code from Microsoft’s site.
- Download the Jupyter extension in the VS Code Extension Marketplace.
- Create a virtual environment to work in (on the command line):
python3 -m venv env_name- This will create a directory named
env_namein the current directory.
- This will create a directory named
- Activate the virtual environment:
source ./env_name/bin/activate- You should see the command line prompt change to indicate your current environment.
- If not already installed, install Jupyter:
python -m pip install ipykernel jupyter- This takes about 250MB of space.
- Open the directory in VS Code and create a new Jupyter notebook.
- Click
Select Kernelon the right side of the window.- Select
Python Environments - You should see
env_namelisted. Select it.
- Select
Use deactivate to get out of the virtual environment.
Why venv?
It is a good idea to be able to containerize a project’s Python modules for easy disposal.
Apple uses Miniconda in their developer documentation2, but I dislike installing extra software when venv does everything I need.