4

I'm importing the following packages into Jupyter Lab and I keep getting an error whenever I try to import the "pingouin" library as follows:

import scipy.stats as stats
import seaborn as sns

from sklearn.linear_model import LinearRegression
from factor_analyzer import FactorAnalyzer 

import statsmodels.api as sm
import pingouin as pg

please note that I am using pingouin version 0.5.1 and scipy version 1.8.0 the Error message is this:

---------------------------------------------------------------------------
ImportError                               Traceback (most recent call last)
Input In [33], in <cell line: 25>()
     22 from factor_analyzer import FactorAnalyzer 
     24 import statsmodels.api as sm
---> 25 import pingouin as pg
     27 import warnings
     28 warnings.simplefilter(action='ignore', category=FutureWarning)

File ~\anaconda3\lib\site-packages\pingouin\__init__.py:14, in <module>
     12 from .correlation import *
     13 from .circular import *
---> 14 from .pairwise import *
     15 from .power import *
     16 from .reliability import *

File ~\anaconda3\lib\site-packages\pingouin\pairwise.py:12, in <module>
     10 from pingouin.effsize import compute_effsize, convert_effsize
     11 from pingouin.utils import (_check_dataframe, _flatten_list, _postprocess_dataframe)
---> 12 from scipy.stats import studentized_range
     14 __all__ = ["pairwise_ttests", "pairwise_tukey", "pairwise_gameshowell",
     15            "pairwise_corr"]
     18 @pf.register_dataframe_method
     19 def pairwise_ttests(data=None, dv=None, between=None, within=None, subject=None,
     20                     parametric=True, marginal=True, alpha=.05, alternative='two-sided',
     21                     padjust='none', effsize='hedges', correction='auto', nan_policy='listwise',
     22                     return_desc=False, interaction=True, within_first=True):

ImportError: cannot import name 'studentized_range' from 'scipy.stats' (C:\Users\Skafi\AppData\Roaming\Python\Python38\site-packages\scipy\stats\__init__.py)
Mostafa Skafi
  • 41
  • 1
  • 3
  • 1
    What versions of these packages do you have installed? Each version of `pingouin` requires a specific minimum version of `scipy`, I suspect you simply have a mismatch here. – jasonharper Apr 15 '22 at 15:54
  • @jasonharper I'm using `pingouin` version 0.5.1 and `scipy` version 1.7.3 – Mostafa Skafi Apr 15 '22 at 16:11
  • 1
    Ok, that's the problem right there - 0.5.1 requires 1.8. – jasonharper Apr 15 '22 at 16:16
  • @jasonharper I've just updated the `scipy` package to version 1.8.0 and restarted my laptop (just in case) and the error is still the same. I really do appreciate you helping on this so do you think there might be anything else that might solve this issue? – Mostafa Skafi Apr 15 '22 at 16:43
  • If you want a place to compare/contrast what you are seeing on your machine, see my comment [here](https://stackoverflow.com/q/71052986/8508004). 0.51 gets installed when running `%pip install pingouin` there and import of it works. Are you checking what is installed and being seen from in a cell inside the notebook? Updating from in the notebook using `%pip install` or `%conda install`, depending on your preferred package manager? – Wayne Apr 15 '22 at 17:02
  • @Wayne I'm installing and updating all the packages using `conda install` from the anaconda console and not from jupyter's cells. – Mostafa Skafi Apr 15 '22 at 21:13
  • And where did you check the versions you were seeing? Tried from inside the notebook to see if they match and are updated? If checking involves conda, use `%conda`. And if you want to get past the problem, I'd suggest using the `%conda` magic to install from inside your notebook. You may need to force install/update first. @jasonharper was definitely telling you what was wrong. And it seems your notebook is accessing a different environment than you seem to be editing. Using `%conda` magic inside the notebook should insure you are checking or modifying the environment the notebook uses. – Wayne Apr 16 '22 at 20:06

0 Answers0