Skip to content

A. Importing the Ursina Library

Estimated time: 5 min | Next: B. Making a Game Window


๐ŸŽฏ Learning Goals

By the end of this lesson, you'll be able to:

  • โ—‹ from ursina import *Understand the meaning of
  • โ—‹ Understand what a library is
  • โ—‹ Understand why we import libraries

Core Concepts

What is a library (Library)?

libraryis a collection of code that other people made in advance.

๐Ÿ“ Analogy: a toolbox

A library is a toolboxis the same as!

  • a toolbox that holds a hammer, screwdriver, saw, and so on
  • You just take out the tool you need and use it
  • Use it right away โ€” no need to build your own tools!

The Ursina library comes packed with tools for making 3D games!

import flowchart

flowchart TD
    A["from ursina import *"] --> B["Load the Ursina library"]
    B --> C["Entity, color, Vec3, and more<br/>all features available!"]
    C --> D["Start 3D game development"]

    style A fill:#e3f2fd,stroke:#1976d2
    style B fill:#fff3e0,stroke:#f57c00
    style C fill:#e8f5e9,stroke:#388e3c
    style D fill:#f3e5f5,stroke:#7b1fa2

Comparison of major libraries

library Use Example
math Math calculations sqrt(), sin()
turtle 2D graphics Turtle drawing
ursina 3D game development Cubes, characters

Writing the code

from ursina import *

Description:

  • from ursina: From the Ursina library
  • import *: Import all features
  • * means "everything"

โš ๏ธ Order matters!

from ursina import *always goes at the Top of the fileof your code!

Without this line, you can't use any of Ursina's features.


Example Code

from ursina import *  # Import all of Ursina's features

# Now you can use Ursina(), Entity(), color, and more!

Result

Thanks to this line, you get access to 3D game features!


๐ŸŽฏ Quiz

Quiz: the import statement
from ursina import *in * โ€” what does it mean?
Show Answer

Answer: C) It means importing all features

* is a wildcard that means "everything." from ursina import * imports all of the Ursina library's features!


๐Ÿ”ง Debug Clinic

Problem: NameError: name 'Ursina' is not defined

Cause: from ursina import *: you didn't write it or there's a typo

Fix: At the very top of the file, from ursina import * Add

# โŒ Wrong code
app = Ursina()  # NameError occurs!
# โœ… Correct code
from ursina import *  # Import it first!
app = Ursina()

Problem: ModuleNotFoundError: No module named 'ursina'

Cause: Ursina isn't installed

Fix: Run the install command in the terminal

pip install ursina

Try Coding It Yourself

Try writing the code to import the Ursina library yourself!

Writing an import statement

Fill in the blank with the correct import statement.

Example Answer
from ursina import *

Description: This one line gives you access to all of Ursina's 3D game features!


๐Ÿงฉ Key Takeaways

What you learned in this lesson:

  • library: A collection of ready-made code (a toolbox)
  • import: The command to import a library
  • *: Means "everything" (a wildcard)
  • Position: Always at the very top of the file!

Review Checklist

  • [ ] Can you explain what a library is?
  • [ ] from ursina import *Do you understand what it means?
  • [ ] Do you know where in the file the import statement should go?

Next step: B. Making a Game Window โ†’