Skip to content

FileNotFoundError: [WinError 2] The system cannot find the file specified ERROR:asyncio:Unclosed client session #12

@Al-aminI

Description

@Al-aminI

hi thanks for this amazing project, it is actually more accurate than langchain one and pandasAI, but i observe this issue excpecially when running on windows system.

this is really amazing

Activity

shroominic

shroominic commented on Jul 17, 2023

@shroominic
Owner

@Al-aminI Thanks!:)

Can you tell me what code you were trying to run and maybe you got a traceback this would help a lot!

Al-aminI

Al-aminI commented on Jul 17, 2023

@Al-aminI
Author
from codeinterpreterapi import CodeInterpreterSession
from codeinterpreterapi.schema import File


async def main():
    # context manager for auto start/stop of the session
    async with CodeInterpreterSession(openai_api_key="openai-api-key") as session:
        # define the user request
        user_request = "Analyze this dataset and plot something interesting about it."
        files = [
            File.from_path(r'C:\Users\myuser\Desktop\myai\uploaded-files\b699c5b9-ea83-42e9-ac61-5c6fa738214a.csv'),
        ]
        
        # generate the response
        response = await session.generate_response(
            user_request, files=files
        )

        # output to the user
        print("AI: ", response.content)
        for file in response.files:
            file.show_image()


if __name__ == "__main__":
    import asyncio

    asyncio.run(main())
Traceback (most recent call last):
  File "c:\Users\Al-amin I\Desktop\SafAI\e.py", line 28, in <module>
    asyncio.run(main())
  File "C:\Users\Al-amin I\AppData\Local\Programs\Python\Python310\lib\asyncio\runners.py", line 44, in run
    return loop.run_until_complete(main)
  File "C:\Users\Al-amin I\AppData\Local\Programs\Python\Python310\lib\asyncio\base_events.py", line 649, in run_until_complete
    return future.result()
  File "c:\Users\Al-amin I\Desktop\SafAI\e.py", line 7, in main
    async with CodeInterpreterSession(openai_api_key="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") as session:
  File "C:\Users\Al-amin I\AppData\Local\Programs\Python\Python310\lib\site-packages\codeinterpreterapi\session.py", line 190, in __aenter__
    await self.astart()
  File "C:\Users\Al-amin I\AppData\Local\Programs\Python\Python310\lib\site-packages\codeinterpreterapi\session.py", line 31, in astart
    await self.codebox.astart()
  File "C:\Users\Al-amin I\AppData\Local\Programs\Python\Python310\lib\site-packages\codeboxapi\box\localbox.py", line 111, in astart
    self.subprocess = await asyncio.create_subprocess_exec(
  File "C:\Users\Al-amin I\AppData\Local\Programs\Python\Python310\lib\asyncio\subprocess.py", line 218, in create_subprocess_exec
    transport, protocol = await loop.subprocess_exec(
  File "C:\Users\Al-amin I\AppData\Local\Programs\Python\Python310\lib\asyncio\base_events.py", line 1675, in subprocess_exec
    transport = await self._make_subprocess_transport(
  File "C:\Users\Al-amin I\AppData\Local\Programs\Python\Python310\lib\asyncio\windows_events.py", line 394, in _make_subprocess_transport
    transp = _WindowsSubprocessTransport(self, protocol, args, shell,
  File "C:\Users\Al-amin I\AppData\Local\Programs\Python\Python310\lib\asyncio\base_subprocess.py", line 36, in __init__
    self._start(args=args, shell=shell, stdin=stdin, stdout=stdout,
  File "C:\Users\Al-amin I\AppData\Local\Programs\Python\Python310\lib\asyncio\windows_events.py", line 896, in _start
    self._proc = windows_utils.Popen(
  File "C:\Users\Al-amin I\AppData\Local\Programs\Python\Python310\lib\asyncio\windows_utils.py", line 153, in __init__
    super().__init__(args, stdin=stdin_rfd, stdout=stdout_wfd,
  File "C:\Users\Al-amin I\AppData\Local\Programs\Python\Python310\lib\subprocess.py", line 971, in __init__
    self._execute_child(args, executable, preexec_fn, close_fds,
  File "C:\Users\Al-amin I\AppData\Local\Programs\Python\Python310\lib\subprocess.py", line 1440, in _execute_child
    hp, ht, pid, tid = _winapi.CreateProcess(executable, args,
FileNotFoundError: [WinError 2] The system cannot find the file specified
ERROR:asyncio:Unclosed client session
client_session: <aiohttp.client.ClientSession object at 0x000002A2591FF9A0>
shroominic

shroominic commented on Jul 18, 2023

@shroominic
Owner

Hmm I am not 100% sure because I dont have a windows system and it looks like the problem has something todo with windows. But I guess that some binary for starting the jupyter kernel with the codebox-api is missing. Maybe you can try in a different python environment or just use cloud hosted solutions like Github Codespaces or Goodle Colab.
But also maybe someone else using windows has some ideas what todo

savire

savire commented on Jul 22, 2023

@savire

AI: Sorry, something went while generating your response.Please try again or restart the session.

Even if we got passed this issue I've still got that result above. On Linux VPS too have the same result.

Is there any debug mode available so that we know where the issue might happen? I mean its a good library but the way its currently working we won't be able to use it in production if it can suddenly produces random issues.

shroominic

shroominic commented on Jul 22, 2023

@shroominic
Owner

You can enable more details for the session.generate_response method

https://github.com/shroominic/codeinterpreter-api/blob/66759f263f497c691ada5cefbdf89edc3e642baa/codeinterpreterapi/session.py#L171C9-L171C38

Then you don't get the basic error output for stuff that is happening in the CodeBox.

rakkyo150

rakkyo150 commented on Jul 22, 2023

@rakkyo150

In an environment where a virtual environment is created with the venv module, if I run venv/Scripts/activate and then python main.py, it works fine, but if I run venv/Scripts/python main.py without running venv/Scripts/activate, I get an error similar to this.

savire

savire commented on Jul 23, 2023

@savire

You can enable more details for the session.generate_response method

https://github.com/shroominic/codeinterpreter-api/blob/66759f263f497c691ada5cefbdf89edc3e642baa/codeinterpreterapi/session.py#L171C9-L171C38

Then you don't get the basic error output for stuff that is happening in the CodeBox.

Yeah I've already using the toggle from the main class.

Also just a note for you, might be helpful for others too. Those error message might appears if the user does not have access yet to GPT-4.

Although probably not intended passing an older model like GPT-3.5 at least will make sure the libs are working.

v479038280

v479038280 commented on Jul 27, 2023

@v479038280

I GOT THE SAME QUESTION.

Roych13

Roych13 commented on Sep 21, 2023

@Roych13

嗯,我不是 100% 确定,因为我没有 Windows 系统,看起来问题与 Windows 有关。但我猜想缺少一些用于使用 codebox-api 启动 jupyter 内核的二进制文件。也许您可以尝试不同的 python 环境,或者只使用云托管解决方案,例如 Github Codespaces 或 Goodle Colab。 但也可能使用 Windows 的其他人有一些想法要做什么

You can enable more details for the session.generate_response method

https://github.com/shroominic/codeinterpreter-api/blob/66759f263f497c691ada5cefbdf89edc3e642baa/codeinterpreterapi/session.py#L171C9-L171C38

Then you don't get the basic error output for stuff that is happening in the CodeBox.

I review the code, such as below

def from_path(cls, path: str):
        if not path.startswith("/"):
            path = f"./{path}"
        with open(path, "rb") as f:
            path = path.split("/")[-1]
            return cls(name=path, content=f.read())

but Windows path like as r"C:\b699c5b9-ea83-42e9-ac61-5c6fa738214a.csv" , r"C:\b699c5b9-ea83-42e9-ac61-5c6fa738214a.csv" or "C:/b699c5b9-ea83-42e9-ac61-5c6fa738214a.csv", not start with "".
I think it may be worked out it when using "from pathlib import PurePath" to find the path and add elif clause.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workinghelp wantedExtra attention is needed

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @savire@v479038280@shroominic@Roych13@rakkyo150

        Issue actions

          FileNotFoundError: [WinError 2] The system cannot find the file specified ERROR:asyncio:Unclosed client session · Issue #12 · shroominic/codeinterpreter-api