[Pip library list] Cannot list installed package or install new package #2

Closed
opened 2026-02-16 08:18:51 -05:00 by yindo · 3 comments
Owner

Originally created by @tradanghi1999 on GitHub (Apr 28, 2025).

Sorry, I have not found any guide on install new package in langchain-sandbox so I try these code

from langchain_sandbox import PyodideSandbox

# Create a sandbox instance
sandbox = PyodideSandbox(
   "./sessions", # Directory to store session files
   # Allow Pyodide to install python packages that
   # might be required.
   allow_net=True,
)
code = """\
!pip install openai
"""

# Execute Python code
print(await sandbox.execute(code, session_id="123"))

And got these error:

CodeExecutionResult(result=None, stdout=None, stderr='Traceback (most recent call last):\n  File "/lib/python312.zip/_pyodide/_base.py", line 597, in eval_code_async\n    await CodeRunner(\n          ^^^^^^^^^^^\n  File "/lib/python312.zip/_pyodide/_base.py", line 285, in __init__\n    self.ast = next(self._gen)\n               ^^^^^^^^^^^^^^^\n  File "/lib/python312.zip/_pyodide/_base.py", line 149, in _parse_and_compile_gen\n    mod = compile(source, filename, mode, flags | ast.PyCF_ONLY_AST)\n          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n  File "<exec>", line 1\n    !pip install openai\n    ^\nSyntaxError: invalid syntax\n', status='error', execution_time=5.070329904556274)
Originally created by @tradanghi1999 on GitHub (Apr 28, 2025). Sorry, I have not found any guide on install new package in `langchain-sandbox` so I try these code ```python from langchain_sandbox import PyodideSandbox # Create a sandbox instance sandbox = PyodideSandbox( "./sessions", # Directory to store session files # Allow Pyodide to install python packages that # might be required. allow_net=True, ) code = """\ !pip install openai """ # Execute Python code print(await sandbox.execute(code, session_id="123")) ``` And got these error: ```terminal CodeExecutionResult(result=None, stdout=None, stderr='Traceback (most recent call last):\n File "/lib/python312.zip/_pyodide/_base.py", line 597, in eval_code_async\n await CodeRunner(\n ^^^^^^^^^^^\n File "/lib/python312.zip/_pyodide/_base.py", line 285, in __init__\n self.ast = next(self._gen)\n ^^^^^^^^^^^^^^^\n File "/lib/python312.zip/_pyodide/_base.py", line 149, in _parse_and_compile_gen\n mod = compile(source, filename, mode, flags | ast.PyCF_ONLY_AST)\n ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n File "<exec>", line 1\n !pip install openai\n ^\nSyntaxError: invalid syntax\n', status='error', execution_time=5.070329904556274) ```
yindo closed this issue 2026-02-16 08:18:51 -05:00
Author
Owner

@vbarda commented on GitHub (May 14, 2025):

!pip install openai is not a valid python command

@vbarda commented on GitHub (May 14, 2025): `!pip install openai` is not a valid python command
Author
Owner

@tradanghi1999 commented on GitHub (May 19, 2025):

Sorry, could you provide the example how to install new package in your sandbox?

@tradanghi1999 commented on GitHub (May 19, 2025): Sorry, could you provide the example how to install new package in your sandbox?
Author
Owner

@332123342 commented on GitHub (Jul 3, 2025):

import micropip
await micropip.install(["openpyxl"], keep_going=True)

@332123342 commented on GitHub (Jul 3, 2025): import micropip await micropip.install(["openpyxl"], keep_going=True)
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: langchain-ai/langchain-sandbox#2