The Energy Data Scientist

The Energy Data Scientist

How Python Modules & Packages work. Application: Energy

Packages & Modules in Energy

Dr Spyros Giannelos's avatar
Dr Spyros Giannelos
Dec 11, 2025
∙ Paid

If you’ve been using Python for a while, you’ve probably written import something hundreds of times. Have you ever stopped to think about what exactly you’re importing? Is it a module? A package? Does it matter? Yes, it does matter. And understanding the difference will make you a better Python developer.

Let’s start with the fundamentals.

What is a Module?

A module is simply any .py file. That’s it.

When you create a file called wind.py or solar.py or main.py, you’ve created a module. It doesn’t matter if the file is empty or contains thousands of lines of code. If it ends in .py, it’s a module.

Think of a module as a single book. It contains code (functions, classes, variables) that you can import and use elsewhere. Examples of modules you probably use all the time:

  • math - Python’s built-in math module

  • random - for generating random numbers

What is a Package?

A package is a folder that contains a special file called __init__.py along with one or more modules.

The __init__.py file is what transforms an ordinary directory into a package. This file can be empty (and often is for beginners), but its presence tells Python: “Treat this folder as a package that can be imported.”

Think of a package as a library building that contains multiple books (modules) organized together. Examples of popular packages:

  • pandas - for data analysis

  • numpy - for numerical computing

  • pvlib - for solar photovoltaic system modeling (we’ll use this later)

What is a Directory?

A directory is simply a folder without the __init__.py file. You can import directories. They become what are called “namespace packages” or “implicit namespace packages.” So import directory_energy works just fine.

The difference between a package and a directory is the presence of __init__.py. Add the file, and you get a Python package. Remove it, and you get a namespace package (a directory) that’s just a container.

Installing Packages in PyCharm

Quick tip for PyCharm users on macOS, to install a package like pvlib:

  1. Go to PyCharm menu → Settings

  2. Navigate to Python → Interpreter

  3. Click the + button

  4. Search for the package (e.g., pvlib)

  5. Click Install Package

Creating Packages and Modules in PyCharm

In PyCharm, when you click the + button in the Project view:

  • Python Package : Creates a folder with __init__.py

  • Python File : Creates a module (.py file)

  • Directory : Creates a plain folder (no __init__.py)

What you can do with __init__.py

Full code below with the Python model.

Join our community! Visit skool.com, search for “Energy Data Scientist”

User's avatar

Continue reading this post for free, courtesy of Dr Spyros Giannelos.

Or purchase a paid subscription.
© 2025 The Energy Data Scientist · Privacy ∙ Terms ∙ Collection notice
Start your SubstackGet the app
Substack is the home for great culture