run-llama / llama_index

LlamaIndex is a data framework for your LLM applications
https://docs.llamaindex.ai
MIT License
33.29k stars 4.66k forks source link

[Bug]: ImportError: DLL load failed while importing _multiarray_umath: The specified module was not found. #14309

Open danerlt opened 1 week ago

danerlt commented 1 week ago

Bug Description

When I run my python test code, It tips: "ImportError: DLL load failed while importing _multiarray_umath: The specified module was not found."

my code:

from llama_index.core.base.llms.types import ChatMessage, MessageRole
from llama_index.core.prompts import (
    PromptTemplate,
)

def test_template_hava_json() -> None:
    """Test partial format."""
    prompt_txt = 'hello {text} {foo} \noutput format:\n```json\n{"name": "llamaindex"}\n```'
    except_prompt = 'hello world bar \noutput format:\n```json\n{"name": "llamaindex"}\n```'
    print(prompt_txt)

    prompt_template = PromptTemplate(prompt_txt)

    prompt_fmt = prompt_template.partial_format(foo="bar")
    prompt = prompt_fmt.format(text="world")
    print(prompt)
    assert isinstance(prompt_fmt, PromptTemplate)

    assert prompt == except_prompt

    assert prompt_fmt.format_messages(text="world") == [
        ChatMessage(content=except_prompt, role=MessageRole.USER)
    ]

Version

0.10.48.post1

Steps to Reproduce

To create an environment using conda and install llama_index, follow these steps:

conda create -n ai python=3.10

conda activate ai

pip install llama_index

run python test code.

Relevant Logs/Tracbacks

version:

llama-index                             0.10.48.post1
llama-index-agent-openai                0.2.7
llama-index-cli                         0.1.12
llama-index-core                        0.10.48
llama-index-embeddings-openai           0.1.10
llama-index-indices-managed-llama-cloud 0.1.6
llama-index-legacy                      0.9.48
llama-index-llms-openai                 0.1.22
llama-index-multi-modal-llms-openai     0.1.6
llama-index-program-openai              0.1.6
llama-index-question-gen-openai         0.1.3
llama-index-readers-file                0.1.25
llama-index-readers-llama-parse         0.1.4
llama-parse                             0.4.4
llamaindex-py-client                    0.1.19
numpy                                   1.26.4
pandas                                  2.2.2

trace:

ImportError: DLL load failed while importing _multiarray_umath: 找不到指定的模块。
ImportError: DLL load failed while importing _multiarray_umath: 找不到指定的模块。
ImportError: DLL load failed while importing _multiarray_umath: 找不到指定的模块。

test_have_json.py:None (test_have_json.py)
ImportError while importing test module 'E:\workspace\JobAgent\tests\test_have_json.py'.
Hint: make sure your test modules/packages have valid Python names.
Traceback:
E:\Anaconda3\envs\ai\lib\site-packages\_pytest\python.py:492: in importtestmodule
    mod = import_path(
E:\Anaconda3\envs\ai\lib\site-packages\_pytest\pathlib.py:591: in import_path
    importlib.import_module(module_name)
E:\Anaconda3\envs\ai\lib\importlib\__init__.py:126: in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
<frozen importlib._bootstrap>:1050: in _gcd_import
    ???
<frozen importlib._bootstrap>:1027: in _find_and_load
    ???
<frozen importlib._bootstrap>:1006: in _find_and_load_unlocked
    ???
<frozen importlib._bootstrap>:688: in _load_unlocked
    ???
E:\Anaconda3\envs\ai\lib\site-packages\_pytest\assertion\rewrite.py:178: in exec_module
    exec(co, module.__dict__)
test_have_json.py:10: in <module>
    from llama_index.core.base.llms.types import ChatMessage, MessageRole
E:\Anaconda3\envs\ai\lib\site-packages\llama_index\core\__init__.py:19: in <module>
    from llama_index.core.indices import (
E:\Anaconda3\envs\ai\lib\site-packages\llama_index\core\indices\__init__.py:4: in <module>
    from llama_index.core.indices.composability.graph import ComposableGraph
E:\Anaconda3\envs\ai\lib\site-packages\llama_index\core\indices\composability\__init__.py:4: in <module>
    from llama_index.core.indices.composability.graph import ComposableGraph
E:\Anaconda3\envs\ai\lib\site-packages\llama_index\core\indices\composability\graph.py:7: in <module>
    from llama_index.core.indices.base import BaseIndex
E:\Anaconda3\envs\ai\lib\site-packages\llama_index\core\indices\base.py:8: in <module>
    from llama_index.core.base.base_retriever import BaseRetriever
E:\Anaconda3\envs\ai\lib\site-packages\llama_index\core\base\base_retriever.py:30: in <module>
    from llama_index.core.service_context import ServiceContext
E:\Anaconda3\envs\ai\lib\site-packages\llama_index\core\service_context.py:11: in <module>
    from llama_index.core.indices.prompt_helper import PromptHelper
E:\Anaconda3\envs\ai\lib\site-packages\llama_index\core\indices\prompt_helper.py:20: in <module>
    from llama_index.core.node_parser.text.token import TokenTextSplitter
E:\Anaconda3\envs\ai\lib\site-packages\llama_index\core\node_parser\__init__.py:12: in <module>
    from llama_index.core.node_parser.relational.hierarchical import (
E:\Anaconda3\envs\ai\lib\site-packages\llama_index\core\node_parser\relational\__init__.py:4: in <module>
    from llama_index.core.node_parser.relational.markdown_element import (
E:\Anaconda3\envs\ai\lib\site-packages\llama_index\core\node_parser\relational\markdown_element.py:3: in <module>
    from llama_index.core.node_parser.relational.base_element import (
E:\Anaconda3\envs\ai\lib\site-packages\llama_index\core\node_parser\relational\base_element.py:5: in <module>
    import pandas as pd
E:\Anaconda3\envs\ai\lib\site-packages\pandas\__init__.py:62: in <module>
    from pandas.core.api import (
E:\Anaconda3\envs\ai\lib\site-packages\pandas\core\api.py:1: in <module>
    from pandas._libs import (
E:\Anaconda3\envs\ai\lib\site-packages\pandas\_libs\__init__.py:17: in <module>
    import pandas._libs.pandas_datetime  # noqa: F401 # isort: skip # type: ignore[reportUnusedImport]
E   ImportError: numpy._core.multiarray failed to import
dosubot[bot] commented 1 week ago

Ensure you are using Python 3.10 and that all required dependencies, especially NumPy, are correctly installed and compatible with your Python version. Here are the steps to resolve the issue:

  1. Verify Python Version:

    python --version
  2. Install/Update NumPy:

    pip install --upgrade numpy
  3. Check for Missing DLLs: Use tools like Dependency Walker to identify any missing DLLs.

  4. Reinstall Dependencies:

    pip uninstall numpy
    pip install numpy
  5. Check Environment Variables: Ensure that your PATH includes directories where the required DLLs are located.

Following these steps should help resolve the ImportError related to _multiarray_umath [1].

To continue talking to Dosu, mention @dosu.

tibor-reiss commented 1 day ago

Hi @danerlt, this is the (numpy-)dll curse with conda under windows ;)

There are several possibilities, e.g. reinstalling numpy (the same or another version), copying dlls, manipulating path, setting CONDA_DLL_SEARCH_MODIFICATION_ENABLE, etc.

However my recommendation: do not use conda if you are anyways installing the packages with pip. E.g. use venv (or poetry if it is a bigger project): python -m venv venv_ai venv_ai\Scripts\activate pip install llama-index