Loading video player…

Installing Python's Ollama Library

00:00 Now you’re almost done setting up your environment. You’ve installed Ollama and pulled the models, but before installing the ollama library, you could set up a virtual environment.

00:11 This is optional but recommended. So do that whatever way you prefer, but if you don’t have a preference, you can follow along with me now. First, you need a folder for your project code.

00:23 You can start one fresh or download the example code for this course from the starting page, unzip it, and navigate to that inside of VS Code. Now open up a terminal in the current location, and the current location here should be inside of your START-OLLAMA-CODE folder or whatever project folder you’re using, so pwd to confirm.

00:46 Now you can create a virtual environment using the command python -m venv venv. The python command that you use is going to depend on what works for your operating system and what version of Python you want to use.

01:03 I’m on a Mac, and I have Python 3.14 installed, so I’m going to use python3.14, and when I run that, it’s going to create a virtual environment folder here.

01:16 If you’re on Windows, you might need to use the py command, and then to target a certain version, you can use -3.14. And you’re going to need at least Python 3.8 or higher for this course.

01:29 Now to activate the virtual environment on Mac and Linux, you can say source venv/bin/activate to run the activate script. On the next line, you can see that the virtual environment is active, and now it’s time to install ollama.

01:49 If you’re on Windows, the command to activate it would be .\venv\Scripts\Activate.ps1.

02:02 So here are the links for the PyPI repository page, the source code on GitHub, and the API documentation for the ollama library.

02:13 Let’s install it now in your terminal. You can run pip install ollama.

02:20 Note that because the virtual environment is active, the pip and the python commands should work and should point to that environment.

02:28 Once that’s done, you can confirm that it was installed properly by running the python command to open up a REPL, then import ollama.

02:41 And if there were no import errors, everything’s good, and you can exit out of here and move on to actually start coding in Python. In the next lesson, you’re going to look at the different functions available in the ollama library, and then afterwards actually use them in your Python code.

Become a Member to join the conversation.