Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cannot import statsmodels.formula.api

Whenever i am trying to import statsmodels.formula.api as smf i get the following error.

import statsmodels.formula.api as smf

Traceback (most recent call last):

File "<ipython-input-257-268d740a5877>", line 1, in <module>
   import statsmodels.formula.api as smf

File "C:\Users\ldresl\Anaconda3\lib\site- 
    packages\statsmodels\formula\__init__.py", line 1, in <module>
  from statsmodels import PytestTester

 ImportError: cannot import name 'PytestTester'
like image 238
Lucas Dresl Avatar asked May 09 '26 01:05

Lucas Dresl


2 Answers

You will have to update the package pytest and restart your kernel:

pip install pytest --upgrade

I had this problem importing statsmodels in a Jupyter notebook (Anaconda distribution). If you run on the same set-up, you can update a package in Anaconda like so:

conda update pytest

Do not forget to restart the kernel in the top navigation of your notebook afterwards. Hope that helps.

like image 110
fpersyn Avatar answered May 10 '26 15:05

fpersyn


Worked for me,

  1. pip install statsmodels --upgrade

  2. pip install pytest --upgrade

Restart Kernel

like image 33
DeepakT Avatar answered May 10 '26 15:05

DeepakT



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!