Python没有安装sklearn

时间:2014-08-10 08:28:21

标签: python python-2.7 ubuntu numpy scikit-learn

我正在使用ubuntu 14.我已经下载了sklearn的dpkg软件包并将其解压缩。我尝试运行sudo python setup.py install但似乎陷入了循环

    compiling C++ sources
C compiler: c++ -pthread -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall -fPIC

creating build/temp.linux-x86_64-2.7/sklearn/utils/src
compile options: '-Isklearn/utils/src -I/usr/lib/python2.7/dist-packages/numpy/core/include -I/usr/include/python2.7 -c'
c++: sklearn/utils/src/MurmurHash3.cpp
c++ -pthread -shared -Wl,-O1 -Wl,-Bsymbolic-functions -Wl,-Bsymbolic-functions -Wl,-z,relro -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -D_FORTIFY_SOURCE=2 -g -fstack-protector --param=ssp-buffer-size=4 -Wformat -Werror=format-security build/temp.linux-x86_64-2.7/sklearn/utils/murmurhash.o build/temp.linux-x86_64-2.7/sklearn/utils/src/MurmurHash3.o -Lbuild/temp.linux-x86_64-2.7 -o build/lib.linux-x86_64-2.7/sklearn/utils/murmurhash.so
building 'sklearn.utils.lgamma' extension
compiling C sources
C compiler: x86_64-linux-gnu-gcc -pthread -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -fPIC

compile options: '-Isklearn/utils/src -I/usr/lib/python2.7/dist-packages/numpy/core/include -I/usr/include/python2.7 -c'
x86_64-linux-gnu-gcc: sklearn/utils/lgamma.c
x86_64-linux-gnu-gcc: sklearn/utils/src/gamma.c
x86_64-linux-gnu-gcc -pthread -shared -Wl,-O1 -Wl,-Bsymbolic-functions -Wl,-Bsymbolic-functions -Wl,-z,relro -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -D_FORTIFY_SOURCE=2 -g -fstack-protector --param=ssp-buffer-size=4 -Wformat -Werror=format-security build/temp.linux-x86_64-2.7/sklearn/utils/lgamma.o build/temp.linux-x86_64-2.7/sklearn/utils/src/gamma.o -Lbuild/temp.linux-x86_64-2.7 -lm -o build/lib.linux-x86_64-2.7/sklearn/utils/lgamma.so
building 'sklearn.utils.graph_shortest_path' extension
compiling C sources
C compiler: x86_64-linux-gnu-gcc -pthread -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -fPIC

compile options: '-I/usr/lib/python2.7/dist-packages/numpy/core/include -I/usr/lib/python2.7/dist-packages/numpy/core/include -I/usr/include/python2.7 -c'
x86_64-linux-gnu-gcc: sklearn/utils/graph_shortest_path.c
In file included from /usr/lib/python2.7/dist-packages/numpy/core/include/numpy/ndarraytypes.h:1761:0,
                 from /usr/lib/python2.7/dist-packages/numpy/core/include/numpy/ndarrayobject.h:17,
                 from /usr/lib/python2.7/dist-packages/numpy/core/include/numpy/arrayobject.h:4,
                 from sklearn/utils/graph_shortest_path.c:256:
/usr/lib/python2.7/dist-packages/numpy/core/include/numpy/npy_1_7_deprecated_api.h:15:2: warning: #warning "Using deprecated NumPy API, disable it by " "#defining NPY_NO_DEPRECATED_API NPY_1_7_API_VERSION" [-Wcpp]
 #warning "Using deprecated NumPy API, disable it by " \
  ^
In file included from /usr/lib/python2.7/dist-packages/numpy/core/include/numpy/ufuncobject.h:327:0,
                 from sklearn/utils/graph_shortest_path.c:257:
/usr/lib/python2.7/dist-packages/numpy/core/include/numpy/__ufunc_api.h:241:1: warning: ‘_import_umath’ defined but not used [-Wunused-function]
 _import_umath(void)
 ^
x86_64-linux-gnu-gcc -pthread -shared -Wl,-O1 -Wl,-Bsymbolic-functions -Wl,-Bsymbolic-functions -Wl,-z,relro -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -D_FORTIFY_SOURCE=2 -g -fstack-protector --param=ssp-buffer-size=4 -Wformat -Werror=format-security build/temp.linux-x86_64-2.7/sklearn/utils/graph_shortest_path.o -Lbuild/temp.linux-x86_64-2.7 -o build/lib.linux-x86_64-2.7/sklearn/utils/graph_shortest_path.so
building 'sklearn.utils.fast_dict' extension
compiling C++ sources
C compiler: c++ -pthread -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall -fPIC

compile options: '-I/usr/lib/python2.7/dist-packages/numpy/core/include -I/usr/lib/python2.7/dist-packages/numpy/core/include -I/usr/include/python2.7 -c'
c++: sklearn/utils/fast_dict.cpp
In file included from /usr/lib/python2.7/dist-packages/numpy/core/include/numpy/ndarraytypes.h:1761:0,
                 from /usr/lib/python2.7/dist-packages/numpy/core/include/numpy/ndarrayobject.h:17,
                 from /usr/lib/python2.7/dist-packages/numpy/core/include/numpy/arrayobject.h:4,
                 from sklearn/utils/fast_dict.cpp:320:
/usr/lib/python2.7/dist-packages/numpy/core/include/numpy/npy_1_7_deprecated_api.h:15:2: warning: #warning "Using deprecated NumPy API, disable it by " "#defining NPY_NO_DEPRECATED_API NPY_1_7_API_VERSION" [-Wcpp]
 #warning "Using deprecated NumPy API, disable it by " \
  ^
sklearn/utils/fast_dict.cpp: In function ‘PyObject* __pyx_pw_7sklearn_5utils_9fast_dict_1argmin(PyObject*, PyObject*)’:
sklearn/utils/fast_dict.cpp:18786:44: warning: ‘__pyx_v_min_key’ may be used uninitialized in this function [-Wmaybe-uninitialized]
             return PyInt_FromLong((long)val);
                                            ^
sklearn/utils/fast_dict.cpp:3316:46: note: ‘__pyx_v_min_key’ was declared here
   __pyx_t_7sklearn_5utils_9fast_dict_ITYPE_t __pyx_v_min_key;
                                              ^
In file included from /usr/lib/python2.7/dist-packages/numpy/core/include/numpy/ufuncobject.h:327:0,
                 from sklearn/utils/fast_dict.cpp:321:
/usr/lib/python2.7/dist-packages/numpy/core/include/numpy/__ufunc_api.h: At global scope:
/usr/lib/python2.7/dist-packages/numpy/core/include/numpy/__ufunc_api.h:241:1: warning: ‘int _import_umath()’ defined but not used [-Wunused-function]
 _import_umath(void)
 ^

..并继续这样。

我安装了numpy,但是我是通过ubuntu的软件中心完成的。当我尝试在python中导入sklearn时,我得到了

  来自sklearn.ensemble的

导入RandomForestClassifier Traceback(大多数   最近调用的最后一个):File中的文件“”,第1行   “sklearn / init .py”,第37行,in       来自。 import check_build文件“sklearn / __ check_build / __ init .py”,第46行,在       raise_build_error(e)在raise_build_error中的文件“sklearn / check_build / __ init .py”,第41行       %s“”“%(e,local_dir,''。join(dir_content).strip(),msg))ImportError:没有名为_check_build的模块    _______________________________________________________________________ sklearn的内容/ check_build:setup.py
  __init
.py _check_build.pyx   _check_build.c setup.pyc init .pyc    _______________________________________________________________________ 似乎scikit-learn还没有正确构建。

     

如果你已经安装了scikit-learn from source,请不要忘记   在使用它之前构建包:运行python setup.py install或   源目录中的make

     

如果您使用过安装程序,请检查它是否适合您的安装程序   Python版本,您的操作系统和您的平台。

我不知道sklearn / check_build的位置。

/usr/lib/python2.7/dist-packages中的我的文件夹是空的,但我可以在python中导入numpy。就像我说的,我使用ubuntu软件中心来安装numpy,但不是我现在后悔的sklearn。

3 个答案:

答案 0 :(得分:0)

我建议使用Anaconda软件包安装sklearn和所有依赖项:https://www.continuum.io/downloads#_unix

它将与numpy和其他软件包一起安装,完整列表可在此处获取:http://docs.continuum.io/anaconda/pkg-docs

答案 1 :(得分:0)

如果您希望您的软件包管理器处理所有内容,那通常会有效,尽管您不一定会使用最新版本

否则按照

的方式做点什么
sudo apt-get install build-essential gcc g++ python-dev python3-dev python-scipy python3-scipy

并尝试再次安装/编译。编译python扩展模块依赖于有一个工作的编译环境,以及python的扩展或开发头。我不确定这些依赖关系是否100%完全适用于Ubuntu b / c我最近一直在使用更多的openSUSE,但是如果我输了错误的话,apt-cache搜索会让你找到正确的命名

答案 2 :(得分:0)

处理环境问题的新方法之一是使用docker图像处理它。这允许任何开发人员在一分钟内在任何服务器中重新创建环境。您可以从here提取图像。

使用datmo CLI工具也可以非常轻松地执行此操作。我们自己面临这些问题并决定建立它。

编辑:您可以安装如下,

apt-get update; \
apt-get install -y python python-pip \
                    python-numpy \
                    python-scipy \
                    build-essential \
                    python-dev \
                    python-setuptools \
                    libatlas-dev \
                    libatlas3gf-base

update-alternatives --set libblas.so.3 /usr/lib/atlas-base/atlas/libblas.so.3; update-alternatives --set liblapack.so.3 /usr/lib/atlas-base/atlas/liblapack.so.3

pip install -U scikit-learn

免责声明:我在Datmo

工作