Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/303.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jsf-2/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在Python2.7和3.2中导入内核密度_Python_Pip_Scikit Learn - Fatal编程技术网

在Python2.7和3.2中导入内核密度

在Python2.7和3.2中导入内核密度,python,pip,scikit-learn,Python,Pip,Scikit Learn,我正在尝试使用以下页面上的示例学习scikit: 我的机器上安装了Python2.7和3.2(Ubuntu 12.04)。当我在2.7中尝试以下行时 from sklearn.neighbors import KernelDensity 我得到以下错误: Python 2.7.3 (default, Feb 27 2014, 20:00:17) [GCC 4.6.3] on linux2 Type "help", "copyright", "credits" or "license" fo

我正在尝试使用以下页面上的示例学习scikit:

我的机器上安装了Python2.7和3.2(Ubuntu 12.04)。当我在2.7中尝试以下行时

from sklearn.neighbors import KernelDensity
我得到以下错误:

Python 2.7.3 (default, Feb 27 2014, 20:00:17) 
[GCC 4.6.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> from sklearn.neighbors import KernelDensity
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: cannot import name KernelDensity
Python 3.2.3 (default, Feb 27 2014, 21:33:50) 
[GCC 4.6.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> from sklearn.neighbors import KernelDensity
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python3.2/dist-packages/sklearn/neighbors/__init__.py", line 6, in <module>
    from .ball_tree import BallTree
  File "numpy.pxd", line 155, in init sklearn.neighbors.ball_tree (sklearn/neighbors/ball_tree.c:34290)
ValueError: numpy.dtype has the wrong size, try recompiling
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python3.2/dist-packages/sklearn/__init__.py", line 38, in <module>
    from .base import clone
  File "/usr/local/lib/python3.2/dist-packages/sklearn/base.py", line 10, in <module>
    from scipy import sparse
  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
我还运行了以下程序:

sudo -E pip install -U scikit-learn
它返回:

Requirement already up-to-date: scikit-learn in /usr/local/lib/python3.2/dist-packages
Cleaning up...
我最近一直在学习python,随着我在理解python语言方面的进步,我已经开始学习“sklearn”,但由于这个错误,我陷入了困境。我怎么修理它

在尝试不同的选项时,我还升级了numpy(到1.8.1版),在按照建议使用pip卸载和重新安装scikit learn后,我遇到以下错误:

Python 2.7.3 (default, Feb 27 2014, 20:00:17) 
[GCC 4.6.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> from sklearn.neighbors import KernelDensity
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: cannot import name KernelDensity
Python 3.2.3 (default, Feb 27 2014, 21:33:50) 
[GCC 4.6.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> from sklearn.neighbors import KernelDensity
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python3.2/dist-packages/sklearn/neighbors/__init__.py", line 6, in <module>
    from .ball_tree import BallTree
  File "numpy.pxd", line 155, in init sklearn.neighbors.ball_tree (sklearn/neighbors/ball_tree.c:34290)
ValueError: numpy.dtype has the wrong size, try recompiling
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python3.2/dist-packages/sklearn/__init__.py", line 38, in <module>
    from .base import clone
  File "/usr/local/lib/python3.2/dist-packages/sklearn/base.py", line 10, in <module>
    from scipy import sparse
  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
回溯(最近一次呼叫最后一次):
文件“”,第1行,在
文件“/usr/local/lib/python3.2/dist-packages/sklearn/_init__.py”,第38行,在
从.base导入克隆
文件“/usr/local/lib/python3.2/dist-packages/sklearn/base.py”,第10行,在
从scipy导入稀疏
文件“/usr/lib/python3/dist-packages/scipy/_-init__.py”,第124行,在
pkgload(verbose=SCIPY\u IMPORT\u verbose,delayer=True)
文件“/usr/local/lib/python3.2/dist packages/numpy/\u import\u tools.py”,第177行,在调用中__
对于self中的包名称。\u获取\u排序\u名称():
文件“/usr/local/lib/python3.2/dist-packages/numpy/\u-import\u-tools.py”,第114行,在“获取排序”名称中
对于depend_dict.keys()中的名称:
RuntimeError:字典在迭代期间更改了大小

尝试卸载已安装的scikit learn,然后使用pip重新安装。我刚刚这么做了,现在我遇到了一个新错误-刚刚用它更新了我的帖子。我已经升级了numpy的基础上一些谷歌。