ImportError: cannot import name 'factorial'

Update: upgrading statsmodels will fix this issue nowadays: pip install statsmodels --upgrade.


From this issue on statsmodels' github repo, the solution appears to be to downgrade SciPy to version 1.2 (current version is 1.3, which you appear to use).
At least for me, SciPy 1.2 has the factorial function in the scipy.misc package.

You can do

python3.6 -m pip install scipy==1.2 --upgrade

Use the --user option with that if you don't have standard install rights.

Perhaps you want to avoid using pip, since you're using Conda. You should be able to pin the version of scipy in Conda as well, but if you don't plan to add any other packages to your environment, just use the pip version.
Of course, downgrading SciPy may cause issues elsewhere, but that's hard to foresee, especially without knowing exactly what other packages and dependencies you have installed; you'll just have to find out. Fingers crossed for not ending up in dependency hell (as you've already on the doorstep).


For the more curious, scipy.misc.factorial has been deprecated since version 1.0; scipy.special.factorial should be used instead.

Importing in version 1.2 does not, however, show any clear warning, nor does using it. This might explain why statsmodels still uses the old import. A fix is on the way for the next statsmodels release.


pip install statsmodels --upgrade 

did the trick for me


One easy fix I found is editing the .py file. I was getting the same error as the OP while using Dominance analysis. Edited the dominance.py file to have from scipy.special import factorial and it worked. I would think editing the from scipy.misc import factorial line to from scipy.special import factorial in the statsmodel package code in edgeworth.py would do the same job here.


Thanks @9769953.

  1. pip3 uninstall statsmodels # make sure to remove old versions
  2. pip3 install statsmodels==0.10.0rc2 --pre --user # install release candidate of statsmodels
  3. Restarting the kernel of the jupyter notebook

fixed it for me.
You can check your versions with pip3 list

Summary: copy&run the following in your terminal:

pip3 uninstall statsmodels -y
pip3 install statsmodels==0.10.0rc2 --pre --user

and don't forget to restart the kernel of your jupyter notebook :)