pandas-ta: Numpy ImportError: cannot import name 'sliding_window_view' from 'numpy.lib.stride_tricks'
Which version are you running? The lastest version is on Github. Pip is for major releases.
version v0.2.75
Running Windows 10
Describe the bug
I just installed the version 0.2.75 from github by downloading the .zip file, then installed using pip3 install pandas-ta-master.zip
Received a notification that I didn’t have ‘wheels’ installed so it used legacy method of install, but installation was successful.
But when I tried to add the library I get the error shown below.
I uninstalled pandas-ta, then I installed wheels. I then reinstalled pandas-ta successfully:
C:\Users\chuck\Downloads>pip3 install pandas-ta-master.zip
<snip>a bunch of installation details....</snip>
Successfully built pandas-ta
Installing collected packages: pandas-ta
Successfully installed pandas-ta-0.2.75b0
C:\Users\chuck\Downloads>
=== Below is the result of simply trying to import the library =====
>>> import pandas_ta as pta
Traceback (most recent call last):
File "<pyshell#0>", line 1, in <module>
import pandas_ta as pta
File "C:\Users\chuck\AppData\Local\Programs\Python\Python39\lib\site-packages\pandas_ta\__init__.py", line 116, in <module>
from pandas_ta.core import *
File "C:\Users\chuck\AppData\Local\Programs\Python\Python39\lib\site-packages\pandas_ta\core.py", line 4, in <module>
from pandas_ta.candles.cdl_pattern import ALL_PATTERNS
File "C:\Users\chuck\AppData\Local\Programs\Python\Python39\lib\site-packages\pandas_ta\candles\__init__.py", line 2, in <module>
from .cdl_doji import cdl_doji
File "C:\Users\chuck\AppData\Local\Programs\Python\Python39\lib\site-packages\pandas_ta\candles\cdl_doji.py", line 2, in <module>
from pandas_ta.overlap import sma
File "C:\Users\chuck\AppData\Local\Programs\Python\Python39\lib\site-packages\pandas_ta\overlap\__init__.py", line 6, in <module>
from .hilo import hilo
File "C:\Users\chuck\AppData\Local\Programs\Python\Python39\lib\site-packages\pandas_ta\overlap\hilo.py", line 4, in <module>
from .ma import ma
File "C:\Users\chuck\AppData\Local\Programs\Python\Python39\lib\site-packages\pandas_ta\overlap\ma.py", line 8, in <module>
from .linreg import linreg
File "C:\Users\chuck\AppData\Local\Programs\Python\Python39\lib\site-packages\pandas_ta\overlap\linreg.py", line 6, in <module>
from numpy.lib.stride_tricks import sliding_window_view
ImportError: cannot import name 'sliding_window_view' from 'numpy.lib.stride_tricks' (C:\Users\chuck\AppData\Local\Programs\Python\Python39\lib\site-packages\numpy\lib\stride_tricks.py)
>>>
About this issue
- Original URL
- State: closed
- Created 3 years ago
- Comments: 18 (9 by maintainers)
Commits related to this issue
- DOC README stable version update — committed to twopirllc/pandas-ta by twopirllc 3 years ago
- BUG #285 #324 #329 numpy linreg version — committed to twopirllc/pandas-ta by twopirllc 3 years ago
Ran into the same issue. Resolved it by updating numpy (current is 1.21.x):
$ pip install numpy --upgrade
Then reinstall pandas_ta:
$ pip uninstall pandas_ta $ pip install pandas_ta
Worked for me - so might work for you too.
Yep, that was the issue, which I thought was a red herring. But in fact it is new in 1.20 and I was running 1.19. Thanks for that.
Same issue!!!
My numpy version is ‘1.18.4’ import pandas_ta as ta I got same error and I did uninstall and reinstall.
My version is ‘Pandas TA v0.2.45b0’ and working perfectly!
Hello @ctilly,
This is unfortunate bug. However it is a Numpy ImportError and not a Pandas TA bug as noted by the last statement during the import:
According to Numpy, sliding_window_view documentation says that it is New in version 1.20.0. I would ensure that you are running the correct or latest version of Numpy. If updating Numpy continues to produce this
ImportError, then you need to make an Issue with Numpy.For further information about this Issue, you can dig deeper into this search if need.
Please let me know when you resolve the
ImportErrorand get Pandas TA working. 😎 Hope this helps!Kind Regards, KJ
@twopirllc Works well for me too - thanks!
I found two potential solutions. The first uses
rollingas shown in thefor window in s.rolling(window=2)example on the Pandas docs (https://pandas.pydata.org/pandas-docs/stable/user_guide/window.html#windowing-operations). Since it also yields windows which are less than length, this was the solution I came up with, adding thelen(_) == lengthcondition:(Replaces the following line) https://github.com/twopirllc/pandas-ta/blob/3b40553dfa74954d99b8aed9dac2c813c4e91f39/pandas_ta/overlap/linreg.py#L57
This is very slow for some reason however, and I found a solution which is many times faster (~1.7s vs ~0.15s). It uses another similar
numpyfunction which is present in the older versions and is almost exactly as fast assliding_window_view.I found this solution at https://stackoverflow.com/a/6811241.