Tuesday, July 15, 2025

Shift remote Jupyter Notebooks to run locally on MacOS with Pycharm



This year I've been working with IntelliJ so much that I decided to pay a little more and get the "All Packs" edition so I could use JetBrains IDEs with Python and .Net.  When I completed a Coursera course on Machine Learning, I wanted to have the Jupyter notebooks on my laptop so I'd have access to the materials in case I stopped my Coursera subscription.  The Jupyter notebooks for the course are a very good resource as I develop my own products that use machine learning, and I wanted them available on my Mac and Pycharm.  

Below are the steps and resources I used to: download the Jupyter notebooks and execute them on my MacBook.  Mac or Windows won't impact the steps much.  The I also included references to the resources I used work out what I needed to do but viewing them are not necessary as I'm showing the steps.  It took an hour to work out how to do this so hopefully this article will speed you along.

Tool chain: Web browser, Pycharm.  (Community edition of Pycharm doesn't allow execution of notebooks. I have the paid/Pro edition, which isn't very much for an individual developer.)

1) Download the entire lab files necessary to run the notebook

It's possible to just download and run a notebook but in my case, each notebook had dependencies with files outside of the notebook file (.ipynb file).  This required me to downloaded all the lab files.  This is likely a common situation so you'll probably need to do this too.  You'll know this is your case if when you look at the import statements in your notebook, you'll see items it's getting from custom modules that are available only as part of the notebook environment and cannot be pip installed later.  

An example of a notebook using custom modules


The following steps will produce a Zip file of the lab. Unzip the files to a location where you wish to keep this work.



Optional Reading: 

https://community.deeplearning.ai/t/downloading-your-notebook-downloading-your-workspace-and-refreshing-your-workspace/475495#1.2

2) Create a Pycharm project at that location. I used the "create venv" for interpreter.

Open Pycharm and create a project for the directory containing the zip file you downloaded. I didn't like the "Files" directory that wrapped the files in the zip so I moved those files out and removed the "Files" directory. I kept the "Files.zip" but renamed it to "Original Download Files.zip" so I'd later know what the contents are and I could have a backup if I later mucked up the notebooks too much.

Expanded the Zip file and moved the contents of the Files directory up one level.

Create the Pycharm project




Optional viewing:

https://youtu.be/4Ji-r455FVk

https://youtu.be/uiIKaacMGoE

3) Add dependencies that you know of into the Requirements.txt

Although the local dependencies needed by the notebook are available, there will be some others that were pip installed by the lab.  You can find out what those are by looking at the import statements at the top of each notebook. What I did is then add them to the Pycharm project's Requirements.txt. Or you can use the Pycharm's Python Packages tool.


 
This is an alternative to hand editing the Requirements.txt file.

4) Operate the notebook

Navigate to a notebook and execute it and see how it does. You may discover runtime errors at which point you'll need to determine what dependency you missed in which case look through the error message to discover what is missing, or click on the Pycharm AI button and it will help.  If you forget to install the dependencies listed in Requirements.txt, you'll be reminded when opening the notebook.

You'll know you've got your notebook sorted when all the cells execute without errors.

This is an example.