when installing statsmodels, I get the following e

2019-09-03 01:19发布

问题:

I have read a lot of posts about this error, and the reason I am posting this is because I get the error when trying to install statsmodels package, and not one of my programs.

how do I correct the error when installing a package?

$ sudo pip3 install statsmodels
Downloading/unpacking statsmodels
  Downloading statsmodels-0.5.0.tar.gz (5.5MB): 5.5MB downloaded
  Running setup.py (path:/tmp/pip_build_root/statsmodels/setup.py) egg_info for package statsmodels
    Traceback (most recent call last):
      File "<string>", line 17, in <module>
      File "/tmp/pip_build_root/statsmodels/setup.py", line 463, in <module>
        check_dependency_versions(min_versions)
      File "/tmp/pip_build_root/statsmodels/setup.py", line 109, in check_dependency_versions
        from scipy.version import short_version as spversion
      File "/usr/lib/python3/dist-packages/scipy/__init__.py", line 124, in <module>
        pkgload(verbose=SCIPY_IMPORT_VERBOSE,postpone=True)
      File "/usr/local/lib/python3.2/dist-packages/numpy/_import_tools.py", line 177, in __call__
        for package_name in self._get_sorted_names():
      File "/usr/local/lib/python3.2/dist-packages/numpy/_import_tools.py", line 114, in _get_sorted_names
        for name in depend_dict.keys():
    RuntimeError: dictionary changed size during iteration
    Complete output from command python setup.py egg_info:
    Traceback (most recent call last):

  File "<string>", line 17, in <module>

  File "/tmp/pip_build_root/statsmodels/setup.py", line 463, in <module>

    check_dependency_versions(min_versions)

  File "/tmp/pip_build_root/statsmodels/setup.py", line 109, in check_dependency_versions

    from scipy.version import short_version as spversion

  File "/usr/lib/python3/dist-packages/scipy/__init__.py", line 124, in <module>

    pkgload(verbose=SCIPY_IMPORT_VERBOSE,postpone=True)

  File "/usr/local/lib/python3.2/dist-packages/numpy/_import_tools.py", line 177, in __call__

    for package_name in self._get_sorted_names():

  File "/usr/local/lib/python3.2/dist-packages/numpy/_import_tools.py", line 114, in _get_sorted_names

    for name in depend_dict.keys():

RuntimeError: dictionary changed size during iteration

----------------------------------------
Cleaning up...
Command python setup.py egg_info failed with error code 1 in /tmp/pip_build_root/statsmodels

Reading the suggested response, I ran:

sudo pip3 install numpy --upgrade
Requirement already up-to-date: numpy in /usr/local/lib/python3.2/dist-packages
Cleaning up...

Uninstalled matplotlib and numpy and then upon installing it again, I get the following message:

sudo pip3 install matplotlib
Requirement already satisfied (use --upgrade to upgrade): matplotlib in /usr/local/lib/python3.2/dist-packages
Requirement already satisfied (use --upgrade to upgrade): numpy>=1.5 in /usr/lib/python3/dist-packages (from matplotlib)
Requirement already satisfied (use --upgrade to upgrade): python-dateutil in /usr/local/lib/python3.2/dist-packages/python_dateutil-2.2-py3.2.egg (from matplotlib)
Requirement already satisfied (use --upgrade to upgrade): tornado in /usr/local/lib/python3.2/dist-packages (from matplotlib)
Requirement already satisfied (use --upgrade to upgrade): pyparsing>=1.5.6 in /usr/local/lib/python3.2/dist-packages/pyparsing-2.0.2-py3.2.egg (from matplotlib)
Requirement already satisfied (use --upgrade to upgrade): nose in /usr/local/lib/python3.2/dist-packages (from matplotlib)
Requirement already satisfied (use --upgrade to upgrade): six in /usr/local/lib/python3.2/dist-packages/six-1.7.2-py3.2.egg (from python-dateutil->matplotlib)
Cleaning up...

For numpy, the reinstall returns the following:

sudo pip3 install numpy
Requirement already satisfied (use --upgrade to upgrade): numpy in /usr/lib/python3/dist-packages
Cleaning up..

.

回答1:

It's a bug hitting numpy in Python 3.*. It seems to have been fixed in the source, but I don't know if it has found itself to a release yet.

Try upgrading numpy before installing statsmodel.

In Python 2., the .keys() function would return a list, but in 3. it returns an iterator, hence the reason to the bug.