brew install python3This command uses Homebrew to install Python 3 on your macOS system. Homebrew is a package manager that simplifies the installation of software on macOS.
After installation, check the versions of Python and pip:
python3 --version
pip3 --versionThese commands will display the installed versions, confirming a successful installation.
Install Jupyter using pip:
pip3 install jupyterThis installs Jupyter globally, allowing you to use it across your system.
- Open the Extensions view in VSCode (Ctrl+Shift+X).
- Search for "Pylance" and install it.
Pylance provides enhanced language support for Python, including:
- Type checking
- Auto-imports
- Code completion
- Refactoring
- Syntax highlighting
- In the Extensions view, search for "Jupyter" and install it.
The Jupyter extension allows you to create and run Jupyter notebooks directly in VSCode.
To test the Python installation:
-
Open Visual Studio Code (VSCode) or your preferred code editor.
-
Create a new file named
index.py. -
Add the following code:
print("Hello Python")
-
Save the file and run it in the terminal:
python3 index.py
You should see "Hello Python" printed in the terminal.
Jupyter notebooks are powerful, interactive documents that combine live code, equations, visualizations, and narrative text. They offer several key features:
- Interactive Computing: You can write and execute code in discrete cells, seeing the results immediately below the code.
- Rich Media Output: Notebooks can display various types of output including text, images, HTML, LaTeX equations, and interactive plots.
- Markdown Support: You can include formatted text using Markdown for documentation and explanations alongside your code.
- Language Flexibility: While commonly used with Python, Jupyter supports many programming languages.
- Sharable and Convertible: Notebooks can be easily shared and converted to other formats like HTML or PDF.
Jupyter notebooks are widely used in data science, scientific computing, and education due to their ability to create and share documents that contain live code, equations, visualizations, and explanatory text.
- Create a new file with the
.ipynbextension (e.g.,trial.ipynb). - VSCode will open it as a Jupyter notebook.
For Python projects, it's recommended to use a virtual environment. This environment controls any packages you install into the workspace:
python3 -m venv venv
source venv/bin/activateThis creates a virtual environment named venv and activates it.
If you need to exit the virtual environment, you can do so by running:
deactivate- You can add both Markdown and code cells in a Jupyter notebook.
- To add a new cell, click the "+ Code" or "+ Markdown" button.
- Execute code blocks independently by clicking the "Run" button or using Shift+Enter.
When working with Jupyter notebooks, it's crucial to select the correct kernel, which corresponds to your Python environment:
- Open your Jupyter notebook in VSCode.
- Look for the "Select Kernel" button in the top right corner of the notebook.
- Click on it and choose the kernel that corresponds to your
venvenvironment. It should be listed as something like "Python 3.x.x ('venv': venv)" and will often have 'Rec. (Recommended)' next to it.
After you select the kernel, you should see the venv environment in the top right corner of the notebook:
- If you don't see your
venvenvironment, you may need to restart VSCode or reload the window.
Selecting the correct kernel ensures that your notebook uses the Python interpreter and packages from your virtual environment, maintaining consistency with your project setup.
NOTE: When you first try to run code inside a Jupyter block or when you try to choose the kernel, you will most likely receive a popup saying that you must install ipykernel.
Choose Install
- Jupyter notebooks are great for data analysis, visualization, and creating interactive documents.
- You can install additional Python packages within your virtual environment using
pip install <package-name>. - Remember to activate your virtual environment when working on your Python projects.
- VSCode's Python and Jupyter extensions provide features like IntelliSense, debugging, and code navigation, enhancing your development experience.
- Jupyter notebooks provide an excellent environment for exploratory data analysis, creating data visualizations, and developing and testing algorithms incrementally.
- The combination of code execution, rich text, and immediate output makes notebooks ideal for creating comprehensive, self-documenting pieces of analysis or research.



