本文介绍了如何在GoogleColab上安装auto-sklearn?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用 auto-sklearn .我使用了代码从文档中获取.所有软件包均已安装.但是我遇到了这样的错误.

I'd like to use auto-sklearn.I used the code from this document.All packages are installed. But I got an error like this.

!curl https://raw.githubusercontent.com/automl/auto-sklearn/master/requirements.txt | xargs -n 1 -L 1 pip install 
!pip install auto-sklearn
import autosklearn.classification


---------------------------------------------------------------------------
ImportError                               Traceback (most recent call last)
<ipython-input-9-f7b2b884019b> in <module>()
     24 from keras.callbacks import EarlyStopping
     25 from keras.metrics import categorical_accuracy
---> 26 import autosklearn.classification
     27 
     28 

/usr/local/lib/python3.6/dist-packages/autosklearn/classification.py in <module>()
----> 1 from autosklearn.estimators import AutoSklearnClassifier

/usr/local/lib/python3.6/dist-packages/autosklearn/estimators.py in <module>()
      3 import numpy as np
      4 
----> 5 from autosklearn.automl import AutoMLClassifier, AutoMLRegressor
      6 from autosklearn.util.backend import create

/usr/local/lib/python3.6/dist-packages/sklearn/ensemble/base.py in <module>()
     12 from ..base import BaseEstimator
     13 from ..base import MetaEstimatorMixin
---> 14 from ..utils import _get_n_jobs, check_random_state
     15 from ..externals import six
     16 from abc import ABCMeta, abstractmethod

ImportError: cannot import name '_get_n_jobs'

我尝试了此建议,它与指定安装文件夹有关.但是我仍然有同样的错误...

I tried this advice which is about specify install folder.But I have still same error...

有人可以帮我吗?

我尝试了tidylobster和CrepeGoat解决方案,然后又收到了如下的错误消息.

I tried tidylobster and CrepeGoat solutions.Then I got another error message which is like below.

---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
/usr/local/lib/python3.6/dist-packages/pkg_resources/__init__.py in _dep_map(self)
   2896         try:
-> 2897             return self.__dep_map
   2898         except AttributeError:

/usr/local/lib/python3.6/dist-packages/pkg_resources/__init__.py in __getattr__(self, attr)
   2690         if attr.startswith('_'):
-> 2691             raise AttributeError(attr)
   2692         return getattr(self._provider, attr)

AttributeError: _DistInfoDistribution__dep_map

During handling of the above exception, another exception occurred:

AttributeError                            Traceback (most recent call last)
/usr/local/lib/python3.6/dist-packages/pkg_resources/__init__.py in _parsed_pkg_info(self)
   2887         try:
-> 2888             return self._pkg_info
   2889         except AttributeError:

/usr/local/lib/python3.6/dist-packages/pkg_resources/__init__.py in __getattr__(self, attr)
   2690         if attr.startswith('_'):
-> 2691             raise AttributeError(attr)
   2692         return getattr(self._provider, attr)

AttributeError: _pkg_info

During handling of the above exception, another exception occurred:

FileNotFoundError                         Traceback (most recent call last)
<ipython-input-2-e20ebb276309> in <module>()
      5 get_ipython().system('pip install auto-sklearn')
      6 
----> 7 import autosklearn.classification

/usr/local/lib/python3.6/dist-packages/autosklearn/__init__.py in <module>()
     16 '''
     17 
---> 18 dependencies.verify_packages(__MANDATORY_PACKAGES__)
     19 
     20 if os.name != 'posix':

/usr/local/lib/python3.6/dist-packages/autosklearn/util/dependencies.py in verify_packages(packages)
     25             operation = match.group('operation1')
     26             version = match.group('version1')
---> 27             _verify_package(name, operation, version)
     28         else:
     29             raise ValueError('Unable to read requirement: %s' % package)

/usr/local/lib/python3.6/dist-packages/autosklearn/util/dependencies.py in _verify_package(name, operation, version)
     32 def _verify_package(name, operation, version):
     33     try:
---> 34         module = pkg_resources.get_distribution(name)
     35         installed_version = LooseVersion(module.version)
     36     except pkg_resources.DistributionNotFound:

/usr/local/lib/python3.6/dist-packages/pkg_resources/__init__.py in get_distribution(dist)
    477         dist = Requirement.parse(dist)
    478     if isinstance(dist, Requirement):
--> 479         dist = get_provider(dist)
    480     if not isinstance(dist, Distribution):
    481         raise TypeError("Expected string, Requirement, or Distribution", dist)

/usr/local/lib/python3.6/dist-packages/pkg_resources/__init__.py in get_provider(moduleOrReq)
    353     """Return an IResourceProvider for the named module or requirement"""
    354     if isinstance(moduleOrReq, Requirement):
--> 355         return working_set.find(moduleOrReq) or require(str(moduleOrReq))[0]
    356     try:
    357         module = sys.modules[moduleOrReq]

/usr/local/lib/python3.6/dist-packages/pkg_resources/__init__.py in require(self, *requirements)
    896         included, even if they were already activated in this working set.
    897         """
--> 898         needed = self.resolve(parse_requirements(requirements))
    899 
    900         for dist in needed:

/usr/local/lib/python3.6/dist-packages/pkg_resources/__init__.py in resolve(self, requirements, env, installer, replace_conflicting, extras)
    790 
    791             # push the new requirements onto the stack
--> 792             new_requirements = dist.requires(req.extras)[::-1]
    793             requirements.extend(new_requirements)
    794 

/usr/local/lib/python3.6/dist-packages/pkg_resources/__init__.py in requires(self, extras)
   2633     def requires(self, extras=()):
   2634         """List of Requirements needed for this distro if `extras` are used"""
-> 2635         dm = self._dep_map
   2636         deps = []
   2637         deps.extend(dm.get(None, ()))

/usr/local/lib/python3.6/dist-packages/pkg_resources/__init__.py in _dep_map(self)
   2897             return self.__dep_map
   2898         except AttributeError:
-> 2899             self.__dep_map = self._compute_dependencies()
   2900             return self.__dep_map
   2901 

/usr/local/lib/python3.6/dist-packages/pkg_resources/__init__.py in _compute_dependencies(self)
   2906         reqs = []
   2907         # Including any condition expressions
-> 2908         for req in self._parsed_pkg_info.get_all('Requires-Dist') or []:
   2909             reqs.extend(parse_requirements(req))
   2910 

/usr/local/lib/python3.6/dist-packages/pkg_resources/__init__.py in _parsed_pkg_info(self)
   2888             return self._pkg_info
   2889         except AttributeError:
-> 2890             metadata = self.get_metadata(self.PKG_INFO)
   2891             self._pkg_info = email.parser.Parser().parsestr(metadata)
   2892             return self._pkg_info

/usr/local/lib/python3.6/dist-packages/pkg_resources/__init__.py in get_metadata(self, name)
   1408         if not self.egg_info:
   1409             return ""
-> 1410         value = self._get(self._fn(self.egg_info, name))
   1411         return value.decode('utf-8') if six.PY3 else value
   1412 

/usr/local/lib/python3.6/dist-packages/pkg_resources/__init__.py in _get(self, path)
   1520 
   1521     def _get(self, path):
-> 1522         with open(path, 'rb') as stream:
   1523             return stream.read()
   1524 

FileNotFoundError: [Errno 2] No such file or directory: '/usr/local/lib/python3.6/dist-packages/scikit_learn-0.20.1.dist-info/METADATA'

我搜索了找不到scikit_learn-0.20.1.dist-info/METADATA .但是我没有找到好的答案./p>

I searched not found scikit_learn-0.20.1.dist-info/METADATA .But I haven't find good answer.

推荐答案

使用 sudo apt-get 安装swig,如下所示 AutoScikit了解有关Ubuntu的说明

所以我重新运行了代码,发现的错误 非常 很奇怪.因为我收到的错误与@Nori所述的错误相同,但是它们在第三次尝试导入时消失了.知道这一点,编写一个肮脏的hack来解决它很容易:

So I reran my code, and the errors I'm getting are very strange. Because I get the same errors as @Nori described, but they disappear on the third attempt to import. Knowing that, it's easy to write a dirty hack to get around it:

!sudo apt-get install build-essential swig
!curl https://raw.githubusercontent.com/automl/auto-sklearn/master/requirements.txt | xargs -n 1 -L 1 pip install
!pip install auto-sklearn

for _ in range(3):
    try:
        import autosklearn.classification
        break
    except:
        pass
else:
    raise ImportError("failed to import from autosklearn")

但是不幸的是,我有零想法,为什么会这样.

But unfortunately, I have zero idea why this is the case.

这篇关于如何在GoogleColab上安装auto-sklearn?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-22 08:51