CopilotKit icon indicating copy to clipboard operation
CopilotKit copied to clipboard

🐛 Bug: ModuleNotFoundError: No module named 'dotenv'

Open natea opened this issue 1 year ago • 3 comments

♻️ Reproduction Steps

  1. add OpenAI API key and Tavily API key to .env file
  2. run poetry install
  3. run poetry run demo

✅ Expected Behavior

I expect that I wouldn't get the dotenv error when running the demo.

❌ Actual Behavior

An error occurred in the console:

$ poetry install
Installing dependencies from lock file

No dependencies to install or update

Installing the current project: ai_researcher (0.1.0)

$ poetry run demo
Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "/usr/local/Cellar/[email protected]/3.12.6/Frameworks/Python.framework/Versions/3.12/lib/python3.12/importlib/__init__.py", line 90, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<frozen importlib._bootstrap>", line 1387, in _gcd_import
  File "<frozen importlib._bootstrap>", line 1360, in _find_and_load
  File "<frozen importlib._bootstrap>", line 1331, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 935, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 995, in exec_module
  File "<frozen importlib._bootstrap>", line 488, in _call_with_frames_removed
  File "/Users/nateaune/Documents/code/CopilotKit/examples/coagents-ai-researcher/agent/ai_researcher/demo.py", line 3, in <module>
    from dotenv import load_dotenv
ModuleNotFoundError: No module named 'dotenv'

𝌚 CopilotKit Version

1.0.0

📄 Logs (Optional)

When I try to install dotenv, I see this in the output:

$ pip install python-dotenv
Requirement already satisfied: python-dotenv in /Users/nateaune/.pyenv/versions/3.10.10/lib/python3.10/site-packages (1.0.1)

natea avatar Sep 26 '24 17:09 natea

Check if python-dotenv is listed as a dependency:

Open the pyproject.toml file and ensure that python-dotenv is listed under [tool.poetry.dependencies]poetry add python-dotenv poetry run demo poetry shell

Aakarsh-tech avatar Sep 27 '24 09:09 Aakarsh-tech

It seems the error occurs because python-dotenv is not being recognized in the environment, even though it is installed. Here's a step-by-step guide to troubleshoot and resolve the issue:

Steps to fix:

  1. Check your pyproject.toml or requirements.txt: Ensure that python-dotenv is listed as a dependency in your pyproject.toml or requirements.txt file. If not, add it manually:

[tool.poetry.dependencies] python-dotenv = "^1.0.1"

Then, run:

poetry install

2.Activate virtual environment manually: Even though poetry manages virtual environments, it's possible the environment isn't activated. Run:

poetry shell

Then execute the demo again:

poetry run demo

3.Verify the installation of dotenv: You can confirm the installation of python-dotenv by running:

poetry show python-dotenv

This should show detailed information if dotenv is installed correctly.

4.Check Python version compatibility: Ensure that python-dotenv is compatible with the Python version you're using. If you're using Python 3.12, double-check if it has support for the dotenv version installed.

yoursyuvii avatar Sep 27 '24 18:09 yoursyuvii

okay, i updated the pyproject.toml file with "^1.0.1" (it was previously an earlier version)

And then I re-ran poetry install

I activated the venv using poetry shell and executed the demo with poetry run demo.

In a separate terminal window, I ran this command and confirmed that it's using the 1.0.1 version of python-dotenv.

(ai-researcher-py3.12) $ poetry show python-dotenv
 name         : python-dotenv
 version      : 1.0.1
 description  : Read key-value pairs from a .env file and set them as environment variables

I also started up the UI with npm run dev but when i go to http://localhost:3000, I'm getting a 500 Error message.

natea avatar Sep 27 '24 19:09 natea

Hi @natea, I see that it has been awhile. If you still see this issue please let us know and re-open this issue. Otherwise I'm going to close this out.

tylerslaton avatar May 19 '25 21:05 tylerslaton