我想使用auto-sklearn。我使用了此document中的代码。所有软件包都已安装。但是我遇到了这样的错误。
!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'
我尝试了this advice,这是有关指定安装文件夹的。但是我仍然遇到相同的错误...
有人可以帮我吗?
我尝试了tidylobster和CrepeGoat解决方案,然后又收到了如下的错误消息。
---------------------------------------------------------------------------
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'
我搜索了not found scikit_learn-0.20.1.dist-info/METADATA,但是找不到很好的答案。
答案 0 :(得分:2)
您还安装了构建软件包吗?我只是尝试按照以下步骤操作,并且工作正常。
!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
import autosklearn.classification
在依赖性安装过程中正在编译一些软件包。因此,如果您没有在!curl ...
之前安装build-essentials,则可能是原因。
答案 1 :(得分:1)
使用sudo apt-get
来安装swig
the AutoScikitLearn instructions for Ubuntu ,
并执行 !sudo apt-get upgrade
以获取所有内容的最新版本。完整:
!sudo apt-get update
!sudo apt-get install build-essential swig
!sudo apt-get upgrade
!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
所以我重新运行了代码,发现的错误 非常 很奇怪。因为我收到的错误与@Nori所述的错误相同,但是它们在第三次尝试导入时消失了。知道这一点,编写一个肮脏的hack来解决它很容易:
!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")
但不幸的是,我有零想法,为什么会这样。