
How to Install and Run Your First Local LLM on Your Laptop
Have you ever used ChatGPT or other GenAI tools online? Imagine running one of these smart language models directly on your laptop—no coding experience required. In this guide, I’ll show you how to install a local LLM (Large Language Model) like DeepSeek and LLama2, using Ollama and run it within a Jupyter Notebook. All you need is a laptop with an internet connection. Simply follow the steps and copy-paste the code.
If you ever get stuck or want to understand what a particular piece of code does, you can harness the power of GenAI tools like ChatGPT or Gemini. Just paste the code in ChatGPT/Gemini and ask for an explanation, or share any error messages and request debugging help.
Ready? Let’s get started!
Step 1: Install Ollama
What is Ollama?
Ollama is a tool that makes it easy to download, optimize, and run LLMs (like LLaMA, DeepSeek) locally on your computer. With Ollama, you don’t need to be a tech expert or programmer to experiment with powerful language models.
How to Install Ollama:
- Download Ollama:
- Open your web browser and visit the Ollama official website.
- Download the Windows installer and follow the on-screen instructions to install it on your laptop (Note: For this tutorial I have used a Windows Laptop )
- Download a Model (LLaMA 2):
- After installing Ollama, open the Command Prompt in your laptop ( In Windows Search type ‘cmd’)
- Type the following command and press Enter. Wait till ‘success’ message is displayed.
ollama pull llama2

This command downloads the LLaMA 2 model to your system from Ollama. At the end of the blog I will explain how to use other LLM models also.
Now in case you want to use the LLM LLama2 for basic queries, you can just use the command prompt. For this type the below code in command prompt and ask the LLama2 any query.
ollama run llama2


In the above example I asked LLama2 what is the capital of USA. Note, to exit the LLM type /bye.
However for more complex use cases, command line prompt is not quite useful. Most developers therefore prefer Python code to call the LLM as it provides more flexibility. In the next section we will understand how to involve LLama2 using a Python code from a app called Jupyter notebook.
Step 2: Set Up Your Python Environment with Anaconda
Why Anaconda?
Anaconda is a user-friendly platform that helps you manage Python and its libraries. It includes Jupyter Notebook, an interactive tool where you can write and run Python code easily.
How to Install Anaconda:
- Download Anaconda Distribution (One Time Step):
- Go to the Anaconda website : https://www.anaconda.com/download
- Download the version for Windows and install it by following the instructions.
- Launch Jupyter Notebook:
- Once Anaconda is installed , open the Anaconda Navigator from your Start menu.
- Click on the “Launch” button under Jupyter Notebook.
- Once Jupyter Notebook opens in your browser, create a new Python notebook by clicking on New > Notebook.


Step 3: Communicate with Your Local LLM via Jupyter Notebook
Now that you have Ollama and Anaconda set up, you can run your first LLM using Python code in a Jupyter Notebook. Here are two simple options:
Option 1: Using the Requests Library
This method sends a prompt to the local LLM server ( set up in your laptop) and prints the response.
- Install the Requests Library: In a new cell in Jupyter notebook, type the below code and press SHIFT+ENTER
!pip install requests
- Run the Following Script: In a new cell now copy paste the below code and press SHIFT+ENTER
import requests
import json
# Define the Ollama API endpoint (it runs locally)
OLLAMA_API_URL = "http://localhost:11434/api/generate"
# Define the request payload
payload = {
"model": "llama2",
"prompt": "Tell me a joke", #Enter your query here which you want GenAI model to answer
"stream": False # Set to False for a simple response
}
# Send a request to Ollama's local server
response = requests.post(OLLAMA_API_URL, json=payload)
# Parse and print the response
if response.status_code == 200:
result = response.json()
print("Response:", result["response"])
else:
print("Error:", response.status_code, response.text)

- What this does:
The script sends a prompt (“Tell me a joke”) to your local LLM LLama2 running via Ollama and prints out the answer.
Option 2: Using the Ollama Python Package
Ollama provides a Python package for even easier interaction via Jupyter notebook.
- Install the Ollama Package: In a new cell in Jupyter notebook, type below code and press SHIFT+ENTER
!pip install ollama
- Run the Following Script: In a new cell now copy paste the below code and press SHIFT+ENTER
import ollama
response = ollama.chat(model="llama2", messages=[{"role": "user", "content": "Tell me a joke"}])
print("Response:", response["message"]["content"])

- What this does:
This script uses the Ollama package to send a request (“Tell me a joke”) to the LLaMA 2 model and prints the joke response.
What’s Next?
- Try Different Prompts: Change the prompt in your scripts (Tell me a Joke) to ask other questions or explore topics that interest you.
- Experiment with Other Models: Ollama also supports other models. For example, you can download them (Refer Step 1) with below code
ollama pull deepseek-r1:1.5b
ollama pull mistral
ollama pull gemma
Then, simply change “model”: “llama2” in your code (Step 3) to “model”: “mistral” or “model”: “deepseek-r1:1.5b” and re-run the code.
To get the list of models available for use and their names check out the Ollama website.


Ask ChatGPT or Gemini to create Python code for your use case
Now you have learned how to run a basic command in Python using Jupyter Notebook and invoke an LLM installed on your laptop. You can now leverage GenAI tools like ChatGPT to generate more complex code and execute it.
For example, I asked ChatGPT to create an interactive chatbot using the DeepSeek LLM for Jupyter Notebook. Then, I used Step 3, Option 1 (mentioned above) to run the code successfully.
import requests
# Ollama local API URL
OLLAMA_API_URL = "http://localhost:11434/api/generate"
while True:
user_input = input("You: ")
# Exit condition
if user_input.lower() in ["exit", "quit", "stop"]:
print("Exiting chat.")
break
# Modify the system message to prevent unwanted introductions
payload = {
"model": "deepseek-r1:1.5b",
"prompt": user_input,
"system": "You are a helpful assistant. Answer the user's question directly without any introductions.",
"stream": False
}
response = requests.post(OLLAMA_API_URL, json=payload)
if response.status_code == 200:
result = response.json()
print("DeepSeek-R1:", result["response"])
else:
print("Error:", response.status_code, response.text)

If you ever get stuck or want to understand what a particular piece of code does, you can harness the power of GenAI tools like ChatGPT/Gemini. Just paste the code and ask for an explanation, or share any error messages and request debugging help.
Conclusion
Congratulations! You’ve just installed and run a local LLM on your laptop. By following these steps, you’ve taken your first step into the exciting world of GenAI and machine learning. With minimal technical knowledge, you can now explore and experiment with powerful language models right from your own computer.
Feel free to share your experience or ask any questions in the comments below. Happy coding and exploring!
Discover more from Debabrata Pruseth
Subscribe to get the latest posts sent to your email.