Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ModuleNotFoundError: No module named 'seaborn' #1439

Open
desertproject opened this issue Nov 27, 2024 · 1 comment
Open

ModuleNotFoundError: No module named 'seaborn' #1439

desertproject opened this issue Nov 27, 2024 · 1 comment
Labels
bug Something isn't working

Comments

@desertproject
Copy link

desertproject commented Nov 27, 2024

System Info

OS version: Debian GNU/Linux 12 (bookworm)
Python version: Python 3.11.2
The current version of pandasai being used: 2.4.0

🐛 Describe the bug

When instantiating a new Agent, the following error occurs, indicating that seaborn should not be an optional dependency:

Traceback (most recent call last):
  File ".../streamlit/runtime/scriptrunner/exec_code.py", line 88, in exec_func_with_error_handling
    result = func()
             ^^^^^^
  File ".../streamlit/runtime/scriptrunner/script_runner.py", line 579, in code_to_exec
    exec(code, module.__dict__)
  File ".../app.py", line 1, in <module>
    from pandasai import Agent
  File ".../pandasai/__init__.py", line 6, in <module>
    from pandasai.smart_dataframe import SmartDataframe
  File ".../pandasai/smart_dataframe/__init__.py", line 27, in <module>
    from pandasai.agent import Agent
  File ".../pandasai/agent/__init__.py", line 1, in <module>
    from .agent import Agent
  File ".../pandasai/agent/agent.py", line 5, in <module>
    from pandasai.agent.base import BaseAgent
  File ".../pandasai/agent/base.py", line 8, in <module>
    from pandasai.agent.base_security import BaseSecurity
  File ".../pandasai/agent/base_security.py", line 2, in <module>
    from pandasai.pipelines.pipeline import Pipeline
  File ".../pandasai/pipelines/__init__.py", line 3, in <module>
    from .pipeline import Pipeline
  File ".../pandasai/pipelines/pipeline.py", line 5, in <module>
    from pandasai.config import load_config_from_json
  File ".../pandasai/config.py", line 4, in <module>
    from . import llm
  File ".../pandasai/llm/__init__.py", line 5, in <module>
    from .google_gemini import GoogleGemini
  File ".../pandasai/llm/google_gemini.py", line 16, in <module>
    from ..helpers.optional import import_dependency
  File ".../pandasai/helpers/optional.py", line 22, in <module>
    from pandasai.safe_libs.restricted_seaborn import RestrictedSeaborn
  File ".../pandasai/safe_libs/restricted_seaborn.py", line 1, in <module>
    import seaborn as sns
ModuleNotFoundError: No module named 'seaborn'

After installing seaborn using poetry add seaborn, the following error occurs, indicating that pyyaml is also required:

Traceback (most recent call last):
  File ".../streamlit/runtime/scriptrunner/exec_code.py", line 88, in exec_func_with_error_handling
    result = func()
             ^^^^^^
  File ".../streamlit/runtime/scriptrunner/script_runner.py", line 579, in code_to_exec
    exec(code, module.__dict__)
  File ".../app.py", line 1, in <module>
    from pandasai import Agent
  File ".../pandasai/__init__.py", line 6, in <module>
    from pandasai.smart_dataframe import SmartDataframe
  File ".../pandasai/smart_dataframe/__init__.py", line 27, in <module>
    from pandasai.agent import Agent
  File ".../pandasai/agent/__init__.py", line 1, in <module>
    from .agent import Agent
  File ".../pandasai/agent/agent.py", line 5, in <module>
    from pandasai.agent.base import BaseAgent
  File ".../pandasai/agent/base.py", line 8, in <module>
    from pandasai.agent.base_security import BaseSecurity
  File ".../pandasai/agent/base_security.py", line 2, in <module>
    from pandasai.pipelines.pipeline import Pipeline
  File ".../pandasai/pipelines/__init__.py", line 3, in <module>
    from .pipeline import Pipeline
  File ".../pandasai/pipelines/pipeline.py", line 5, in <module>
    from pandasai.config import load_config_from_json
  File ".../pandasai/config.py", line 6, in <module>
    from .schemas.df_config import Config
  File ".../pandasai/schemas/df_config.py", line 4, in <module>
    from pandasai.helpers.dataframe_serializer import DataframeSerializerType
  File ".../pandasai/helpers/dataframe_serializer.py", line 4, in <module>
    import yaml
ModuleNotFoundError: No module named 'yaml'

To resolve this, I had to run poetry add pyyaml, and then everything worked correctly.

Suggestion

  1. Make seaborn a required dependency: It appears that seaborn is being imported without being marked as a required dependency, causing errors when it's missing. It should either be made a required dependency or a check should be added to verify if it is present in the environment before importing.

  2. Make pyyaml a required dependency: Similarly, pyyaml should be listed as a required dependency, as it is necessary for proper functionality.

Copy link

dosubot bot commented Nov 27, 2024

Hey @desertproject! I'm here to help you with any bugs, questions, or contributions you have. I'm a bot designed to assist you while you wait for a human maintainer.

The issue you're encountering is due to seaborn and pyyaml being used in the code without being listed as required dependencies in the pyproject.toml file. Currently, seaborn is treated as an optional dependency, and the codebase includes mechanisms to handle its absence using conditional imports [1]. However, it seems that in some parts of the code, seaborn is imported directly, leading to the ModuleNotFoundError when it's not installed.

To address this, you can consider the following suggestions:

  1. Make seaborn a required dependency: If seaborn is essential for the functionality of the project, it should be added to the required dependencies in the pyproject.toml file. This ensures that it is installed automatically when setting up the project.

  2. Make pyyaml a required dependency: Similarly, if pyyaml is necessary for the project to function correctly, it should also be added to the required dependencies.

These changes would prevent the ModuleNotFoundError by ensuring that both seaborn and pyyaml are installed when the project is set up. If you have the ability to modify the pyproject.toml file, you can add these dependencies there. Otherwise, you might want to discuss this with the maintainers to see if they can update the dependency list accordingly.

To continue talking to Dosu, mention @dosu.

@dosubot dosubot bot added the bug Something isn't working label Nov 27, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant