chaquo / chaquopy

Chaquopy: the Python SDK for Android
https://chaquo.com/chaquopy/
MIT License
748 stars 127 forks source link

Langchain installation in android with chaquopy #1160

Closed KaduAshlesha123 closed 3 weeks ago

KaduAshlesha123 commented 1 month ago

Hello everyone, I am trying to install langchain in android studio with chaquopy and while doing this I am facing various issues. So, I wanted to know is langchain installable in android using chaquopy, if yes could you please provide me solution.

Following are the gardle (app) lines which I am using to install packages:

pip {
            // A requirement specifier, with or without a version number:
            install("numpy")
            install("langchain")
//            options("--extra-index-url", "https://www.piwheels.org/simple/langchain/langchain-0.2.0-py3-none-any.whl#sha256=a495d3eeaa98a8434f457db71109d6a4d76e294462539f3561817716f70fe432")
//            install("langchain==0.2.0")
        }

Following are the errors I am facing:

 ERROR: Command errored out with exit status 1:
     command: 'C:\Users\User\AndroidStudioProjects\pyTest\app\build\python\env\debug\Scripts\python.exe' 'C:\Users\User\AndroidStudioProjects\pyTest\app\build\python\env\debug\Lib\site-packages\pip\_vendor\pep517\_in_process.py' prepare_metadata_for_build_wheel 'C:\Users\User\AppData\Local\Temp\tmp7g5tvaiq'
         cwd: C:\Users\User\AppData\Local\Temp\pip-install-y2hfhmwh\pydantic-core
    Complete output (26 lines):
    Checking for Rust toolchain....
    Running `maturin pep517 write-dist-info --metadata-directory C:\Users\User\AppData\Local\Temp\pip-modern-metadata-pmsvddd5 --interpreter C:\Users\User\AndroidStudioProjects\pyTest\app\build\python\env\debug\Scripts\python.exe`
    Traceback (most recent call last):
      File "C:\Users\User\AndroidStudioProjects\pyTest\app\build\python\env\debug\Lib\site-packages\pip\_vendor\pep517\_in_process.py", line 280, in <module>
        main()
      File "C:\Users\User\AndroidStudioProjects\pyTest\app\build\python\env\debug\Lib\site-packages\pip\_vendor\pep517\_in_process.py", line 263, in main
        json_out['return_val'] = hook(**hook_input['kwargs'])
                                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
      File "C:\Users\User\AndroidStudioProjects\pyTest\app\build\python\env\debug\Lib\site-packages\pip\_vendor\pep517\_in_process.py", line 133, in prepare_metadata_for_build_wheel
        return hook(metadata_directory, config_settings)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
      File "C:\Users\User\AppData\Local\Temp\pip-build-env-86gyq0xl\overlay\Lib\site-packages\maturin\__init__.py", line 192, in prepare_metadata_for_build_wheel
        _output = subprocess.check_output(command)
                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
      File "C:\Users\User\AppData\Local\Programs\Python\Python312\Lib\subprocess.py", line 466, in check_output
        return run(*popenargs, stdout=PIPE, timeout=timeout, check=True,
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
      File "C:\Users\User\AppData\Local\Programs\Python\Python312\Lib\subprocess.py", line 548, in run
        with Popen(*popenargs, **kwargs) as process:
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^
      File "C:\Users\User\AppData\Local\Programs\Python\Python312\Lib\subprocess.py", line 1026, in __init__
        self._execute_child(args, executable, preexec_fn, close_fds,
      File "C:\Users\User\AppData\Local\Programs\Python\Python312\Lib\subprocess.py", line 1538, in _execute_child
        hp, ht, pid, tid = _winapi.CreateProcess(executable, args,
                           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    FileNotFoundError: [WinError 2] The system cannot find the file specified
    ----------------------------------------
ERROR: Failed to install pydantic-core==2.18.2 from https://files.pythonhosted.org/packages/e9/23/a609c50e53959eb96393e42ae4891901f699aaad682998371348650a6651/pydantic_core-2.18.2.tar.gz#sha256=2e29d20810dfc3043ee13ac7d9e25105799817683348823f305ab3f349b9386e (from pydantic<3,>=1->langchain==0.2.0).
mhsmith commented 3 weeks ago

As it says in #1017, Pydantic version 2 isn't currently available for Chaquopy. But since langchain's requirement is pydantic<3,>=1, you can work around this by adding install("pydantic<2") to your pip section, above langchain.

Even after this, langchain still fails with the error Failed to install orjson<4.0.0,>=3.9.14 from https://files.pythonhosted.org/packages/f8/16/c10c42b69beeebe8bd136ee28b76762837479462787be57f11e0ab5d6f5d/orjson-3.10.3.tar.gz#sha256=2b166507acae7ba2f7c315dcf185a9111ad5e992ac81f2d507aac39193c2c818 (from langsmith<0.2.0,>=0.1.17->langchain).

Unfortunately I don't have any easy solution for this. Please subscribe to #1031 for updates on orjson.