Loading video player…

Installing Altair

00:00 In this lesson, you’ll start by installing the Altair library. It’s generally a good idea to install things like third-party packages in what’s called a virtual environment.

00:09 This keeps the packages relating to this project together and separate from your other projects. In this course, we’ll use a virtual environment created using uv.

00:19 There are other tools to manage virtual environments, such as venv, so feel free to use whatever works for you. In data science, uv is becoming increasingly popular because it’s fast and a modern way to handle your projects and your package management.

00:35 So first of all, you need to have uv installed. Then, in your project folder, type uv init to initialize the project.

00:48 And there you can see a project has been initialized. Once you have a project and a virtual environment set up, you can add your third-party libraries to it, such as Altair.

00:59 With uv, the command looks like this. Back in the terminal, type uv add altair.

01:09 And you see that was lightning fast. The next step is to add some more dependencies that you need for this project. You’re actually going to need pandas because we’re going to be working with data stored in DataFrames, and we’re also going to need notebook because we’re going to be working in Jupyter Notebooks.

01:26 So add pandas and notebook to the environment.

01:40 And now that’s done as well.

01:43 I’ve now opened the project folder in VS Code and selected the virtual environment’s kernel. This lets VS Code use the correct virtual environment. When using a tool outside the terminal, such as VS Code, it’s important that the correct environment is selected so the right version of Python and third-party libraries are used.

02:03 If you prefer to use Jupyter in the browser, you can also run uv run jupyter notebook or uv run jupyter lab. Now, before we go on, verify that you have Altair installed in the correct environment in Jupyter.

02:19 Create a new code cell and import Altair. The preferred way to import Altair is using the alias alt.

02:29 That succeeded, so now you’re ready to go. If you’re interested in finding out more about virtual environments, here’s a tutorial you can check out. And here is a specific tutorial about the differences between using pip and uv for virtual environment management.

02:46 And finally, if you’re interested in finding out more about Jupyter Notebooks, there’s a tutorial for that as well. Now that you’ve successfully installed Altair, it’s time to create your first chart, which is what we’ll be doing in the next lesson.

Become a Member to join the conversation.