e2b-dev / E2B

Secure open source cloud runtime for AI apps & AI agents
https://e2b.dev/docs
Apache License 2.0
6.6k stars 420 forks source link

ImportError: Unable to import e2b, please install with `pip install e2b`. #383

Closed lap1zl4zuli closed 1 month ago

lap1zl4zuli commented 3 months ago

Describe the bug ImportError: Unable to import e2b, please install with pip install e2b."

To Reproduce I have copied the code from the documentation from the official erb.dev site

# Artifacts are charts created by matplotlib when `plt.show()` is called
def save_artifact(artifact):
    print("New matplotlib chart generated:", artifact.name)
    # Download the artifact as `bytes` and leave it up to the user to display them (on frontend, for example)
    file = artifact.download()
    basename = os.path.basename(artifact.name)
    # Save the chart to the `charts` directory
    # Make sure the "charts" directory exists
    with open(f"./charts/{basename}", "wb") as f:
        f.write(file)

e2b_data_analysis_tool = E2BDataAnalysisTool(
    on_stdout=lambda stdout: print("stdout:", stdout),
    on_stderr=lambda stderr: print("stderr:", stderr),
    on_artifact=save_artifact,
)

Expected behavior I have already Installed the python library.

Terminal commands & output

{
    "name": "ImportError",
    "message": "Unable to import e2b, please install with `pip install e2b`.",
    "stack": "---------------------------------------------------------------------------
ImportError                               Traceback (most recent call last)
File e:\\ISF Analytica Infomatica\\Easy2Learn\\SQL chatbot\\.venv\\Lib\\site-packages\\langchain_community\\tools\\e2b_data_analysis\\tool.py:117, in E2BDataAnalysisTool.__init__(self, api_key, cwd, env_vars, on_stdout, on_stderr, on_artifact, on_exit, **kwargs)
    116 try:
--> 117     from e2b import DataAnalysis
    118 except ImportError as e:

ImportError: cannot import name 'DataAnalysis' from 'e2b' (e:\\ISF Analytica Infomatica\\Easy2Learn\\SQL chatbot\\.venv\\Lib\\site-packages\\e2b\\__init__.py)

The above exception was the direct cause of the following exception:

ImportError                               Traceback (most recent call last)
Cell In[2], line 12
      9     with open(f\"./charts/{basename}\", \"wb\") as f:
     10         f.write(file)
---> 12 e2b_data_analysis_tool = E2BDataAnalysisTool(
     13     on_stdout=lambda stdout: print(\"stdout:\", stdout),
     14     on_stderr=lambda stderr: print(\"stderr:\", stderr),
     15     on_artifact=save_artifact,
     16 )

File e:\\ISF Analytica Infomatica\\Easy2Learn\\SQL chatbot\\.venv\\Lib\\site-packages\\langchain_community\\tools\\e2b_data_analysis\\tool.py:119, in E2BDataAnalysisTool.__init__(self, api_key, cwd, env_vars, on_stdout, on_stderr, on_artifact, on_exit, **kwargs)
    117     from e2b import DataAnalysis
    118 except ImportError as e:
--> 119     raise ImportError(
    120         \"Unable to import e2b, please install with `pip install e2b`.\"
    121     ) from e
    123 # If no API key is provided, E2B will try to read it from the environment
    124 # variable E2B_API_KEY
    125 super().__init__(description=base_description, **kwargs)

ImportError: Unable to import e2b, please install with `pip install e2b`."
}

Desktop:

ValentaTomas commented 2 months ago

Hey @lap1zl4zuli, we moved data analysis/code interpreter to a separate package — https://pypi.org/project/e2b-code-interpreter/

You can install it with pip install e2b-code-interpreter and use it as:

from e2b_code_interpreter import CodeInterpreter

with CodeInterpreter() as sandbox:
    sandbox.notebook.exec_cell("x = 1")

    execution = sandbox.notebook.exec_cell("x+=1; x")
    print(execution.text)  # outputs 2

Check out our cookbook where we have Langchain example with the new package https://github.com/e2b-dev/e2b-cookbook

ValentaTomas commented 1 month ago

Closing because it seems to be resolved.