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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

FileNotFoundError: [Errno 2] No such file or directory: 'path/to/project/exports/charts/temp_chart.png' #1092

Open
leungdunn opened this issue Apr 5, 2024 · 4 comments
Labels
bug Something isn't working good first issue Good for newcomers

Comments

@leungdunn
Copy link

leungdunn commented Apr 5, 2024

System Info

OS version: macOS Sonoma 14.4.1
Python version: 3.10.12
pandasai version: 2.0.28

馃悰 Describe the bug

It cannot go through when using the Agent to plot pictures. It is okay if the question response is supposed to be text.

Below is my code:

import os

from dotenv import load_dotenv
import pandas as pd
from pandasai import Agent

load_dotenv()

DEFAULT_PICTURE_FOLDER = "./exports/charts"

# create picture folder if necessary
if not os.path.isdir(DEFAULT_PICTURE_FOLDER):
    os.makedirs(DEFAULT_PICTURE_FOLDER)

df = pd.DataFrame({
    "country": ["United States", "United Kingdom", "France", "Germany", "Italy", "Spain", "Canada", "Australia", "Japan", "China"],
    "sales": [5000, 3200, 2900, 4100, 2300, 2100, 2500, 2600, 4500, 7000]
})

agent = Agent(
    df,
    config={
        "verbose": True,
        "enforce_privacy": True,
        "enable_cache": True,
        "conversational": False,
        "save_charts": False,
        "open_charts": False,
        "save_charts_path": DEFAULT_PICTURE_FOLDER,
    },
)

qeury = "Plot the histogram of countries in Europe showing for each the gdp, using different colors for each bar"
response = agent.chat(qeury)

full traceback is as below

Traceback (most recent call last):
  File "/Users/liaden/miniconda3/envs/genai/lib/python3.10/site-packages/pandasai/pipelines/chat/generate_chat_pipeline.py", line 283, in run
    output = (self.code_generation_pipeline | self.code_execution_pipeline).run(
  File "/Users/liaden/miniconda3/envs/genai/lib/python3.10/site-packages/pandasai/pipelines/pipeline.py", line 137, in run
    raise e
  File "/Users/liaden/miniconda3/envs/genai/lib/python3.10/site-packages/pandasai/pipelines/pipeline.py", line 101, in run
    step_output = logic.execute(
  File "/Users/liaden/miniconda3/envs/genai/lib/python3.10/site-packages/pandasai/pipelines/chat/code_execution.py", line 134, in execute
    {"content_type": "response", "value": ResponseSerializer.serialize(result)},
  File "/Users/liaden/miniconda3/envs/genai/lib/python3.10/site-packages/pandasai/responses/response_serializer.py", line 29, in serialize
    with open(result["value"], "rb") as image_file:
FileNotFoundError: [Errno 2] No such file or directory: '/Users/liaden/genai_streamlitapp/exports/charts/temp_chart.png'
@leungdunn leungdunn changed the title FileNotFoundError: [Errno 2] No such file or directory: '~/exports/charts/temp_chart.png' FileNotFoundError: [Errno 2] No such file or directory: 'path/to/project/exports/charts/temp_chart.png' Apr 6, 2024
@Emad-Eldin-G
Copy link

Got the same issue, any help is appreciated @gventuri

@gventuri gventuri added bug Something isn't working good first issue Good for newcomers labels May 23, 2024
@gventuri
Copy link
Collaborator

gventuri commented May 23, 2024

Does it work if you remove the save_charts_path? Did you check whether the folder actually exists and is created?

@Emad-Eldin-G
Copy link

Emad-Eldin-G commented May 23, 2024

Does it work if you remove the save_charts_path? Did you check whether the folder actually exists and is created?

I did recreate @leungdunn 's code to try and fix the error on my side, and I can say that the issue persists with or without specifying save_charts_path.

The weird thing is that the directory or folder itself is created (exports/charts/), but the png file for the chart output itself is not created.

@Emad-Eldin-G
Copy link

@leungdunn try to set open_charts to True, this will create the plot png file, which can then be accessed via the returned path.

Note that turning it to True also opens the file automatically.

Also try setting save_charts to True, this should create the plot and save it without opening it (Although this creates some unexpected behaviour, @gventuri check issue #1175)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working good first issue Good for newcomers
Projects
None yet
Development

No branches or pull requests

3 participants