ModuleNotFoundError: No module named 'project_name'

I keep running into this ModuleNotFoundError when running crewai run

presumably from the .venv it auto creates.
File “/path/to/my/project/stock_analyst/.venv/bin/run_crew”, line 5, in
from stock_analyst.main import run
ModuleNotFoundError: No module named ‘stock_analyst’
An error occurred while running the crew: Command ‘[‘uv’, ‘run’, ‘run_crew’]’ returned non-zero exit status 1.

“stock_analyst” is my project root folder’s name.

My main.py file

#!/usr/bin/env python
import sys
import warnings

from stock_analyst.crew import StockAnalyst

warnings.filterwarnings("ignore", category=SyntaxWarning, module="pysbd")

# This main file is intended to be a way for you to run your
# crew locally, so refrain from adding unnecessary logic into this file.
# Replace with inputs you want to test with, it will automatically
# interpolate any tasks and agents information

def run():
    """
    Run the crew.
    """
    inputs = {
        "stock": 'Tesla'
    }
    StockAnalyst().crew().kickoff(inputs=inputs)

I didn’t change the remaining code.

crew.py header

from crewai import Agent, Crew, Process, Task
from crewai.project import CrewBase, agent, crew, task

# Uncomment the following line to use an example of a custom tool
# from stock_analyst.tools.custom_tool import MyCustomTool

# Check our tools documentations for more information on how to use them
# from crewai_tools import SerperDevTool

@CrewBase
class StockAnalyst():
	"""StockAnalyst crew"""

	agents_config = 'config/agents.yaml'
	tasks_config = 'config/tasks.yaml'

in agents.yaml and tasks.yaml, I just modified them. One of my agents are

data_retriever:
  role: >
    {stock} Stock Data Retriever
  goal: >
    Fetch historical {stock} stock data from financial APIs.
  backstory: >
    You're an expert in financial data retrieval. Your skills in accessing
    and processing stock market data help traders make informed decisions.

Screenshot of project structure:

Please let me know if you need more information.

Does anyone know what this problem is? Please advise, thanks

@joycelz Please edit your question above and add the code.

@rokbenko thanks for your reply, I just edited the post. Please take a look again, thank you

@joycelz Can you please edit it again and also add a screenshot of your project folder structure? Open all folders so that we can see where all files are located.

@rokbenko done, do you want me to open bin, lib, share in .venv as well?

@joycelz Try to import the StockAnalyst class as follows:

# main.py
from .crew import StockAnalyst

@rokbenko it throws the same error

Running the Crew
Traceback (most recent call last):
  File "stock_analyst/.venv/bin/run_crew", line 5, in <module>
    from stock_analyst.main import run
ModuleNotFoundError: No module named 'stock_analyst'
An error occurred while running the crew: Command '['uv', 'run', 'run_crew']' returned non-zero exit status 1.

@joycelz What’s your CrewAI SDK version? What command are you using to run the crew?

@rokbenko
version is 0.86.0, I’m using
crewai run

I have the same error with a new project

File "/Users/vincent/Desktop/rgpd_crew/.venv/bin/run_crew", line 6, in <module> from rgpd_crew.main import run ModuleNotFoundError: No module named 'rgpd_crew' An error occurred while running the crew: Command '['uv', 'run', 'run_crew']' returned non-zero exit status 1.

#!/Users/vincent/Desktop/rgpd_crew/.venv/bin/python
# -*- coding: utf-8 -*-
import re
import sys

from rgpd_crew.main import run
if __name__ == "__main__":
    sys.argv[0] = re.sub(r"(-script\.pyw|\.exe)?$", "", sys.argv[0])
    sys.exit(run())

This error seems to pop up every time I make changes to the program

What do you mean? What changes? Can you please elaborate on that?

@rokbenko just very basic changes. For example, I added human_input=True for one of my tasks in crew.py
That was the only line I edited, the program was running fine and performing tasks correctly, but after I added this line, this same error pops up.

The solution I’m using now is to delete the entire folder locally on my computer, re-clone it from git, re-create my virtual environment. This works but I feel there should be a better solution, really hope we can figure out what’s going on. Will appreciate any inputs. Thanks!

So, sometimes it works and other times not? Or after you make a change, it stops working at all no matter how many times you kick off the crew?

Ugh, that’s really not the way to go.

Yes, when it stops working it stops, no matter how many times I kick off the crew.

@joycelz Got it! Have you tried downgrading the CrewAI SDK version and see if the issue still persists? Let’s say, 0.85.0 or older. It might be a bug in the newest version.

Yes, I had used 0.80.0 and I still ran into the same issue once. But I can try again using other versions to see if the issue persists.

@joycelz Can you please share a GitHub repository with me so that I can try to reproduce the issue and solve it?

@rokbenko Yes! Here’s the link GitHub - joycerlz/crewai

It will run successfully at the initial execution, you might need to run it a couple times/make some changes in the source code/have it open for a while and then come back and run it again to see the error message. Please let me know if you have any questions, thank you!

Hm, that sounds like it’s related to your environment, not the CrewAI SDK.