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

FileNotFoundError: [Errno 2] No such file or directory: '/exports/charts/7f792cad-32b6-4385-b334-585a5d46e23a.png' #1458

Open
Catherineasdzz opened this issue Dec 9, 2024 · 2 comments
Labels
bug Something isn't working

Comments

@Catherineasdzz
Copy link

System Info

pandasai 2.3.0
ubuntu 0.20.04.1
python 3.9

🐛 Describe the bug

I looked up similar problems in the past and found that the drawing problems of GPT-3.5 and BambooLLM have been solved, but I still have the same problem when I run the code.

import os
import pandas as pd
from pandasai import Agent

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

os.environ["PANDASAI_API_KEY"] = "MY_API_KEY"

agent = Agent(sales_by_country,config={
    "save_charts": True,
    "open_charts": True,
    "save_charts_path": "/exports/charts",
    })
response = agent.chat('Which are the top 5 countries by sales?')
r2 = agent.chat(
    "Plot the histogram of countries showing for each one the gd. Use different colors for each bar",
)
Traceback (most recent call last):
  File "/root/miniconda3/envs/DataAI/lib/python3.9/site-packages/pandasai/pipelines/chat/generate_chat_pipeline.py", line 333, in run
    output = (
  File "/root/miniconda3/envs/DataAI/lib/python3.9/site-packages/pandasai/pipelines/pipeline.py", line 137, in run
    raise e
  File "/root/miniconda3/envs/DataAI/lib/python3.9/site-packages/pandasai/pipelines/pipeline.py", line 101, in run
    step_output = logic.execute(
  File "/root/miniconda3/envs/DataAI/lib/python3.9/site-packages/pandasai/pipelines/chat/code_execution.py", line 133, in execute
    {"content_type": "response", "value": ResponseSerializer.serialize(result)},
  File "/root/miniconda3/envs/DataAI/lib/python3.9/site-packages/pandasai/responses/response_serializer.py", line 35, in serialize
    with open(result["value"], "rb") as image_file:
FileNotFoundError: [Errno 2] No such file or directory: '/exports/charts/8998e704-c205-46ed-9a6c-3c23a031f93c.png'
@dosubot dosubot bot added the bug Something isn't working label Dec 9, 2024
Copy link

dosubot bot commented Dec 9, 2024

Hey @Catherineasdzz! I'm here to help you with any bugs, questions, or contributions. Let's tackle this together!

To resolve the FileNotFoundError when trying to save charts using the pandasai library, ensure that the directory where you intend to save the chart exists before attempting to save the file. You can modify your code to create the directory if it doesn't exist using the following approach:

import os
import pandas as pd
from pandasai import Agent
from pathlib import Path

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

os.environ["PANDASAI_API_KEY"] = "MY_API_KEY"

# Define the path where charts will be saved
save_charts_path = Path("/exports/charts")
# Ensure the directory exists
save_charts_path.mkdir(parents=True, exist_ok=True)

agent = Agent(sales_by_country, config={
    "save_charts": True,
    "open_charts": True,
    "save_charts_path": str(save_charts_path),
})

response = agent.chat('Which are the top 5 countries by sales?')
r2 = agent.chat(
    "Plot the histogram of countries showing for each one the gd. Use different colors for each bar",
)

This code snippet ensures that the directory /exports/charts is created if it does not already exist, preventing the FileNotFoundError [1].

To continue talking to Dosu, mention @dosu.


Help Dosu learn! Give it feedback: Great Response | Irrelevant Answer | Incorrect Sources | Too Verbose | Hallucination | Other

@Catherineasdzz
Copy link
Author

Catherineasdzz commented Dec 9, 2024

I''m sure that the directory /exports/charts has already existed, but the problem still exists. I even used GPT-4o but the problem is still not solved. @dosu

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