Rodeo: ImportError: No module named 'statsmodels' - python

I just start to use Rodeo with Python 3.6.2. But there is an error when importing statsmodels under Windows 10. Here is the script:
import pandas as pd
import statsmodels.api as sm
import pylab as pl
import numpy as np
When highlight import statsmodels.api as sm and click Run line, there is an error:
>>> import statsmodels.api as sm
ImportError: No module named 'statsmodels'
---------------------------------------------------------------------------
ImportError Traceback (most recent call last)
<ipython-input-3-6030a6549dc0> in <module>()
----> 1 import statsmodels.api as sm
ImportError: No module named 'statsmodels'
Then I downloaded the statsmodels from Github and installed it. Here is the output of pip list:
C:\Users\Documents\statsmodels-master\statsmodels-master>pip list
DEPRECATION: The default format will switch to columns in the future. You can use --format=(legacy|columns) (or define a format=(legacy|columns) in your pip.conf under the [list] section) to disable this warning.
Cython (0.26)
numpy (1.13.1)
pandas (0.20.3)
patsy (0.4.1)
pip (9.0.1)
python-dateutil (2.6.1)
pytz (2017.2)
scipy (0.19.1)
setuptools (28.8.0)
six (1.10.0)
statsmodels (0.8.0)
The output shows that statsmodels 0.8.0 is installed. But there is still importing error. It seems that the Rodeo has difficulty to see statsmodels.
UPDATE:
Here is the output of print(sys.pth) in Rodeo. There is a path for the statsmodels.
>>> print(sys.path)
['', 'C:\\Python36\\Scripts', 'c:\\python36\\lib\\site-packages\\statsmodels-0.8.0-py3.6-win-amd64.egg', 'C:\\Python36', 'C:\\Python36\\python36.zip', 'C:\\Python36\\DLLs', 'C:\\Python36\\lib', 'C:\\Python36\\lib\\site-packages', 'C:\\Python36\\lib\\site-packages\\patsy-0.4.1-py3.6.egg', 'C:\\Python36\\lib\\site-packages\\pandas-0.20.3-py3.6-win-amd64.egg', 'C:\\Python36\\lib\\site-packages\\six-1.10.0-py3.6.egg', 'C:\\Python36\\lib\\site-packages\\pytz-2017.2-py3.6.egg', 'C:\\Python36\\lib\\site-packages\\python_dateutil-2.6.1-py3.6.egg', 'C:\\Python36\\lib\\site-packages\\IPython\\extensions', 'C:\\Users\\JunC\\.ipython']

I had the same issue. I solved it by adding the path to statsmodels to rodes>preferences>environment variables. In my case the path was "C:\ProgramData\Miniconda3\pkgs".

You might not have latest version of python2. Either update it, or use python3 instead.
To use python 3, use pip3 instead of pip. So run the following:
pip3 install statsmodels

Related

Error While Importing statsmodels.api "AttributeError: module 'scipy' has no attribute '_lib'"

when I import statsmodels.api as sm it gives the error import statsmodels.api as sm
But if I only import statsmodels as sm then it does not give any error
but a few days ago import statsmodels.api as sm was also working
and I also tried pip install statsmodels --force-reinstall --user But it did not fix the problem
And also my python file is not named statsmodels.py or statsmodels.ipynb
after I reloaded vs code after running pip install statsmodels --force-reinstall --user it fixed my problem

Cannot import name '_centered' from 'scipy.signal.signaltools'

Unable to import functions from scipy module.
Gives error :
from scipy.signal.signaltools import _centered
Cannot import name '_centered' from 'scipy.signal.signaltools'
scipy.__version__
1.8.0
I encountered the same problem while using statsmodels~=0.12.x. Increasing the statsmodels package to version 0.13.2, this import issue is resolved.
UPDATE with more notes:
before:
installation of fixed version of statsmodels==0.12.2 which is dependent on scipy
there was newly released scipy==1.8.0 - 2022-02-05
when installing it, got this problem:
from statsmodels.tsa.seasonal import seasonal_decompose
File "/usr/local/lib/python3.8/site-packages/statsmodels/tsa/seasonal.py", line 12, in <module>
from statsmodels.tsa.filters.filtertools import convolution_filter
File "/usr/local/lib/python3.8/site-packages/statsmodels/tsa/filters/filtertools.py", line 18, in <module>
from scipy.signal.signaltools import _centered as trim_centered
ImportError: cannot import name '_centered' from 'scipy.signal.signaltools' (/usr/local/lib/python3.8/site-packages/scipy/signal/signaltools.py)
after:
when bumping up statsmodels to the latest version available 0.13.2 release 2022-02-08, it works
If you are not using statsmodels but other package which is dependent on scipy, have a look if there is newer version available (after the release of scipy to v.1.8.0)
If you need to use that specific version of statsmodels 0.12.x with scipy 1.8.0 I have the following hack.
Basically it just re-publishes the existing (but private) _centered function as a public attribute to the module already imported in RAM.
It is a workaround, and if you can simply upgrade your dependencies to the latest versions. Only use this if you are forced to use those specific versions.
import scipy.signal.signaltools
def _centered(arr, newsize):
# Return the center newsize portion of the array.
newsize = np.asarray(newsize)
currsize = np.array(arr.shape)
startind = (currsize - newsize) // 2
endind = startind + newsize
myslice = [slice(startind[k], endind[k]) for k in range(len(endind))]
return arr[tuple(myslice)]
scipy.signal.signaltools._centered = _centered
As it was mentioned by AndrejHan and ThomasCokelaer, you need to upgrade to statsmodels-0.13.2 with:
$ pip install statsmodels --upgrade
or
$ python3 -m pip install statsmodels --upgrade
Your error should disappear
With scipy 1.8.0, the deprecated form
from scipy.signal.signaltools import _centered
should become
from scipy.signal._signaltools import _centered
Note the underscore in front of signaltools

How to resolve error importing stats.scipy.loguniform

When importing 'loguniform' from scipy.stats i get an importerror.
Both in colab.google and jupyter.
I am running python 3.7.
scipy version 1.3.0
I even just upgraded to version 1.4.1, still the same error.
code:
from scipy.stats import loguniform
error:
---------------------------------------------------------------------------
ImportError Traceback (most recent call last)
<ipython-input-3-b01b9ec1c262> in <module>
----> 1 from scipy.stats import loguniform
ImportError: cannot import name 'loguniform' from 'scipy.stats'
other distributions load just fine,
from scipy.stats import uniform
no problem.
For Python 3 SciPy version 1.4.0 or higher should allow you to install loguniform.
So, type import scipy, then type print(scipy.__version__) and make sure 1.4.0 or newer is installed, then type from loguniform import scripy.stats.
You have the import backwards. You are importing scipy.stats from the library loguniform.
Try:
from loguniform import scripy.stats
You can reference the Library description for more details on the uses of the library Here

No module named 'mlxtend'

I am unable to install the mlextend package in Jupyter Python3 notebook
I have tried pip install mlxtend or pip3 install mlxtend, but either it shows syntax error for some reason on Python2 or it tells to try on the command line in python3. I have tried installing it on command line but it shows "ERROR: Could not find a version that satisfies the requirement mlextend (from versions: none)
ERROR: No matching distribution found for mlextend"
from mlxtend.frequent_patterns import apriori
from mlxtend.frequent_patterns import association_rules
ModuleNotFoundError Traceback (most recent call
last)
<ipython-input-3-73c97be96c5f> in <module>()
----> 1 from mlxtend.frequent_patterns import apriori
2 from mlxtend.frequent_patterns import association_rules
ModuleNotFoundError: No module named 'mlxtend'`enter code here`
You need to use the following command:
pip install mlxtend
You are currently trying to install mlextend (which does not exist) instead of mlxtend.
I had the same issue recently. What worked was importing the module first, and then getting the components:
import mlxtend
from mlxtend.frequent_patterns import apriori
from mlxtend.frequent_patterns import association_rules
To add to the above possible solutions. Under Anaconda/Miniconda environments it is also possible to use conda. Among the various options under https://anaconda.org/conda-forge/mlxtend the following worked for me
conda install -c conda-forge mlxtend
'pip install' works on Python2,if you install for Python3, use
pip3 install mlxtend instead
Use !pip install mlxtend. It will definitely work.
#Import the libraries
#To install mlxtend run : pip install mlxtend
import pandas as pd
from mlxtend.preprocessing import TransactionEncoder
from mlxtend.frequent_patterns import association_rules,apriori

ImportError: cannot import name 'factorial'

I want to use a logit model and trying to import statsmodels library.
My Version: Python 3.6.8
The best suggestion I got is to downgrade scipy but unclear how to and to what version should I downgrade. Please help how to resolve.
https://github.com/statsmodels/statsmodels/issues/5747
import statsmodels.formula.api as smf
ImportError Traceback (most recent call last)
<ipython-input-52-f897a2d817de> in <module>
----> 1 import statsmodels.formula.api as smf
~/anaconda3/envs/py36/lib/python3.6/site-packages/statsmodels/formula/api.py in <module>
13 from statsmodels.robust.robust_linear_model import RLM
14 rlm = RLM.from_formula
---> 15 from statsmodels.discrete.discrete_model import MNLogit
16 mnlogit = MNLogit.from_formula
17 from statsmodels.discrete.discrete_model import Logit
~/anaconda3/envs/py36/lib/python3.6/site-packages/statsmodels/discrete/discrete_model.py in <module>
43
44 from statsmodels.base.l1_slsqp import fit_l1_slsqp
---> 45 from statsmodels.distributions import genpoisson_p
46
47 try:
~/anaconda3/envs/py36/lib/python3.6/site-packages/statsmodels/distributions/__init__.py in <module>
1 from .empirical_distribution import ECDF, monotone_fn_inverter, StepFunction
----> 2 from .edgeworth import ExpandedNormal
3 from .discrete import genpoisson_p, zipoisson, zigenpoisson, zinegbin
~/anaconda3/envs/py36/lib/python3.6/site-packages/statsmodels/distributions/edgeworth.py in <module>
5 import numpy as np
6 from numpy.polynomial.hermite_e import HermiteE
----> 7 from scipy.misc import factorial
8 from scipy.stats import rv_continuous
9 import scipy.special as special
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.
Thanks #9769953.
pip3 uninstall statsmodels # make sure to remove old versions
pip3 install statsmodels==0.10.0rc2 --pre --user # install release candidate of statsmodels
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 :)
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.

Categories