Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings
Discussion options

🧡 Chainlit App Not Launching β€” LLMs-from-scratch ch07/app.py Import Failures

I'm currently working through the LLMs-from-scratch project and trying to run the Chainlit interface for ch07 using:

LLMs-from-scratch/llms_from_scratch> chainlit run ch07/app.py

Chainlit initializes and creates translation files:

Created default translation file at .chainlit/translations/de-DE.json  
Created default translation file at .chainlit/translations/ko.json

But then crashes with:

ModuleNotFoundError: No module named 'LLMs_from_scratch'

I also tried:

python -m chainlit run ch07/app.py

Still got:

ModuleNotFoundError: No module named 'LLMs_from_scratch'

After correcting the import to lowercase (llms_from_scratch), I hit another error:

ImportError: cannot import name 'GPTModel' from 'llms_from_scratch.ch04' (unknown location)

Then I tried to run the file directly:

python ch04/GPTModel.py

And got:

python: can't open file '...ch04/GPTModel.py': [Errno 2] No such file or directory

Also tried:

llms_from_scratch/ch04/GPTModel.py

But got:

'llms_from_scratch' is not recognized as an internal or external command

Finally, after correcting the import path again, I hit this:

ImportError: cannot import name 'generate' from 'llms_from_scratch.ch05.gpt_download'

πŸ” My Conditions

  • I’m new to coding and just started learning, so I’m still figuring out how imports, modules, and project structures work.
  • Running everything from inside the llms_from_scratch folder.
  • Chainlit CLI is installed and working.
  • app.py exists and is being picked up.
  • Import paths in app.py seem to mismatch the actual folder structure.
  • GPTModel.py is either missing or misnamed in ch04.
  • generate is not defined or exposed in ch05/gpt_download.py.

🧱 What I Need Help With

  • Has anyone successfully launched ch07/app.py without modifying the original imports?
  • Is GPTModel defined somewhere else or exposed differently?
  • Is generate supposed to be defined in gpt_download.py, or is it a wrapper that’s missing?
  • Should the folder/module naming be standardized before Chainlit can load it properly?

Any working setups, guidance, or upstream fixes would be appreciated. I’ll keep adding logs if needed. Thanks in advance β€” I’m still learning and trying to understand how all these pieces fit together.

You must be logged in to vote

Replies: 3 comments · 4 replies

Comment options

Ah sorry, a while back, I cleaned up the code a bit and moved it into the llms_from_scratch Python package inside the pkg folder in this repo ( (https://github.com/rasbt/LLMs-from-scratch/tree/main/pkg/llms_from_scratch) so that often reused code is not excessively duplicated everywhere to reduce clutter.

What you could do is, in the main folder of this repo, run

pip install -e .

or, if you are using uv:

uv add . --dev

This will install the llms_from_scratch package from your local copy of this repo.

You can then also still make changes to your local code in pkg/llms_from_scratch, and they will be automatically reflected when you run the script the next time.

(Alternatively, you could also install it from pypi via pip install llms_from_scratch)

Please let me know if this works for you.

You must be logged in to vote
0 replies
Comment options

Hi Sebastian,

Thank you so much for your previous response and for maintaining such a fantastic repository. I’ve been following your book and YouTube videos closely, and I’m really excited to learn about LLMs and generative AI. I’m new to coding and Python, and while I’ve learned a lot from your materials, I’ve been struggling to get the project running smoothly on my Windows machine.


πŸ§ͺ What I’ve Tried

βœ… Environment Setup

  • Installed Python 3.11.0
  • Created a virtual environment using uv:
    uv venv --python=python3.11
    .\.venv\Scripts\activate

βœ… Package Installation

  • From the root of the repo, I ran:
    pip install -e .
    and also tried:
    uv add . --dev
  • Both completed without errors, but when I tried importing modules like:
    from llms_from_scratch.ch04 import GPTModel
    I got:
    ModuleNotFoundError: No module named 'llms_from_scratch.ch04'
    

πŸ“ My Project Structure

Here’s how my local copy of the repo is organized:

LLMs-from-scratch/
β”œβ”€β”€ .chainlit/
β”œβ”€β”€ .files/
β”œβ”€β”€ .ipynb_checkpoints/
β”œβ”€β”€ .venv/
β”œβ”€β”€ llms_from_scratch/
β”‚   β”œβ”€β”€ app.py
β”‚   β”œβ”€β”€ appendix-A/
β”‚   β”œβ”€β”€ appendix-D/
β”‚   β”œβ”€β”€ appendix-E/
β”‚   β”œβ”€β”€ ch02/
β”‚   β”œβ”€β”€ ch03/
β”‚   β”œβ”€β”€ ch04/
β”‚   β”œβ”€β”€ ch05/
β”‚   β”œβ”€β”€ ch06/
β”‚   β”œβ”€β”€ ch07/
β”‚   β”œβ”€β”€ pkg/
β”‚   β”œβ”€β”€ setup/
β”‚   β”œβ”€β”€ CITATION.cff
β”‚   β”œβ”€β”€ LICENSE.txt
β”‚   β”œβ”€β”€ pixi.toml
β”‚   β”œβ”€β”€ pyproject.toml
β”‚   β”œβ”€β”€ README.md
β”‚   β”œβ”€β”€ requirements.txt
β”‚   └── serve.py
β”œβ”€β”€ pkg/
β”œβ”€β”€ requirements.txt
β”œβ”€β”€ setup.py
β”œβ”€β”€ test_prompt.py
β”œβ”€β”€ Untitled.ipynb

I’m not sure if the presence of both pkg/ and llms_from_scratch/ folders is causing confusion for Python’s import system. I’ve tried activating the virtual environment from inside llms_from_scratch, but I got:

The system cannot find the path specified.

πŸ§ͺ Chainlit Error Report

When I tried running the Chainlit app from chapter 7 (app.py inside ch07/06_user_interface), I got the following error:

ModuleNotFoundError: No module named 'llms_from_scratch.ch04'

Here’s the full traceback:

chainlit run app.py
...
File "app.py", line 11, in <module>
    from llms_from_scratch.ch04 import GPTModel
ModuleNotFoundError: No module named 'llms_from_scratch.ch04'

I tried running it again and got the same error on line 17. I’ve tried installing the package, adjusting paths, and even manually modifying sys.path, but nothing has worked reliably.


⚠️ What’s Been Difficult

  • Understanding how to structure the folders so Python can find the modules
  • Knowing where to run each command from (root vs subfolder)
  • Getting the imports to work across chapters
  • Running Chainlit without crashing due to missing model files or import errors

Even though I’ve followed your videos and instructions, the setup feels overwhelming for someone new to coding. Importing files and managing environments has been a nightmare for me, and I’m not sure if I’m missing something fundamental.


πŸ™ What I’m Asking For

Would it be possible for you to share a step-by-step setup guide for Windows users β€” including:

  • How to structure the folders
  • How to set up the environment
  • How to install the package locally
  • How to run the notebooks and Chainlit apps without import errors

Even just a short checklist or annotated example would help a lot. I’m really motivated to learn and build, and I want to make sure I’m following your book the right way.

Thanks again for your time and support β€” your work is truly appreciated.

Best regards,

You must be logged in to vote
3 replies
@rasbt
Comment options

It looks like you installed the package with both pip and uv, so I'd expect that at least one of them installed it in the right place. However, let's assume you are using primarily uv, in this case, can you try the following command:

uv run chainlit run app.py

(PS: Sorry, unfortunately I don't have a computer that can run Windows, and I also have unfortunately no experience with it; however, I think it should probably work via the uv run chainlit run app.py command; it looks like it's merely an installation issue.)

@ngonde1
Comment options

Hi Sir, thanks again for your respond

Following the yours advice, I tried running the Chainlit app using:

uv run chainlit run app.py

This command was meant to:

  • Use the uv environment manager to run Chainlit
  • Ensure the correct environment and installed packages are used
  • Avoid import errors by relying on uv's internal resolution

⚠️ First Result

I received the following error:

Error: Invalid value: File does not exist: app.py

This happened because I ran the command from the root folder:

LLMs-from-scratch/

…but the actual app.py file is located deeper inside:

llms_from_scratch/ch07/06_user_interface/app.py

🧠 Adjusted Attempt

I corrected the path and ran:

uv run chainlit run llms_from_scratch/ch07/06_user_interface/app.py

This time, Chainlit found the file, but the app crashed with:

ModuleNotFoundError: No module named 'llms_from_scratch.ch04'

Despite having installed the package using both:

pip install -e .

and

uv add . --dev

…the import still failed. I also tried manually adjusting sys.path, but nothing worked reliably.


After several attempts of troubleshooting, I’ve decided to rebuild the project from scratch using Conda instead of uv. I’ll clean up the environments, reinstall dependencies, and restructure the setup to see if that resolves the import issues and makes the workflow more stable on Windows.

I’m hopeful that starting fresh with Conda will give me better control and clarity over the environment and package paths.

Thank you once again

@casinca
Comment options

in case you want to retry on Windows with uv, the commands below are similar to what you've done but to make sure.
First delete your venv folder and make sure you are in the correct directory: root of your repo folder in your terminal or your IDE (like vscode, pycharm) terminal

I think it's still powershell by default? and run the commands in the image (make sure you see .venv once activated for the last command
image

After that if you do pip list or uv pip list you should be able to see in the list "llms-from-scratch" installed
Hope that helps otherwise Idk either what could have gone wrong

Edit: My bad I forgot uv will install the first python version it sees if not specified, if you have already python 3.11 it should be fine otherwise replace the first command with uv venv .venv --python 3.11 or uv venv --python 3.11 same thing

Comment options

Guys, I can't find my way out on sure this issue. so many attempts but all fialed.

You must be logged in to vote
1 reply
@rasbt
Comment options

rasbt Oct 7, 2025
Maintainer

Arg, it's a bummer that it turns out to be so frustrating to get to work in your case. I would maybe sugges

I think you are potentially running into two things at once:

  1. running Chainlit from the wrong working directory, and
  2. importing subpackages

I would maybe suggest giving it another try, starting with a fresh installation / venv.

E.g,.

# from the repo ROOT (the folder that contains pyproject.toml)
Remove-Item -Recurse -Force .venv -ErrorAction Ignore
uv venv --python 3.11
.\.venv\Scripts\Activate.ps1
# Remove any previous installs in this venv just in case
uv pip uninstall -y llms-from-scratch llms_from_scratch 2>$null

# Install the local package (this installs pkg/llms_from_scratch)
uv pip install -e .

And then try chainlit again:

uv run chainlit run llms_from_scratch/ch07/06_user_interface/app.py
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
3 participants
Morty Proxy This is a proxified and sanitized view of the page, visit original site.