Error in <module> from pandas_ta.XXX import

I have developed the code to generate signals using 5EM, MACD and RSI. There are no syntax or other errors shown in the code but it throws run time errors. The code and the errors are pasted below.

=====================================================================

import yfinance as yf

import pandas_ta as ta

import pandas as pd

def get_signals(symbol, interval=‘30m’, period=‘5d’):

\# Download historical data

df = yf.download(tickers=symbol+'.NS', interval=interval, period=period)

df.dropna(inplace=True)

\# Calculate indicators

df\['EMA5'\] = ta.ema(df\['Close'\], length=5)

macd = ta.macd(df\['Close'\])

df\['MACD'\] = macd\['MACD_12_26_9'\]

df\['MACD_signal'\] = macd\['MACDs_12_26_9'\]

df\['RSI'\] = ta.rsi(df\['Close'\], length=14)


# Entry condition: MACD crossover, RSI > 50, price above EMA5

df\['Entry'\] = (df\['MACD'\] > df\['MACD_signal'\]) & (df\['RSI'\] > 50) & (df\['Close'\] > df\['EMA5'\])

\# SL: previous swing low

df\['SL'\] = df\['Low'\].shift(1)

\# Target: 1.5x risk

df\['Target'\] = df\['Close'\] + 1.5 \* (df\['Close'\] - df\['SL'\])

\# Exit: MACD cross down or RSI < 50 or price below EMA5

df\['Exit'\] = (df\['MACD'\] < df\['MACD_signal'\]) | (df\['RSI'\] < 50) | (df\['Close'\] < df\['EMA5'\])


# Filter signals

signals = df\[df\['Entry'\]\]

return signals\[\['Close', 'EMA5', 'MACD', 'MACD_signal', 'RSI', 'SL', 'Target', 'Exit'\]\]

# Example usage

signals = get_signals(‘RELIANCE’)

print(signals.tail())

=====================================================================

c:/Users/vasud/OneDrive/Desktop/SAMPLE/class1_challenge.py
C:\Users\vasud\OneDrive\Desktop.venv\Lib\site-packages\pandas_ta_init_.py:7: UserWarning: pkg_resources is deprecated as an API. See Package Discovery and Resource Access using pkg_resources - setuptools 80.9.0 documentation . The pkg_resources package is slated for removal as early as 2025-11-30. Refrain from using this package or pin to Setuptools<81.
from pkg_resources import get_distribution, DistributionNotFound
Traceback (most recent call last):
File “c:\Users\vasud\OneDrive\Desktop\SAMPLE\class1_challenge.py”, line 2, in
import pandas_ta as ta
File “C:\Users\vasud\OneDrive\Desktop.venv\Lib\site-packages\pandas_ta_init_.py”, line 116, in
from pandas_ta.core import *
File “C:\Users\vasud\OneDrive\Desktop.venv\Lib\site-packages\pandas_ta\core.py”, line 18, in
from pandas_ta.momentum import *
File “C:\Users\vasud\OneDrive\Desktop.venv\Lib\site-packages\pandas_ta\momentum_init_.py”, line 34, in
from .squeeze_pro import squeeze_pro
File “C:\Users\vasud\OneDrive\Desktop.venv\Lib\site-packages\pandas_ta\momentum\squeeze_pro.py”, line 2, in
from numpy import NaN as npNaN
ImportError: cannot import name ‘NaN’ from ‘numpy’ (C:\Users\vasud\OneDrive\Desktop.venv\Lib\site-packages\numpy_init_.py). Did you mean: ‘nan’?

==========================================================================

I don’t understand why these errors are occurring and how they can be fixed.

Please help.

This error seems to be caused by a compatibility issue between the latest NumPy and the pandas-ta library, not your code. The quick fix is to either downgrade NumPy (pip install “numpy<2”) or upgrade pandas-ta (pip install -U pandas-ta). Once done, restart your environment and give it a try.

Note: this is just a suggestion; I’m not an expert on this.

Thank you @Pradeep_Jaiswar for taking time to analyze my problem and suggesting a possible solution. I tried both methods, but unfortunately neither made a difference :frowning:

@Archit_Mittal

Sir, here is the code file, needs fix. Community is not accepting text file, so I am uploading an image file. Thanks.