Updating Statsmodels in Anaconda

Viewed 5993

The root problem I have is when I try to call the test_proportions_2indep attribute of statsmodels.stats.proportion in an Anaconda Jupyter Notebook in Mac OS, I get the following error:

AttributeError: module 'statsmodels.stats.proportion' has no attribute 'test_proportions_2indep'

I'm assuming this is because Statsmodels isn't properly updated. When I call statsmodels.__version__ it says I have 0.11.1 installed in my current environment, but the version in the documentation page is 0.12.1.

I've taken the following steps:

  1. I removed Anaconda, deleted all relevant files, and downloaded it again. I've removed and re-installed Statsmodels.
  2. I've tried to update Statsmodels with the following commands in Jupyter: ! conda update statsmodels -y, ! conda update statsmodels=0.12.1 -y, and ! conda install -c conda-forge statsmodels.
  3. I went through the Anaconda app and tried to remove and reinstall Statsmodels there, but ran into a situation where a bunch of different packages were going to be uninstalled, so I think my understanding of how the environment works isn't quite up to speed. I don't know if there's a solution here or not.

Finally, I gave the following command (! conda install update statsmodels==0.12.1 -y), and got a new error/response in command line:

Collecting package metadata (current_repodata.json): done
Solving environment: failed with initial frozen solve. Retrying with flexible solve.
Collecting package metadata (repodata.json): done
Solving environment: failed with initial frozen solve. Retrying with flexible solve.

PackagesNotFoundError: The following packages are not available from current channels:

  - statsmodels==0.12.1
  - update

Current channels:

  - https://repo.anaconda.com/pkgs/main/osx-64
  - https://repo.anaconda.com/pkgs/main/noarch
  - https://repo.anaconda.com/pkgs/r/osx-64
  - https://repo.anaconda.com/pkgs/r/noarch

To search for alternate channels that may provide the conda package you're
looking for, navigate to

    https://anaconda.org

and use the search bar at the top of the page.

Of course, the Statsmodels version is still 0.10.1.

So: 1. Do I need to get Statsmodels updated to use this attribute? and 2. How do I get it updated?

1 Answers

I've had a lot of issues with Anaconda in the past when I tried upgrading packages from the base environment. Here's what I recommend:

Create your own environment. You can do this from the Anaconda GUI or from the command line as follows:

conda create --name newenv

Now you can activate this environment with the following:

conda activate newenv

If you want to see all the environments you have available:

conda info --envs

For me this prints the following:

base                     C:\ProgramData\Anaconda3
myenv                    C:\Users\james\.conda\envs\myenv
newenv                *  C:\Users\james\.conda\envs\newenv

You can tell from the * that I'm currently in the newenv.

Now I can use pip to show my current installation of statsmodels.

pip show statsmodels

For me this shows:

Name: statsmodels
Version: 0.11.0
Summary: Statistical computations and models for Python
Home-page: https://www.statsmodels.org/
Author: None
Author-email: None
License: BSD License
Location: c:\programdata\anaconda3\lib\site-packages
Requires: numpy, scipy, pandas, patsy
Required-by:

To upgrade to the latest and greatest version I simply use conda update to upgrade it.

conda update statsmodels

pip show statsmodels now shows me that I've got version 0.12.1 installed.

I highly recommend the conda cheatsheet as well. It has all the command line stuff you need to get comfortable in conda.

Related