Yvictor / polars_ta_extension

Polars extension for Ta-Lib: Support Ta-Lib functions in Polars expressions
MIT License
87 stars 16 forks source link

ModuleNotFoundError: No module named 'polars.utils' #9

Closed heury closed 3 months ago

heury commented 3 months ago

After upgrading to polars 1.0, the following error occurred. Would you guide me how to fix it?

from polars.utils.udfs import _get_shared_lib_location ModuleNotFoundError: No module named 'polars.utils'

sbushmanov commented 3 months ago
#/home/user/anaconda3/lib/python3.11/site-packages/polars_talib/__init.py__
from pathlib import Path
#lib = _get_shared_lib_location(__file__)
lib = Path(__file__).parent.__str__()

But anyway, library update is highly appreciated!

heury commented 3 months ago

Thanks for your solution

firmai commented 3 months ago

It would be greeat to update to Polars 1 and over, this should not be a solution. It should be reopened. This works before import, but should not be the solution.

import sys
from pathlib import Path

def find_and_modify_polars_talib():
    # Find the polars_talib installation
    polars_talib_path = next((Path(p) / 'polars_talib' for p in sys.path if (Path(p) / 'polars_talib').exists()), None)

    if polars_talib_path is None:
        print("polars_talib not found in sys.path")
        return

    # Modify the __init__.py file
    init_file = polars_talib_path / '__init__.py'

    with open(init_file, 'r') as f:
        content = f.read()

    # Replace the problematic import and lib definition
    new_content = content.replace(
        "from polars.utils.udfs import _get_shared_lib_location",
        "from pathlib import Path"
    )
    new_content = new_content.replace(
        "lib = _get_shared_lib_location(__file__)",
        "lib = str(Path(__file__).parent)"
    )

    with open(init_file, 'w') as f:
        f.write(new_content)

    print(f"Updated {init_file}")

# Run the function to modify polars_talib
find_and_modify_polars_talib()
Yvictor commented 3 months ago

fix with version 0.1.3